KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.FileOutputStream JavaDoc;
17
18 import javax.naming.Context JavaDoc;
19
20 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionHome;
21 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionRemote;
22
23
24 /**
25  * Retrieves the latest CRL from the CA.
26  *
27  * @version $Id: CaGetCrlCommand.java,v 1.1 2006/01/17 20:28:05 anatom Exp $
28  */

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

35     public CaGetCrlCommand(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             if (args.length < 3) {
47                 throw new IllegalAdminCommandException("Retrieves CRL in DER format.\nUsage: CA getcrl <caname> <outfile>");
48             }
49             try {
50                 String JavaDoc outfile = args[2];
51                 String JavaDoc caname = args[1];
52                 String JavaDoc issuerdn = getIssuerDN(caname);
53                 Context JavaDoc context = getInitialContext();
54                 ICertificateStoreSessionHome storehome = (ICertificateStoreSessionHome) javax.rmi.PortableRemoteObject.narrow(context.lookup("CertificateStoreSession"),ICertificateStoreSessionHome.class);
55                 ICertificateStoreSessionRemote store = storehome.create();
56                 byte[] crl = store.getLastCRL(administrator, issuerdn);
57                 FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(outfile);
58                 fos.write(crl);
59                 fos.close();
60                 getOutputStream().println("Wrote latest CRL to " + outfile + ".");
61             } catch (Exception JavaDoc e) {
62                 throw new ErrorAdminCommandException(e);
63             }
64     } // execute
65

66 }
67
Popular Tags