KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > cli > RaSetUserStatusCommand


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.cli;
15
16 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
17
18
19 /**
20  * Changes status for a user in the database, status is defined in
21  * org.ejbca.core.ejb.ra.UserDataLocal.
22  *
23  * @version $Id: RaSetUserStatusCommand.java,v 1.3 2006/08/12 09:49:30 herrvendil Exp $
24  *
25  * @see org.ejbca.core.ejb.ra.UserDataLocal
26  */

27 public class RaSetUserStatusCommand extends BaseRaAdminCommand {
28     /**
29      * Creates a new instance of RaSetUserStatusCommand
30      *
31      * @param args command line arguments
32      */

33     public RaSetUserStatusCommand(String JavaDoc[] args) {
34         super(args);
35     }
36
37     /**
38      * Runs the command
39      *
40      * @throws IllegalAdminCommandException Error in command args
41      * @throws ErrorAdminCommandException Error running command
42      */

43     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
44         try {
45             if (args.length < 3) {
46                 getOutputStream().println("Usage: RA setuserstatus <username> <status>");
47                 getOutputStream().println(
48                     "Status: NEW=10; FAILED=11; INITIALIZED=20; INPROCESS=30; GENERATED=40; HISTORICAL=50");
49
50                 return;
51             }
52
53             String JavaDoc username = args[1];
54             int status = Integer.parseInt(args[2]);
55
56             try {
57                 getAdminSession().setUserStatus(administrator, username, status);
58                 getOutputStream().println("New status for user " + username + " is " + status);
59             } catch (AuthorizationDeniedException e) {
60                 getOutputStream().println("Error : Not authorized to change userdata.");
61             }
62         } catch (Exception JavaDoc e) {
63             throw new ErrorAdminCommandException(e);
64         }
65     }
66
67     // execute
68
}
69
Popular Tags