KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > ejb > ca > store > LocalCertificateStoreOnlyDataSessionBean


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.ejb.ca.store;
15
16 import java.math.BigInteger JavaDoc;
17 import java.security.cert.Certificate JavaDoc;
18 import java.security.cert.X509Certificate JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Date JavaDoc;
21
22 import javax.ejb.CreateException JavaDoc;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.log4j.Logger;
26 import org.ejbca.core.ejb.BaseSessionBean;
27 import org.ejbca.core.ejb.protect.TableProtectSessionLocalHome;
28 import org.ejbca.core.model.ca.crl.RevokedCertInfo;
29 import org.ejbca.core.model.log.Admin;
30 import org.ejbca.util.CertTools;
31
32 /**
33  * Stores certificate and CRL in the local database using Certificate and CRL Entity Beans.
34  * Uses JNDI name for datasource as defined in env 'Datasource' in ejb-jar.xml.
35  *
36  * @ejb.bean display-name="CertificateStoreOnlyDataSB"
37  * name="CertificateStoreOnlyDataSession"
38  * jndi-name="CertificateStoreOnlyDataSession"
39  * view-type="both"
40  * type="Stateless"
41  * transaction-type="Container"
42  *
43  * @ejb.transaction type="Supports"
44  *
45  * @weblogic.enable-call-by-reference True
46  *
47  * @ejb.env-entry description="JDBC datasource to be used"
48  * name="DataSource"
49  * type="java.lang.String"
50  * value="${datasource.jndi-name-prefix}${datasource.jndi-name}"
51  *
52  * @ejb.env-entry description="Enable or disable protection of database entrys"
53  * name="certSigning"
54  * type="java.lang.String"
55  * value="${protection.certprotect}"
56  *
57  * @ejb.ejb-external-ref description="The Certificate entity bean used to store and fetch certificates"
58  * view-type="local"
59  * ref-name="ejb/CertificateDataLocal"
60  * type="Entity"
61  * home="org.ejbca.core.ejb.ca.store.CertificateDataLocalHome"
62  * business="org.ejbca.core.ejb.ca.store.CertificateDataLocal"
63  * link="CertificateData"
64  *
65  * @ejb.ejb-external-ref
66  * description="The table protection session bean"
67  * view-type="local"
68  * ref-name="ejb/TableProtectSessionLocal"
69  * type="Session"
70  * home="org.ejbca.core.ejb.protect.TableProtectSessionLocalHome"
71  * business="org.ejbca.core.ejb.protect.TableProtectSessionLocal"
72  * link="TableProtectSession"
73  *
74  * @ejb.home extends="javax.ejb.EJBHome"
75  * local-extends="javax.ejb.EJBLocalHome"
76  * local-class="org.ejbca.core.ejb.ca.store.ICertificateStoreOnlyDataSessionLocalHome"
77  * remote-class="org.ejbca.core.ejb.ca.store.ICertificateStoreOnlyDataSessionHome"
78  *
79  * @ejb.interface extends="javax.ejb.EJBObject"
80  * local-extends="javax.ejb.EJBLocalObject"
81  * local-class="org.ejbca.core.ejb.ca.store.ICertificateStoreOnlyDataSessionLocal"
82  * remote-class="org.ejbca.core.ejb.ca.store.ICertificateStoreOnlyDataSessionRemote"
83  *
84  * @version $Id: LocalCertificateStoreOnlyDataSessionBean.java,v 1.9 2006/12/10 16:19:59 anatom Exp $
85  */

86 public class LocalCertificateStoreOnlyDataSessionBean extends BaseSessionBean {
87
88     /**
89      * The home interface of Certificate entity bean
90      */

91     private CertificateDataLocalHome certHome = null;
92     private final CertificateDataUtil.Adapter adapter;
93
94     /** The come interface of the protection session bean */
95     private TableProtectSessionLocalHome protecthome = null;
96     
97     public LocalCertificateStoreOnlyDataSessionBean() {
98         super();
99         CertTools.installBCProvider();
100         adapter = new MyAdapter();
101     }
102
103     /**
104      * Checks if a certificate is revoked.
105      *
106      * @param admin Administrator performing the operation
107      * @param issuerDN the DN of the issuer.
108      * @param serno the serialnumber of the certificate that will be checked
109      * @return RevokedCertInfo with revocation information, with reason RevokedCertInfo.NOT_REVOKED if NOT revoked. Returns null if certificate is not found.
110      * @ejb.interface-method
111      */

112     public RevokedCertInfo isRevoked(Admin admin, String JavaDoc issuerDN, BigInteger JavaDoc serno) {
113         return CertificateDataUtil.isRevoked(admin, issuerDN, serno, certHome, protecthome, adapter);
114     } //isRevoked
115

116     /**
117      * Finds a certificate specified by issuer DN and serial number.
118      *
119      * @param admin Administrator performing the operation
120      * @param issuerDN issuer DN of the desired certificate.
121      * @param serno serial number of the desired certificate!
122      * @return Certificate if found or null
123      * @ejb.interface-method
124      */

125     public Certificate JavaDoc findCertificateByIssuerAndSerno(Admin admin, String JavaDoc issuerDN, BigInteger JavaDoc serno) {
126         return CertificateDataUtil.findCertificateByIssuerAndSerno(admin, issuerDN, serno, certHome, adapter);
127     } //findCertificateByIssuerAndSerno
128

129     /**
130      * Lists all active (status = 20) certificates of a specific type and if
131      * given from a specific issuer.
132      * <p/>
133      * The type is the bitwise OR value of the types listed
134      * int {@link org.ejbca.core.ejb.ca.store.CertificateDataBean}:<br>
135      * <ul>
136      * <li><tt>CERTTYPE_ENDENTITY</tt><br>
137      * An user or machine certificate, which identifies a subject.
138      * </li>
139      * <li><tt>CERTTYPE_CA</tt><br>
140      * A CA certificate which is <b>not</b> a root CA.
141      * </li>
142      * <li><tt>CERTTYPE_ROOTCA</tt><br>
143      * A Root CA certificate.
144      * </li>
145      * </ul>
146      * <p/>
147      * Usage examples:<br>
148      * <ol>
149      * <li>Get all root CA certificates
150      * <p/>
151      * <code>
152      * ...
153      * ICertificateStoreOnlyDataSessionRemote itf = ...
154      * Collection certs = itf.findCertificatesByType(adm,
155      * CertificateDataBean.CERTTYPE_ROOTCA,
156      * null);
157      * ...
158      * </code>
159      * </li>
160      * <li>Get all subordinate CA certificates for a specific
161      * Root CA. It is assumed that the <tt>subjectDN</tt> of the
162      * Root CA certificate is located in the variable <tt>issuer</tt>.
163      * <p/>
164      * <code>
165      * ...
166      * ICertificateStoreOnlyDataSessionRemote itf = ...
167      * Certficate rootCA = ...
168      * String issuer = rootCA.getSubjectDN();
169      * Collection certs = itf.findCertificatesByType(adm,
170      * CertificateDataBean.CERTTYPE_SUBCA,
171      * issuer);
172      * ...
173      * </code>
174      * </li>
175      * <li>Get <b>all</b> CA certificates.
176      * <p/>
177      * <code>
178      * ...
179      * ICertificateStoreOnlyDataSessionRemote itf = ...
180      * Collection certs = itf.findCertificatesByType(adm,
181      * CertificateDataBean.CERTTYPE_SUBCA
182      * + CERTTYPE_ROOTCA,
183      * null);
184      * ...
185      * </code>
186      * </li>
187      * </ol>
188      *
189      * @param admin
190      * @param issuerDN get all certificates issued by a specific issuer.
191      * If <tt>null</tt> or empty return certificates regardless of
192      * the issuer.
193      * @param type CERTTYPE_* types from CertificateDataBean
194      * @return Collection Collection of X509Certificate, never <tt>null</tt>
195      * @ejb.interface-method
196      */

197     public Collection JavaDoc findCertificatesByType(Admin admin, int type, String JavaDoc issuerDN) {
198         return CertificateDataUtil.findCertificatesByType(admin, type, issuerDN, certHome, adapter);
199     } // findCertificatesByType
200

201     private class MyAdapter implements CertificateDataUtil.Adapter {
202         /* (non-Javadoc)
203          * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#getLogger()
204          */

205         public Logger getLogger() {
206             return log;
207         }
208         /* (non-Javadoc)
209          * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#log(org.ejbca.core.model.log.Admin, int, int, java.util.Date, java.lang.String, java.security.cert.X509Certificate, int, java.lang.String)
210          */

211         public void log(Admin admin, int caid, int module, Date JavaDoc time, String JavaDoc username, X509Certificate JavaDoc certificate, int event, String JavaDoc comment) {
212             // no log bean available
213
}
214         /* (non-Javadoc)
215          * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#debug(java.lang.String)
216          */

217         public void debug(String JavaDoc s) {
218             LocalCertificateStoreOnlyDataSessionBean.this.debug(s);
219         }
220         /* (non-Javadoc)
221          * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#error(java.lang.String)
222          */

223         public void error(String JavaDoc s) {
224             LocalCertificateStoreOnlyDataSessionBean.this.error(s);
225         }
226         /* (non-Javadoc)
227          * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#error(java.lang.String)
228          */

229         public void error(String JavaDoc s, Exception JavaDoc e) {
230             LocalCertificateStoreOnlyDataSessionBean.this.error(s, e);
231         }
232     }
233
234     /**
235      * Default create for SessionBean without any creation Arguments.
236      *
237      * @throws CreateException if bean instance can't be created
238      */

239     public void ejbCreate() {
240         certHome = (CertificateDataLocalHome) getLocator().getLocalHome(CertificateDataLocalHome.COMP_NAME);
241         String JavaDoc sign = getLocator().getString("java:comp/env/certSigning");
242         if (StringUtils.equalsIgnoreCase(sign, "true")) {
243             protecthome = (TableProtectSessionLocalHome) getLocator().getLocalHome(TableProtectSessionLocalHome.COMP_NAME);
244         }
245     }
246
247 }
248
Popular Tags