KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > protocol > ws > client > CheckRevokeStatusCommand


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.core.protocol.ws.client;
15
16 import java.math.BigInteger JavaDoc;
17
18 //import org.ejbca.core.model.authorization.wsclient.AuthorizationDeniedException;
19
import org.ejbca.core.model.ca.crl.RevokedCertInfo;
20 import org.ejbca.core.protocol.ws.client.gen.AuthorizationDeniedException_Exception;
21 import org.ejbca.core.protocol.ws.client.gen.RevokeStatus;
22 //import org.ejbca.core.protocol.ws.wsclient.RevokeStatus;
23
import org.ejbca.ui.cli.ErrorAdminCommandException;
24 import org.ejbca.ui.cli.IAdminCommand;
25 import org.ejbca.ui.cli.IllegalAdminCommandException;
26 import org.ejbca.util.CertTools;
27
28 /**
29  * Revokes a given certificate
30  *
31  * @version $Id: CheckRevokeStatusCommand.java,v 1.2 2006/10/08 22:53:26 herrvendil Exp $
32  */

33 public class CheckRevokeStatusCommand extends EJBCAWSRABaseCommand implements IAdminCommand{
34
35     
36     private static final int ARG_ISSUERDN = 1;
37     private static final int ARG_CERTSN = 2;
38     
39     
40     
41     /**
42      * Creates a new instance of RevokeCertCommand
43      *
44      * @param args command line arguments
45      */

46     public CheckRevokeStatusCommand(String JavaDoc[] args) {
47         super(args);
48     }
49
50     /**
51      * Runs the command
52      *
53      * @throws IllegalAdminCommandException Error in command args
54      * @throws ErrorAdminCommandException Error running command
55      */

56     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
57         try {
58            
59             if(args.length != 3){
60                 usage();
61                 System.exit(-1);
62             }
63             
64             String JavaDoc issuerdn = CertTools.stringToBCDNString(args[ARG_ISSUERDN]);
65             String JavaDoc certsn = getCertSN(args[ARG_CERTSN]);
66                    
67             try{
68                 
69                 RevokeStatus status = getEjbcaRAWS().checkRevokationStatus(issuerdn,certsn);
70                 if(status == null){
71                     getPrintStream().println("Error, No certificate found in database.");
72                 }else{
73                     getPrintStream().println("Revokation status :");
74                     getPrintStream().println(" IssuerDN : " + status.getIssuerDN());
75                     getPrintStream().println(" CertificateSN : " + status.getCertificateSN());
76                     if(status.getReason() == RevokedCertInfo.NOT_REVOKED){
77                         getPrintStream().println(" Status : NOT REVOKED");
78                     }else{
79                         getPrintStream().println(" Status : REVOKED");
80                         getPrintStream().println(" Reason : " + getRevokeReason(status.getReason()));
81                         getPrintStream().println(" Date : " + status.getRevocationDate().toString());
82                     }
83                 }
84             }catch(AuthorizationDeniedException_Exception e){
85                 getPrintStream().println("Error : " + e.getMessage());
86             }
87         } catch (Exception JavaDoc e) {
88             throw new ErrorAdminCommandException(e);
89         }
90     }
91
92
93     private String JavaDoc getCertSN(String JavaDoc certsn) {
94         try{
95             new BigInteger JavaDoc(certsn,16);
96         }catch(NumberFormatException JavaDoc e){
97             getPrintStream().println("Error in Certificate SN");
98             usage();
99             System.exit(-1);
100         }
101         return certsn;
102     }
103
104     protected void usage() {
105         getPrintStream().println("Command used check the status of certificate");
106         getPrintStream().println("Usage : checkrevokationstatus <issuerdn> <certificatesn (HEX)> \n\n");
107
108    }
109
110
111 }
112
Popular Tags