KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > ejb > keyrecovery > KeyRecoveryDataBean


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.keyrecovery;
15
16 import org.apache.log4j.Logger;
17 import org.ejbca.core.ejb.BaseEntityBean;
18 import org.ejbca.util.Base64;
19 import org.ejbca.util.StringTools;
20
21
22
23 import javax.ejb.CreateException JavaDoc;
24 import java.math.BigInteger JavaDoc;
25
26
27 /**
28  * Entity bean should not be used directly, use though Session beans. Entity Bean representing a
29  * certificates key recovery data in the ra. Information stored:
30  * <pre>
31  * pk (Primary key, hashcodes of certificatesn and issuerdn)
32  * certificatesn
33  * issuerdn
34  * username
35  * markedasrecoverable
36  * keypair
37  * </pre>
38  *
39  * @version $Id: KeyRecoveryDataBean.java,v 1.5 2006/11/10 09:29:11 anatom Exp $
40  *
41  * @ejb.bean
42  * description="Stores key recovery data"
43  * display-name="KeyRecoveryDataEB"
44  * name="KeyRecoveryData"
45  * jndi-name="KeyRecoveryData"
46  * view-type="local"
47  * type="CMP"
48  * reentrant="False"
49  * cmp-version="2.x"
50  * transaction-type="Container"
51  * schema="KeyRecoveryDataBean"
52  *
53  * @ejb.pk
54  * class="org.ejbca.core.ejb.keyrecovery.KeyRecoveryDataPK"
55  * extends="java.lang.Object"
56  * implements="java.io.Serializable"
57  *
58  * @ejb.persistence table-name = "KeyRecoveryData"
59  *
60  * @ejb.home
61  * generate="local"
62  * local-extends="javax.ejb.EJBLocalHome"
63  * local-class="org.ejbca.core.ejb.keyrecovery.KeyRecoveryDataLocalHome"
64  *
65  * @ejb.interface
66  * generate="local"
67  * local-extends="javax.ejb.EJBLocalObject"
68  * local-class="org.ejbca.core.ejb.keyrecovery.KeyRecoveryDataLocal"
69  *
70  * @ejb.finder
71  * description="findByUsername"
72  * signature="Collection findByUsername(java.lang.String username)"
73  * query="SELECT OBJECT(a) from KeyRecoveryDataBean a WHERE a.username=?1"
74  *
75  * @ejb.finder
76  * description="findByUserMark"
77  * signature="Collection findByUserMark(java.lang.String usermark)"
78  * query="SELECT OBJECT(a) from KeyRecoveryDataBean a WHERE a.username=?1 AND a.markedAsRecoverable=TRUE"
79  *
80  * @ejb.transaction type="Required"
81  *
82  * @jonas.bean
83  * ejb-name="KeyRecoveryData"
84  * jndi-name="KeyRecoveryData"
85  *
86  * @jonas.jdbc-mapping
87  * jndi-name="${datasource.jndi-name}"
88  */

89 public abstract class KeyRecoveryDataBean extends BaseEntityBean {
90     private static final Logger log = Logger.getLogger(KeyRecoveryDataBean.class);
91
92     /**
93      * @ejb.persistence column-name="certSN"
94      * @ejb.pk-field
95      */

96     public abstract String JavaDoc getCertSN();
97
98     /**
99      */

100     public abstract void setCertSN(String JavaDoc certificatesn);
101
102     /**
103      * @ejb.persistence column-name="issuerDN"
104      * @ejb.pk-field
105      * @ejb.interface-method view-type="local"
106      */

107     public abstract String JavaDoc getIssuerDN();
108
109     /**
110      */

111     public abstract void setIssuerDN(String JavaDoc issuerdn);
112
113     /**
114      * @ejb.persistence column-name="username"
115      * @ejb.interface-method view-type="local"
116      */

117     public abstract String JavaDoc getUsername();
118
119     /**
120      * username must be called 'striped' using StringTools.strip()
121      *
122      * @see org.ejbca.util.StringTools
123      * @ejb.interface-method view-type="local"
124      */

125     public abstract void setUsername(String JavaDoc username);
126
127     /**
128      * @ejb.persistence column-name="markedAsRecoverable"
129      * @ejb.interface-method view-type="local"
130      */

131     public abstract boolean getMarkedAsRecoverable();
132
133     /**
134      * @ejb.interface-method view-type="local"
135      */

136     public abstract void setMarkedAsRecoverable(boolean markedasrecoverable);
137
138     /**
139      * @ejb.persistence jdbc-type="LONGVARCHAR" column-name="keyData"
140      */

141     public abstract String JavaDoc getKeyData();
142
143     /**
144      */

145     public abstract void setKeyData(String JavaDoc keydata);
146
147     /**
148      * @ejb.interface-method view-type="local"
149      */

150     public BigInteger JavaDoc getCertificateSN() {
151         return new BigInteger JavaDoc(getCertSN(), 16);
152     }
153
154     /**
155      * @ejb.interface-method view-type="local"
156      */

157     public void setCertificateSN(BigInteger JavaDoc certificatesn) {
158         setCertSN(certificatesn.toString(16));
159     }
160
161     /**
162      * @ejb.interface-method view-type="local"
163      */

164     public byte[] getKeyDataAsByteArray() {
165         return Base64.decode(this.getKeyData().getBytes());
166     }
167
168     /**
169      * @ejb.interface-method view-type="local"
170      */

171     public void setKeyDataFromByteArray(byte[] keydata) {
172         setKeyData(new String JavaDoc(Base64.encode(keydata)));
173     }
174
175     //
176
// Fields required by Container
177
//
178

179     /**
180      * Entity Bean holding keyrecovery data of users certificate.
181      *
182      * @param certificatesn of certificate the keys are belonging to.
183      * @param issuerdn issuerdn of certificate the keys are belonging to.
184      * @param username of the owner of the keys.
185      * @param keydata the actual keydata.
186      *
187      * @return Primary Key
188      *
189      * @ejb.create-method
190      */

191     public KeyRecoveryDataPK ejbCreate(BigInteger JavaDoc certificatesn, String JavaDoc issuerdn, String JavaDoc username,
192                                        byte[] keydata) throws CreateException JavaDoc {
193         setCertificateSN(certificatesn);
194         setIssuerDN(issuerdn);
195         setUsername(StringTools.strip(username));
196         setMarkedAsRecoverable(false);
197         setKeyDataFromByteArray(keydata);
198         KeyRecoveryDataPK pk = new KeyRecoveryDataPK(getCertSN(), issuerdn);
199         log.debug("Created Key Recoverydata for user " + username);
200         return pk;
201     }
202
203     public void ejbPostCreate(BigInteger JavaDoc certificatesn, String JavaDoc issuerdn, String JavaDoc username,
204                               byte[] keydata) {
205         // Do nothing. Required.
206
}
207
208 }
209
Popular Tags