KickJava   Java API By Example, From Geeks To Geeks.

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


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.UnsupportedEncodingException JavaDoc;
17 import java.security.cert.Certificate JavaDoc;
18 import java.security.cert.X509Certificate JavaDoc;
19 import java.util.Date JavaDoc;
20
21 import javax.ejb.CreateException JavaDoc;
22 import javax.ejb.EJBException JavaDoc;
23
24 import org.apache.log4j.Logger;
25 import org.ejbca.core.ejb.BaseEntityBean;
26 import org.ejbca.core.model.ca.store.CertReqHistory;
27 import org.ejbca.core.model.ra.UserDataVO;
28 import org.ejbca.util.CertTools;
29
30
31
32
33
34
35 /**
36  * Entity Bean storing historical information about the data user to
37  * create a certificate. Information stored:
38  * <pre>
39  * Primary Key (fingerprint, String)
40  * Issuer DN (issuerDN)
41  * Serial number (serialNumber)
42  * Username (username);
43  * Timestamp (timestamp)
44  * UserDataVO (userAdminData)
45  * </pre>
46  *
47  * @version $Id: CertReqHistoryDataBean.java,v 1.4 2006/11/10 09:28:51 anatom Exp $
48  *
49  * @ejb.bean description="This enterprise bean entity containing historical record over data user to generate a users certificate"
50  * display-name="CertReqHistoryDataEB"
51  * name="CertReqHistoryData"
52  * jndi-name="CertReqHistoryData"
53  * view-type="local"
54  * type="CMP"
55  * reentrant="False"
56  * cmp-version="2.x"
57  * transaction-type="Container"
58  * schema="CertReqHistoryDataBean"
59  *
60  * @ejb.transaction type="Required"
61  *
62  * @ejb.pk class="org.ejbca.core.ejb.ca.store.CertReqHistoryDataPK"
63  * extends="java.lang.Object"
64  * implements="java.io.Serializable"
65  *
66  * @ejb.persistence table-name = "CertReqHistoryData"
67  *
68  * @ejb.home
69  * generate="local"
70  * local-extends="javax.ejb.EJBLocalHome"
71  * local-class="org.ejbca.core.ejb.ca.store.CertReqHistoryDataLocalHome"
72  *
73  * @ejb.interface
74  * generate="local"
75  * local-extends="javax.ejb.EJBLocalObject"
76  * local-class="org.ejbca.core.ejb.ca.store.CertReqHistoryDataLocal"
77  *
78  * @ejb.finder description="findByIssuerDNSerialNumber"
79  * signature="Collection findByIssuerDNSerialNumber(java.lang.String issuerDN, java.lang.String serialNumber)"
80  * query="SELECT OBJECT(a) from CertReqHistoryDataBean a WHERE a.issuerDN=?1 AND a.serialNumber=?2"
81  *
82  * @ejb.finder description="findByUsername"
83  * signature="Collection findByUsername(java.lang.String username)"
84  * query="SELECT OBJECT(a) from CertReqHistoryDataBean a WHERE a.username=?1"
85  *
86  * @jonas.jdbc-mapping
87  * jndi-name="${datasource.jndi-name}"
88  */

89 public abstract class CertReqHistoryDataBean extends BaseEntityBean {
90
91     private static final Logger log = Logger.getLogger(CertReqHistoryDataBean.class);
92
93     /**
94      * DN of issuer of certificate
95      * Should be used outside of entity bean, use getCertReqHistory instead
96      *
97      * @return issuer dn
98      * @ejb.persistence column-name="issuerDN"
99      *
100      */

101     public abstract String JavaDoc getIssuerDN();
102
103     /**
104      * Use setIssuer instead
105      *
106      * @param issuerDN issuer dn
107      */

108     public abstract void setIssuerDN(String JavaDoc issuerDN);
109
110     /**
111      * Fingerprint of certificate
112      * Should be used outside of entity bean, use getCertReqHistory instead
113      *
114      * @return fingerprint
115      * @ejb.persistence column-name="fingerprint"
116      * @ejb.interface-method
117      * @ejb.pk-field
118      */

119     public abstract String JavaDoc getFingerprint();
120
121     /**
122      * Fingerprint of certificate
123      * Shouldn't be set after creation.
124      *
125      * @param fingerprint fingerprint
126      */

127     public abstract void setFingerprint(String JavaDoc fingerprint);
128
129     /**
130      * Serialnumber formated as BigInteger.toString()
131      * Should be used outside of entity bean, use getCertReqHistory instead
132      *
133      * @return serial number
134      * @ejb.persistence column-name="serialNumber"
135      */

136     public abstract String JavaDoc getSerialNumber();
137
138     /**
139      * Serialnumber formated as BigInteger.toString()
140      * Shouldn't be set after creation.
141      *
142      * @param serialNumber serial number
143      */

144     public abstract void setSerialNumber(String JavaDoc serialNumber);
145
146     /**
147      * Date formated as seconds since 1970 (== Date.getTime())
148      * Should be used outside of entity bean, use getCertReqHistory instead
149      *
150      * @return timestamp
151      * @ejb.persistence column-name="timestamp"
152      */

153     public abstract long getTimestamp();
154
155     /**
156      * Date formated as seconds since 1970 (== Date.getTime())
157      * Shouldn't be set after creation.
158      *
159      * @param timestamp when certificate request info was stored
160      */

161     public abstract void setTimestamp(long timestamp);
162
163
164     /**
165      * UserDataVO in xmlencoded String format
166      * Should be used outside of entity bean, use getCertReqHistory instead
167      *
168      * @return xmlencoded encoded UserDataVO
169      * @ejb.persistence jdbc-type="LONGVARCHAR" column-name="userDataVO"
170      */

171     public abstract String JavaDoc getUserDataVO();
172
173     /**
174      * UserDataVO in xmlencoded String format
175      * Shouldn't be set after creation.
176      *
177      * @param userDataVO xmlencoded encoded UserDataVO
178      */

179     public abstract void setUserDataVO(String JavaDoc userDataVO);
180
181     /**
182      * username in database
183      * Should be used outside of entity bean, use getCertReqHistory instead
184      *
185      * @return username
186      * @ejb.persistence column-name="username"
187      */

188     public abstract String JavaDoc getUsername();
189
190     /**
191      * username must be called 'striped' using StringTools.strip()
192      * Shouldn't be set after creation.
193      *
194      * @param username username
195      *
196      * @see org.ejbca.util.StringTools
197      */

198     public abstract void setUsername(String JavaDoc username);
199
200     //
201
// Public business methods used to help us manage certificates
202
//
203

204     /**
205      * Returns the value object containing the information of the entity bean.
206      * This is the method that should be used to retreive cert req history
207      * correctly.
208      *
209      * @return certificate request history object
210      * @ejb.interface-method
211      */

212     public CertReqHistory getCertReqHistory() {
213         
214         java.beans.XMLDecoder JavaDoc decoder;
215         try {
216           decoder =
217             new java.beans.XMLDecoder JavaDoc(
218                     new java.io.ByteArrayInputStream JavaDoc(getUserDataVO().getBytes("UTF8")));
219         } catch (UnsupportedEncodingException JavaDoc e) {
220           throw new EJBException JavaDoc(e);
221         }
222         UserDataVO useradmindata = (UserDataVO) decoder.readObject();
223         decoder.close();
224
225         return new CertReqHistory(this.getFingerprint(),this.getSerialNumber(),
226                 this.getIssuerDN(),this.getUsername(),new Date JavaDoc(this.getTimestamp()),
227                 useradmindata);
228     }
229
230     //
231
// Fields required by Container
232
//
233

234     /**
235      * Entity Bean holding info about a request data at the time the certificate was issued.
236      *
237      * @param incert the certificate issued
238      * @param UserDataVO, the data used to issue the certificate.
239      *
240      * @return primary key
241      * @ejb.create-method
242      */

243     public CertReqHistoryDataPK ejbCreate(Certificate JavaDoc incert, UserDataVO useradmindata)
244         throws CreateException JavaDoc {
245         // Exctract fields to store with the certificate.
246
X509Certificate JavaDoc tmpcert;
247
248         tmpcert = (X509Certificate JavaDoc) incert;
249         String JavaDoc fingerprint = CertTools.getFingerprintAsString(tmpcert);
250         setFingerprint(fingerprint);
251         setIssuerDN(CertTools.getIssuerDN(tmpcert));
252         log.debug("Creating certreqhistory data, serial=" + tmpcert.getSerialNumber().toString() + ", issuer=" + getIssuerDN());
253         setSerialNumber(tmpcert.getSerialNumber().toString());
254         setTimestamp(new Date JavaDoc().getTime());
255                     
256         setUsername(useradmindata.getUsername());
257         try {
258             // Save the user admin data in xml encoding.
259
java.io.ByteArrayOutputStream JavaDoc baos = new java.io.ByteArrayOutputStream JavaDoc();
260
261             java.beans.XMLEncoder JavaDoc encoder = new java.beans.XMLEncoder JavaDoc(baos);
262             encoder.writeObject(useradmindata);
263             encoder.close();
264
265             if (log.isDebugEnabled()) {
266                log.debug("useradmindata: \n" + baos.toString("UTF8"));
267             }
268             setUserDataVO(baos.toString("UTF8"));
269         } catch (UnsupportedEncodingException JavaDoc e) {
270             throw new EJBException JavaDoc(e);
271         }
272         return null;
273     }
274
275     /**
276      * required method, does nothing
277      *
278      * @param incert certificate
279      * @param UserDataVO, the data used to issue the certificate.
280      */

281     public void ejbPostCreate(Certificate JavaDoc incert, UserDataVO useradmindata) {
282         // Do nothing. Required.
283
}
284 }
285
Popular Tags