KickJava   Java API By Example, From Geeks To Geeks.

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


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.ca.crl.RevokedCertInfo;
18 import org.ejbca.core.model.ra.UserDataConstants;
19 import org.ejbca.core.model.ra.UserDataVO;
20
21 /**
22  * Unrevokes a user in the database, and also unrevokes all the users certificates on hold.
23  *
24  * @version $Id: RaUnRevokeUserCommand.java,v 1.3.6.1 2007/05/16 09:30:24 jeklund Exp $
25  */

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

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

42     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
43         try {
44             if (args.length < 2) {
45                 getOutputStream().println("Usage: RA unrevokeuser <username>");
46                 getOutputStream().println("A users certificate can unly be unrevoked if the revocation reason is certificate_hold.");
47                 return;
48             }
49             String JavaDoc username = args[1];
50             UserDataVO data = getAdminSession().findUser(administrator, username);
51             getOutputStream().println("Found user:");
52             getOutputStream().println("username=" + data.getUsername());
53             getOutputStream().println("dn=\"" + data.getDN() + "\"");
54             getOutputStream().println("Old status=" + data.getStatus());
55             getOutputStream().println("New status=" + UserDataConstants.STATUS_GENERATED);
56             // Unrevoke user and certificates on hold
57
try {
58                 getAdminSession().revokeUser(administrator, username, RevokedCertInfo.NOT_REVOKED);
59             } catch (AuthorizationDeniedException e) {
60                 getOutputStream().println("Error : Not authorized to un-revoke user.");
61             }
62         } catch (Exception JavaDoc e) {
63             throw new ErrorAdminCommandException(e);
64         }
65     } // execute
66
}
67
Popular Tags