1 13 14 package org.ejbca.core.protocol.ws.client; 15 16 17 import java.util.List ; 18 19 import org.ejbca.core.model.ca.crl.RevokedCertInfo; 20 import org.ejbca.core.model.ra.UserDataConstants; 21 import org.ejbca.core.protocol.ws.client.gen.AuthorizationDeniedException_Exception; 22 import org.ejbca.core.protocol.ws.client.gen.UserDataVOWS; 23 import org.ejbca.core.protocol.ws.client.gen.UserMatch; 24 import org.ejbca.ui.cli.ErrorAdminCommandException; 27 import org.ejbca.ui.cli.IAdminCommand; 28 import org.ejbca.ui.cli.IllegalAdminCommandException; 29 30 35 public class RevokeUserCommand extends EJBCAWSRABaseCommand implements IAdminCommand{ 36 37 38 private static final int ARG_USERNAME = 1; 39 private static final int ARG_REASON = 2; 40 private static final int ARG_DELETE = 3; 41 42 43 48 public RevokeUserCommand(String [] args) { 49 super(args); 50 } 51 52 58 public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException { 59 try { 60 61 if(args.length != 4){ 62 usage(); 63 System.exit(-1); 64 } 65 66 String username = args[ARG_USERNAME]; 67 int reason = getRevokeReason(args[ARG_REASON]); 68 boolean delete = getDelete(args[ARG_DELETE]); 69 70 if(reason == RevokedCertInfo.NOT_REVOKED){ 71 getPrintStream().println("Error : Unsupported reason " + reason); 72 usage(); 73 System.exit(-1); 74 } 75 76 try{ 77 UserMatch match = new UserMatch(); 78 match.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS); 79 match.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME); 80 match.setMatchvalue(username); 81 82 List <UserDataVOWS> result = getEjbcaRAWS().findUser(match); 83 if(result == null || result.size() != 1){ 84 getPrintStream().println("Error : User doesn't exist."); 85 System.exit(-1); 86 } 87 88 UserDataVOWS user = result.iterator().next(); 89 if(user.getStatus() == UserDataConstants.STATUS_REVOKED){ 90 getPrintStream().println("Error : User already revoked."); 91 System.exit(-1); 92 } 93 94 getEjbcaRAWS().revokeUser(username,reason,delete); 95 getPrintStream().println("User revoked sucessfully"); 96 }catch(AuthorizationDeniedException_Exception e){ 97 getPrintStream().println("Error : " + e.getMessage()); 98 } 99 } catch (Exception e) { 100 throw new ErrorAdminCommandException(e); 101 } 102 } 103 104 105 private boolean getDelete(String delete) { 106 if(delete.equalsIgnoreCase("true")){ 107 return true; 108 } 109 if(delete.equalsIgnoreCase("false")){ 110 return false; 111 } 112 usage(); 113 System.exit(-1); 114 return false; } 116 117 118 protected void usage() { 119 getPrintStream().println("Command used to revoke a users certificate"); 120 getPrintStream().println("Usage : revokecert <hardtokensn> <reason> <delete (true|false)> \n\n"); 121 getPrintStream().println("Reason should be one of : "); 122 for(int i=1; i< REASON_TEXTS.length-1;i++){ 123 getPrintStream().print(REASON_TEXTS[i] + ", "); 124 } 125 getPrintStream().print(REASON_TEXTS[REASON_TEXTS.length-1]); 126 } 127 128 129 } 130 | Popular Tags |