1 13 14 package org.ejbca.ui.cli; 15 16 import java.rmi.UnmarshalException ; 17 18 import org.ejbca.core.model.SecConst; 19 import org.ejbca.core.model.ca.caadmin.CAInfo; 20 import org.ejbca.core.model.ca.catoken.HardCATokenInfo; 21 import org.ejbca.core.model.ca.catoken.IHardCAToken; 22 23 24 25 26 27 32 public class CaActivateCACommand extends BaseCaAdminCommand { 33 38 public CaActivateCACommand(String [] args) { 39 super(args); 40 } 41 42 48 public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException { 49 try { 50 if (args.length < 3) { 51 getOutputStream().println("Usage: CA activateca <CA name> <authorization code>"); 52 return; 53 } 54 55 String caname = args[1]; 56 String authorizationcode = args[2]; 57 58 CAInfo cainfo = getCAAdminSessionRemote().getCAInfo(administrator, caname); 60 if(cainfo == null){ 61 getOutputStream().println("Error: CA " + caname + " cannot be found"); 62 return; 63 } 64 65 67 if(!(cainfo.getCATokenInfo() instanceof HardCATokenInfo)){ 68 getOutputStream().println("Error: CA have a Soft CAToken and cannot be activated"); 69 return; 70 } 71 72 if(cainfo.getStatus() == SecConst.CA_OFFLINE || 74 (cainfo.getStatus() == SecConst.CA_ACTIVE && ((HardCATokenInfo)cainfo.getCATokenInfo()).getCATokenStatus() == IHardCAToken.STATUS_OFFLINE)) { 75 try { 76 getCAAdminSessionRemote().activateCAToken(administrator, cainfo.getCAId(), authorizationcode); 77 } catch (UnmarshalException e) { 78 getOutputStream().println("Error returned, did you enter the correct PIN?"); 81 getOutputStream().println(e.getMessage()); 82 } 83 }else{ 84 getOutputStream().println("Error: CA or CAToken must be offline to be activated."); 85 } 86 87 88 } catch (Exception e) { 89 throw new ErrorAdminCommandException(e); 90 } 91 } } 93 | Popular Tags |