KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.ejbca.core.model.ra.UserDataConstants;
18 import org.ejbca.core.model.ra.UserDataVO;
19
20
21
22
23
24 /**
25  * Revokes a user in the database, and also revokes all the users certificates.
26  *
27  * @version $Id: RaRevokeUserCommand.java,v 1.4 2006/08/12 09:49:30 herrvendil Exp $
28  */

29 public class RaRevokeUserCommand extends BaseRaAdminCommand {
30     /**
31      * Creates a new instance of RaRevokeUserCommand
32      *
33      * @param args command line arguments
34      */

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

45     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
46         try {
47             if (args.length < 3) {
48                 getOutputStream().println("Usage: RA revokeuser <username> <reason>");
49                 getOutputStream().println(
50                     "Reason: unused(0), keyCompromise(1), cACompromise(2), affiliationChanged(3), superseded(4), cessationOfOperation(5), certficateHold(6), removeFromCRL(8),privilegeWithdrawn(9),aACompromise(10)");
51                 getOutputStream().println("Normal reason is 0");
52
53                 return;
54             }
55
56             String JavaDoc username = args[1];
57             int reason = Integer.parseInt(args[2]);
58
59             if ((reason == 7) || (reason < 0) || (reason > 10)) {
60                 getOutputStream().println("Error : Reason must be an integer between 0 and 10 except 7.");
61             } else {
62                 UserDataVO data = getAdminSession().findUser(administrator, username);
63                 getOutputStream().println("Found user:");
64                 getOutputStream().println("username=" + data.getUsername());
65                 getOutputStream().println("dn=\"" + data.getDN() + "\"");
66                 getOutputStream().println("Old status=" + data.getStatus());
67                 getAdminSession().setUserStatus(administrator, username,
68                         UserDataConstants.STATUS_REVOKED);
69                 getOutputStream().println("New status=" + UserDataConstants.STATUS_REVOKED);
70
71                 // Revoke users certificates
72
try {
73                     getAdminSession().revokeUser(administrator, username, reason);
74                 } catch (AuthorizationDeniedException e) {
75                     getOutputStream().println("Error : Not authorized to revoke user.");
76                 }
77             }
78         } catch (Exception JavaDoc e) {
79             throw new ErrorAdminCommandException(e);
80         }
81     }
82
83     // execute
84
}
85
Popular Tags