KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
17 import java.security.cert.CRLException JavaDoc;
18 import java.security.cert.X509CRL JavaDoc;
19 import java.util.Date JavaDoc;
20
21 import javax.ejb.CreateException JavaDoc;
22
23 import org.apache.log4j.Logger;
24 import org.ejbca.core.ejb.BaseEntityBean;
25 import org.ejbca.util.Base64;
26 import org.ejbca.util.CertTools;
27
28
29
30 /**
31  * Entity Bean representing a CRL. Information stored:
32  * <pre>
33  * CRL (base64Crl)
34  * IssuerDN (issuerDN)
35  * CRLNumber (CRLNumber)
36  * SHA1 fingerprint (fingerprint)
37  * CA SHA1 fingerprint (cAFingerprint)
38  * thisUpdate (thisUpdate)
39  * nextUpdate (nextUpdate)
40  * </pre>
41  *
42  * @version $Id: CRLDataBean.java,v 1.4 2006/11/10 09:28:51 anatom Exp $
43  *
44  * @ejb.bean description="This enterprise bean entity represents a CRL with accompanying data"
45  * display-name="CRLDataEB"
46  * name="CRLData"
47  * jndi-name="CRLData"
48  * view-type="local"
49  * type="CMP"
50  * reentrant="False"
51  * cmp-version="2.x"
52  * transaction-type="Container"
53  * schema="CRLDataBean"
54  *
55  * @ejb.transaction type="Required"
56  *
57  * @ejb.pk class="org.ejbca.core.ejb.ca.store.CRLDataPK"
58  * extends="java.lang.Object"
59  * implements="java.io.Serializable"
60  *
61  * @ejb.persistence table-name = "CRLData"
62
63  * @ejb.home
64  * generate="local"
65  * local-extends="javax.ejb.EJBLocalHome"
66  * local-class="org.ejbca.core.ejb.ca.store.CRLDataLocalHome"
67  *
68  * @ejb.interface
69  * generate="local"
70  * local-extends="javax.ejb.EJBLocalObject"
71  * local-class="org.ejbca.core.ejb.ca.store.CRLDataLocal"
72  *
73  * @ejb.finder description="findByIssuerDNAndCRLNumber"
74  * signature="org.ejbca.core.ejb.ca.store.CRLDataLocal findByIssuerDNAndCRLNumber(java.lang.String issuerdn, int cRLNumber)"
75  * query="SELECT OBJECT(a) from CRLDataBean a WHERE a.issuerDN=?1 AND a.crlNumber=?2"
76  *
77  * @jonas.jdbc-mapping
78  * jndi-name="${datasource.jndi-name}"
79  */

80 public abstract class CRLDataBean extends BaseEntityBean {
81     private static final Logger log = Logger.getLogger(CRLDataBean.class);
82
83     /**
84      * @ejb.persistence column-name="cRLNumber"
85      * @ejb.interface-method
86      */

87     public abstract int getCrlNumber();
88
89     /**
90      * @ejb.interface-method
91      */

92     public abstract void setCrlNumber(int crlNumber);
93
94     /**
95      * @ejb.persistence column-name="issuerDN"
96      * @ejb.interface-method
97      */

98     public abstract String JavaDoc getIssuerDN();
99
100     /**
101      * Use setIssuer instead
102      *
103      * @see #setIssuer(String)
104      */

105     public abstract void setIssuerDN(String JavaDoc issuerDN);
106
107     /**
108      * @ejb.pk-field
109      * @ejb.persistence column-name="fingerprint"
110      * @ejb.interface-method
111      */

112     public abstract String JavaDoc getFingerprint();
113
114     /**
115      */

116     public abstract void setFingerprint(String JavaDoc fingerprint);
117
118     /**
119      * @ejb.persistence column-name="cAFingerprint"
120      * @ejb.interface-method
121      */

122     public abstract String JavaDoc getCaFingerprint();
123
124     /**
125      * @ejb.interface-method
126      */

127     public abstract void setCaFingerprint(String JavaDoc caFingerprint);
128
129     /**
130      * @ejb.persistence column-name="thisUpdate"
131      * @ejb.interface-method
132      */

133     public abstract long getThisUpdate();
134
135     /**
136      * Date formated as seconds since 1970 (== Date.getTime())
137      * @ejb.interface-method
138      */

139     public abstract void setThisUpdate(long thisUpdate);
140
141     /**
142      * @ejb.persistence column-name="nextUpdate"
143      * @ejb.interface-method
144      */

145     public abstract long getNextUpdate();
146
147     /**
148      * Date formated as seconds since 1970 (== Date.getTime())
149      * @ejb.interface-method
150      */

151     public abstract void setNextUpdate(long nextUpdate);
152
153     /**
154      * @ejb.persistence jdbc-type="LONGVARCHAR" column-name="base64Crl"
155      * @ejb.interface-method
156      */

157     public abstract String JavaDoc getBase64Crl();
158
159     /**
160      * @ejb.interface-method
161      */

162     public abstract void setBase64Crl(String JavaDoc base64Crl);
163
164     //
165
// Public methods used to help us manage CRLs
166
//
167
/**
168      * @ejb.interface-method
169      */

170     public X509CRL JavaDoc getCRL() {
171         X509CRL JavaDoc crl = null;
172         try {
173             String JavaDoc b64Crl = getBase64Crl();
174             crl = CertTools.getCRLfromByteArray(Base64.decode(b64Crl.getBytes()));
175         } catch (IOException JavaDoc ioe) {
176             log.error("Can't decode CRL.", ioe);
177             return null;
178         } catch (CRLException JavaDoc ce) {
179             log.error("Can't decode CRL.", ce);
180             return null;
181         }
182         return crl;
183     }
184
185     /**
186      * @ejb.interface-method
187      */

188     public void setCRL(X509CRL JavaDoc incrl) {
189         try {
190             String JavaDoc b64Crl = new String JavaDoc(Base64.encode((incrl).getEncoded()));
191             setBase64Crl(b64Crl);
192         } catch (CRLException JavaDoc ce) {
193             log.error("Can't extract DER encoded CRL.", ce);
194         }
195     }
196
197     /**
198      * @ejb.interface-method
199      */

200     public void setIssuer(String JavaDoc dn) {
201         setIssuerDN(CertTools.stringToBCDNString(dn));
202     }
203
204     /**
205      * @ejb.interface-method
206      */

207     public void setThisUpdate(Date JavaDoc thisUpdate) {
208         if (thisUpdate == null) {
209             setThisUpdate(-1L);
210         }
211
212         setThisUpdate(thisUpdate.getTime());
213     }
214
215     /**
216      * @ejb.interface-method
217      */

218     public void setNextUpdate(Date JavaDoc nextUpdate) {
219         if (nextUpdate == null) {
220             setNextUpdate(-1L);
221         }
222
223         setNextUpdate(nextUpdate.getTime());
224     }
225
226     //
227
// Fields required by Container
228
//
229

230     /**
231      * Entity Bean holding info about a CRL. Create by sending in the CRL, which extracts (from the
232      * crl) fingerprint (primary key), CRLNumber, issuerDN, thisUpdate, nextUpdate. CAFingerprint
233      * are set to default values (null) and should be set using the respective set-methods.
234      *
235      * @param incrl the (X509)CRL to be stored in the database.
236      * @param number monotonically increasnig CRL number
237      *
238      * @ejb.create-method
239      */

240     public CRLDataPK ejbCreate(X509CRL JavaDoc incrl, int number)
241         throws CreateException JavaDoc {
242         // Exctract all fields to store with the certificate.
243
try {
244             String JavaDoc b64Crl = new String JavaDoc(Base64.encode(incrl.getEncoded()));
245             setBase64Crl(b64Crl);
246             setFingerprint(CertTools.getFingerprintAsString(incrl));
247
248             // Make sure names are always looking the same
249
setIssuerDN(CertTools.getIssuerDN(incrl));
250             log.debug("Creating crldata, issuer=" + getIssuerDN());
251
252             // Default values for cafp
253
setCaFingerprint(null);
254             setCrlNumber(number);
255             setThisUpdate(incrl.getThisUpdate());
256             setNextUpdate(incrl.getNextUpdate());
257         } catch (CRLException JavaDoc ce) {
258             log.error("Can't extract DER encoded CRL.", ce);
259
260             return null;
261         }
262
263         CRLDataPK pk = new CRLDataPK(getFingerprint());
264
265         return pk;
266     }
267
268     /**
269      * DOCUMENT ME!
270      *
271      * @param incrl DOCUMENT ME!
272      * @param number DOCUMENT ME!
273      */

274     public void ejbPostCreate(X509CRL JavaDoc incrl, int number) {
275         // Do nothing. Required.
276
}
277 }
278
Popular Tags