KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > cli > CaDeactivateCACommand


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.ui.cli;
15
16 import org.ejbca.core.model.SecConst;
17 import org.ejbca.core.model.ca.caadmin.CAInfo;
18 import org.ejbca.core.model.ca.catoken.HardCATokenInfo;
19
20
21
22
23
24 /**
25  * Makes the specified HSM CA offline.
26  *
27  * @version $Id: CaDeactivateCACommand.java,v 1.2 2006/02/16 07:50:58 herrvendil Exp $
28  */

29 public class CaDeactivateCACommand extends BaseCaAdminCommand {
30     /**
31      * Creates a new instance of RaListUsersCommand
32      *
33      * @param args command line arguments
34      */

35     public CaDeactivateCACommand(String JavaDoc[] args) {
36         super(args);
37     }
38
39     /**
40      * Runs the command
41      *
42      * @throws IllegalAdminCommandException Error in command args
43      * @throws ErrorAdminCommandException Error running command
44      */

45     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
46         try {
47             if (args.length < 2) {
48                 getOutputStream().println("Usage: CA deactivateca <CA name> ");
49                 return;
50             }
51
52             String JavaDoc caname = args[1];
53                         
54             // Get the CAs info and id
55
CAInfo cainfo = getCAAdminSessionRemote().getCAInfo(administrator, caname);
56             if(cainfo == null){
57                 getOutputStream().println("Error: CA " + caname + " cannot be found");
58                 return;
59             }
60             
61             // Check that ca is and hardtoken ca
62
if(!(cainfo.getCATokenInfo() instanceof HardCATokenInfo)){
63                 getOutputStream().println("Error: CA have a Soft CAToken and cannot be deactivated");
64                 return;
65             }
66             
67             if(cainfo.getStatus() == SecConst.CA_ACTIVE){
68               getCAAdminSessionRemote().deactivateCAToken(administrator, cainfo.getCAId());
69             }else{
70                 getOutputStream().println("Error: CA or CAToken must be active to be put offline.");
71             }
72  
73         } catch (Exception JavaDoc e) {
74             throw new ErrorAdminCommandException(e);
75         }
76     } // execute
77
}
78
Popular Tags