1 13 14 package org.ejbca.ui.cli; 15 16 import javax.naming.InitialContext ; 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 28 public class RaKeyRecoverNewestCommand extends BaseRaAdminCommand { 29 34 public RaKeyRecoverNewestCommand(String [] args) { 35 super(args); 36 } 37 38 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 = getInitialContext(); 54 55 IKeyRecoverySessionHome keyrecoverysessionhome = (IKeyRecoverySessionHome) javax.rmi.PortableRemoteObject.narrow(jndicontext.lookup( 56 "KeyRecoverySession"), IKeyRecoverySessionHome.class); 57 IKeyRecoverySessionRemote keyrecoverysession = keyrecoverysessionhome.create(); 58 59 String 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 e) { 84 throw new ErrorAdminCommandException(e); 85 } 86 } 87 88 } 90 | Popular Tags |