KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > ejb > hardtoken > HardTokenDataBean


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.hardtoken;
15
16 import javax.ejb.CreateException JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.Date JavaDoc;
19 import org.apache.log4j.Logger;
20 import org.ejbca.core.ejb.BaseEntityBean;
21 import org.ejbca.core.model.SecConst;
22 import org.ejbca.core.model.hardtoken.types.*;
23 import org.ejbca.util.StringTools;
24
25
26 /**
27  * Entity bean should not be used directly, use though Session beans.
28  *
29  * Entity Bean representing a hard token in the ra.
30  * Information stored:
31  * <pre>
32  * tokenSN (Primary key)
33  * cTime (createtime)
34  * username (username)
35  * mTime (modifytime)
36  * tokenType (tokentype)
37  * significantissuerdn (significantissuerdn), the CA the toke should belong to.
38  * data (Data saved concerning the hard token)
39  * </pre>
40  *
41  *
42  * @ejb.bean
43  * xxxxgenerate="false"
44  * description="This enterprise bean entity represents a hard token with accompanying data"
45  * display-name="HardTokenDataEB"
46  * name="HardTokenData"
47  * jndi-name="HardTokenData"
48  * view-type="local"
49  * type="CMP"
50  * reentrant="False"
51  * cmp-version="2.x"
52  * transaction-type="Container"
53  * schema="HardTokenDataBean"
54  * primkey-field="tokenSN"
55  *
56  * @ejb.pk generate="false"
57  * class="java.lang.String"
58  *
59  * @ejb.persistence table-name = "HardTokenData"
60  *
61  * @ejb.home
62  * generate="local"
63  * local-extends="javax.ejb.EJBLocalHome"
64  * local-class="org.ejbca.core.ejb.hardtoken.HardTokenDataLocalHome"
65  *
66  * @ejb.interface
67  * generate="local"
68  * local-extends="javax.ejb.EJBLocalObject"
69  * local-class="org.ejbca.core.ejb.hardtoken.HardTokenDataLocal"
70  *
71  * @ejb.finder
72  * description="findByUsername"
73  * signature="Collection findByUsername(java.lang.String username)"
74  * query="SELECT OBJECT(a) from HardTokenDataBean a WHERE a.username=?1"
75  *
76  * @ejb.transaction type="Required"
77  *
78  * @jonas.jdbc-mapping
79  * jndi-name="${datasource.jndi-name}"
80  */

81 public abstract class HardTokenDataBean extends BaseEntityBean {
82
83
84
85     private static final Logger log = Logger.getLogger(HardTokenIssuerDataBean.class);
86
87     /**
88      * @ejb.pk-field
89      * @ejb.persistence column-name="tokenSN"
90      * @ejb.interface-method view-type="local"
91      */

92     public abstract String JavaDoc getTokenSN();
93
94     /**
95      */

96     public abstract void setTokenSN(String JavaDoc tokensn);
97
98     /**
99      * @ejb.persistence column-name="username"
100      * @ejb.interface-method view-type="local"
101      */

102     public abstract String JavaDoc getUsername();
103
104     /**
105      * username must be called 'striped' using StringTools.strip()
106      * @see org.ejbca.util.StringTools
107      * @ejb.interface-method view-type="local"
108      */

109     public abstract void setUsername(String JavaDoc username);
110
111     /**
112      * @ejb.persistence column-name="cTime"
113      */

114     public abstract long getCtime();
115
116     /**
117      */

118     public abstract void setCtime(long createtime);
119
120     /**
121      * @ejb.persistence column-name="mTime"
122      */

123     public abstract long getMtime();
124
125     /**
126      */

127     public abstract void setMtime(long modifytime);
128
129     /**
130      * @ejb.persistence column-name="tokenType"
131      * @ejb.interface-method view-type="local"
132      */

133     public abstract int getTokenType();
134
135     /**
136      * @ejb.interface-method view-type="local"
137      */

138     public abstract void setTokenType(int tokentype);
139
140     /**
141      * @ejb.persistence column-name="significantIssuerDN"
142      * @ejb.interface-method view-type="local"
143      */

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

149     public abstract void setSignificantIssuerDN(String JavaDoc significantissuerdn);
150
151     /**
152      * @ejb.persistence column-name="data"
153      * @weblogic.ora.columntyp@
154      */

155     public abstract HashMap JavaDoc getData();
156
157     /**
158      */

159     public abstract void setData(HashMap JavaDoc data);
160
161     /**
162      * @ejb.interface-method view-type="local"
163      */

164     public Date JavaDoc getCreateTime(){ return new Date JavaDoc(getCtime()); }
165
166     /**
167      * @ejb.interface-method view-type="local"
168      */

169     public void setCreateTime(Date JavaDoc createtime){ setCtime(createtime.getTime()); }
170
171     /**
172      * @ejb.interface-method view-type="local"
173      */

174     public Date JavaDoc getModifyTime(){ return new Date JavaDoc(getCtime()); }
175
176     /**
177      * @ejb.interface-method view-type="local"
178      */

179     public void setModifyTime(Date JavaDoc modifytime){ setMtime(modifytime.getTime()); }
180
181     /**
182      * Method that returns the hard token issuer data and updates it if nessesary.
183      * @ejb.interface-method view-type="local"
184      */

185     public HardToken getHardToken(){
186       HardToken returnval = null;
187       HashMap JavaDoc data = getData();
188       int tokentype = ((Integer JavaDoc) data.get(HardToken.TOKENTYPE)).intValue();
189
190       switch(tokentype){
191           case SecConst.TOKEN_SWEDISHEID :
192              returnval = new SwedishEIDHardToken();
193              break;
194           case SecConst.TOKEN_ENHANCEDEID :
195              returnval = new EnhancedEIDHardToken();
196              break;
197           case SecConst.TOKEN_TURKISHEID :
198              returnval = new TurkishEIDHardToken();
199              break;
200           case SecConst.TOKEN_EID : // Left for backward compability
201
returnval = new EIDHardToken();
202              break;
203           default:
204              returnval = new EIDHardToken();
205              break;
206       }
207
208       returnval.loadData(data);
209       return returnval;
210     }
211
212     /**
213      * Method that saves the hard token issuer data to database.
214      * @ejb.interface-method view-type="local"
215      */

216     public void setHardToken(HardToken tokendata){
217        setData((HashMap JavaDoc) tokendata.saveData());
218     }
219
220
221     //
222
// Fields required by Container
223
//
224

225
226     /**
227      * Entity Bean holding data of a ahrd token issuer.
228      *
229      * @return null
230      * @ejb.create-method view-type="local"
231      */

232     public String JavaDoc ejbCreate(String JavaDoc tokensn, String JavaDoc username, Date JavaDoc createtime, Date JavaDoc modifytime, int tokentype, String JavaDoc significantissuerdn, HardToken tokendata) throws CreateException JavaDoc {
233         setTokenSN(tokensn);
234         setUsername(StringTools.strip(username));
235         setCtime(createtime.getTime());
236         setMtime(modifytime.getTime());
237         setTokenType(tokentype);
238         setSignificantIssuerDN(significantissuerdn);
239         setHardToken(tokendata);
240
241         log.debug("Created Hard Token "+ tokensn );
242         return tokensn;
243     }
244
245     public void ejbPostCreate(String JavaDoc tokensn, String JavaDoc username, Date JavaDoc createtime, Date JavaDoc modifytime, int tokentype, String JavaDoc significantissuerdn, HardToken tokendata) {
246         // Do nothing. Required.
247
}
248 }
249
Popular Tags