KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.naming.InitialContext JavaDoc;
17
18 import org.ejbca.core.ejb.keyrecovery.IKeyRecoverySessionHome;
19 import org.ejbca.core.ejb.keyrecovery.IKeyRecoverySessionRemote;
20 import org.ejbca.core.model.ra.UserDataVO;
21
22
23 /**
24  * Find details of a user in the database.
25  *
26  * @version $Id: RaKeyRecoverNewestCommand.java,v 1.5 2006/11/02 08:03:22 anatom Exp $
27  */

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

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

44     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
45         try {
46             if (args.length != 2) {
47                 getOutputStream().println("Usage: RA keyrecovernewest <username>");
48
49                 return;
50             }
51
52             //InitialContext jndicontext = new InitialContext();
53
InitialContext JavaDoc jndicontext = getInitialContext();
54
55             IKeyRecoverySessionHome keyrecoverysessionhome = (IKeyRecoverySessionHome) javax.rmi.PortableRemoteObject.narrow(jndicontext.lookup(
56                         "KeyRecoverySession"), IKeyRecoverySessionHome.class);
57             IKeyRecoverySessionRemote keyrecoverysession = keyrecoverysessionhome.create();
58
59             String JavaDoc username = args[1];
60
61              boolean usekeyrecovery = getRaAdminSession().loadGlobalConfiguration(administrator).getEnableKeyRecovery();
62              if(!usekeyrecovery){
63                getOutputStream().println("Keyrecovery have to be enabled in the system configuration in order to use this command.");
64                return;
65              }
66                
67              if(keyrecoverysession.isUserMarked(administrator,username)){
68                getOutputStream().println("User is already marked for recovery.");
69                return;
70              }
71              
72              UserDataVO userdata = getAdminSession().findUser(administrator, username);
73              if(userdata == null){
74                  getOutputStream().println("Error, The user doesn't exist.");
75                  return;
76              }
77              
78              keyrecoverysession.markNewestAsRecoverable(administrator, username,userdata.getEndEntityProfileId());
79                      
80              getOutputStream().println("Key corresponding to users newest certificate has been marked for recovery.");
81  
82
83         } catch (Exception JavaDoc e) {
84             throw new ErrorAdminCommandException(e);
85         }
86     }
87
88     // execute
89
}
90
Popular Tags