KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.ejbca.core.model.ca.crl.RevokedCertInfo;
17 import org.ejbca.core.protocol.ws.client.gen.AuthorizationDeniedException_Exception;
18 import org.ejbca.ui.cli.ErrorAdminCommandException;
19 import org.ejbca.ui.cli.IAdminCommand;
20 import org.ejbca.ui.cli.IllegalAdminCommandException;
21
22 /**
23  * Revokes a given tokens certificate
24  *
25  * @version $Id: RevokeTokenCommand.java,v 1.2 2006/10/08 22:53:26 herrvendil Exp $
26  */

27 public class RevokeTokenCommand extends EJBCAWSRABaseCommand implements IAdminCommand{
28
29     
30     private static final int ARG_HARDTOKENSN = 1;
31     private static final int ARG_REASON = 2;
32     
33     
34     /**
35      * Creates a new instance of RevokeTokenCommand
36      *
37      * @param args command line arguments
38      */

39     public RevokeTokenCommand(String JavaDoc[] args) {
40         super(args);
41     }
42
43     /**
44      * Runs the command
45      *
46      * @throws IllegalAdminCommandException Error in command args
47      * @throws ErrorAdminCommandException Error running command
48      */

49     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
50          try {
51            
52             if(args.length != 3){
53                 usage();
54                 System.exit(-1);
55             }
56             
57             String JavaDoc hardtokensn = args[ARG_HARDTOKENSN];
58             int reason = getRevokeReason(args[ARG_REASON]);
59             
60             if(reason == RevokedCertInfo.NOT_REVOKED){
61                 getPrintStream().println("Error : Unsupported reason " + reason);
62                 usage();
63                 System.exit(-1);
64             }
65                         
66             try{
67
68                 getEjbcaRAWS().revokeToken(hardtokensn,reason);
69                 getPrintStream().println("Token revoked sucessfully");
70             }catch(AuthorizationDeniedException_Exception e){
71                 getPrintStream().println("Error : " + e.getMessage());
72             }
73         } catch (Exception JavaDoc e) {
74             throw new ErrorAdminCommandException(e);
75         }
76     }
77
78
79
80
81     protected void usage() {
82         getPrintStream().println("Command used to revoke a tokens certificate");
83         getPrintStream().println("Usage : revokecert <hardtokensn> <reason> \n\n");
84         getPrintStream().println("Reason should be one of : ");
85         for(int i=1; i< REASON_TEXTS.length-1;i++){
86             getPrintStream().print(REASON_TEXTS[i] + ", ");
87         }
88         getPrintStream().print(REASON_TEXTS[REASON_TEXTS.length-1]);
89    }
90
91
92 }
93
Popular Tags