KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ra > UserDataVO


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.model.ra;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.Date JavaDoc;
18 import java.util.HashMap JavaDoc;
19
20 import javax.ejb.EJBException JavaDoc;
21
22 import org.ejbca.core.ejb.ra.UserDataBean;
23 import org.ejbca.core.model.SecConst;
24 import org.ejbca.core.model.ra.ExtendedInformation;
25 import org.ejbca.util.Base64GetHashMap;
26 import org.ejbca.util.StringTools;
27
28
29 /**
30  * Holds admin data collected from UserData in the database. Strings are stored in Base64 encoded format to be safe for storing in database, xml etc.
31  *
32  * @version $Id: UserDataVO.java,v 1.9 2006/11/03 17:10:23 anatom Exp $
33  */

34 public class UserDataVO implements Serializable JavaDoc {
35
36     /**
37      * Determines if a de-serialized file is compatible with this class.
38      *
39      * Maintainers must change this value if and only if the new version
40      * of this class is not compatible with old versions. See Sun docs
41      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
42      * /serialization/spec/version.doc.html> details. </a>
43      *
44      */

45     private static final long serialVersionUID = 3837505643343885941L;
46
47     // Public constants
48
public static final int NO_ENDENTITYPROFILE = 0;
49     public static final int NO_CERTIFICATEPROFILE = 0;
50
51
52     private String JavaDoc username;
53     private String JavaDoc subjectDN;
54     private int caid;
55     private String JavaDoc subjectAltName;
56     private String JavaDoc subjectEmail;
57     private String JavaDoc password;
58     private int status;
59     /** Type of user, from SecConst */
60     private int type;
61     private int endentityprofileid;
62     private int certificateprofileid;
63     private Date JavaDoc timecreated;
64     private Date JavaDoc timemodified;
65     private int tokentype;
66     private int hardtokenissuerid;
67     private ExtendedInformation extendedinformation;
68
69     /** Creates new empty UserDataVO */
70     public UserDataVO() {
71     }
72
73     /**
74      * Creates new UserDataVO. All fields are almos required in this constructor. Password must
75      * be set amnually though. This is so you should be sure what you do with the password.
76      *
77      * @param user DOCUMENT ME!
78      * @param dn DOCUMENT ME!
79      * @param subjectaltname DOCUMENT ME!
80      * @param email DOCUMENT ME!
81      * @param status DOCUMENT ME!
82      * @param type one of SecConst.ENDUSER || ...
83      * @param endentityprofileid DOCUMENT ME!
84      * @param certificateprofileid DOCUMENT ME!
85      * @param timecreated DOCUMENT ME!
86      * @param timemodified DOCUMENT ME!
87      * @param tokentype DOCUMENT ME!
88      * @param hardtokenissuerid DOCUMENT ME!
89      */

90     public UserDataVO(String JavaDoc user, String JavaDoc dn, int caid, String JavaDoc subjectaltname, String JavaDoc email, int status, int type, int endentityprofileid, int certificateprofileid,
91                          Date JavaDoc timecreated, Date JavaDoc timemodified, int tokentype, int hardtokenissuerid, ExtendedInformation extendedinfo) {
92         setUsername(user);
93         setPassword(null);
94         setDN(dn);
95         setCAId(caid);
96         setSubjectAltName(subjectaltname);
97         setEmail(email);
98         setStatus(status);
99         setType(type);
100         setEndEntityProfileId(endentityprofileid);
101         setCertificateProfileId(certificateprofileid);
102         setTimeCreated(timecreated);
103         setTimeModified(timemodified);
104         setTokenType(tokentype);
105         setHardTokenIssuerId(hardtokenissuerid);
106         setExtendedinformation(extendedinfo);
107     }
108     
109     /**
110      * Creates new UserDataVO. This constructor shouldonly be used from UserDataSource
111      * implementations. Status and dates aren't used in these cases.
112      *
113      * @param user
114      * @param dn
115      * @param subjectaltname
116      * @param email
117      * @param type one of SecConst.ENDUSER || ...
118      * @param endentityprofileid
119      * @param certificateprofileid
120      * @param tokentype
121      * @param hardtokenissuerid
122      * @param extendedinfo
123      */

124     public UserDataVO(String JavaDoc user, String JavaDoc dn, int caid, String JavaDoc subjectaltname, String JavaDoc email, int type, int endentityprofileid, int certificateprofileid,
125                           int tokentype, int hardtokenissuerid, ExtendedInformation extendedinfo) {
126         setUsername(user);
127         setPassword(null);
128         setDN(dn);
129         setCAId(caid);
130         setSubjectAltName(subjectaltname);
131         setEmail(email);
132         setType(type);
133         setEndEntityProfileId(endentityprofileid);
134         setCertificateProfileId(certificateprofileid);
135         setTokenType(tokentype);
136         setHardTokenIssuerId(hardtokenissuerid);
137         setExtendedinformation(extendedinfo);
138     }
139     
140     
141     public void setUsername(String JavaDoc user) { this.username=StringTools.putBase64String(StringTools.strip(user));}
142     public String JavaDoc getUsername() {return StringTools.getBase64String(username);}
143     public void setDN(String JavaDoc dn) {this.subjectDN=StringTools.putBase64String(dn);}
144     public String JavaDoc getDN() {return StringTools.getBase64String(subjectDN);}
145     public int getCAId(){return this.caid;}
146     public void setCAId(int caid){this.caid=caid;}
147     public void setSubjectAltName( String JavaDoc subjectaltname) { this.subjectAltName=StringTools.putBase64String(subjectaltname); }
148     public String JavaDoc getSubjectAltName() {return StringTools.getBase64String(subjectAltName);}
149     public void setEmail(String JavaDoc email) {this.subjectEmail = StringTools.putBase64String(email);}
150     public String JavaDoc getEmail() {return StringTools.getBase64String(subjectEmail);}
151     public void setPassword(String JavaDoc pwd) {this.password = StringTools.putBase64String(pwd);}
152     public String JavaDoc getPassword() {return StringTools.getBase64String(password);}
153     public void setStatus(int status) {this.status=status;}
154     public int getStatus() {return status;}
155     public void setType(int type) {this.type=type;}
156     public int getType() {return type;}
157     public void setEndEntityProfileId(int endentityprofileid) { this.endentityprofileid=endentityprofileid; }
158     public int getEndEntityProfileId(){ return this.endentityprofileid; }
159     public void setCertificateProfileId(int certificateprofileid) { this.certificateprofileid=certificateprofileid; }
160     public int getCertificateProfileId() {return this.certificateprofileid;}
161     public void setTimeCreated(Date JavaDoc timecreated) { this.timecreated=timecreated; }
162     public Date JavaDoc getTimeCreated() {return this.timecreated;}
163     public void setTimeModified(Date JavaDoc timemodified) { this.timemodified=timemodified; }
164     public Date JavaDoc getTimeModified() {return this.timemodified;}
165     public int getTokenType(){ return this.tokentype;}
166     public void setTokenType(int tokentype) {this.tokentype=tokentype;}
167     public int getHardTokenIssuerId() {return this.hardtokenissuerid;}
168     public void setHardTokenIssuerId(int hardtokenissuerid) { this.hardtokenissuerid=hardtokenissuerid;}
169
170     public boolean getAdministrator(){
171       return (type & SecConst.USER_ADMINISTRATOR) == SecConst.USER_ADMINISTRATOR;
172     }
173
174     public void setAdministrator(boolean administrator){
175       if(administrator)
176         type = type | SecConst.USER_ADMINISTRATOR;
177       else
178         type = type & (~SecConst.USER_ADMINISTRATOR);
179     }
180
181     public boolean getKeyRecoverable(){
182       return (type & SecConst.USER_KEYRECOVERABLE) == SecConst.USER_KEYRECOVERABLE;
183     }
184
185     public void setKeyRecoverable(boolean keyrecoverable){
186       if(keyrecoverable)
187         type = type | SecConst.USER_KEYRECOVERABLE;
188       else
189         type = type & (~SecConst.USER_KEYRECOVERABLE);
190     }
191
192     public boolean getSendNotification(){
193       return (type & SecConst.USER_SENDNOTIFICATION) == SecConst.USER_SENDNOTIFICATION;
194     }
195
196     public void setSendNotification(boolean sendnotification){
197       if(sendnotification)
198         type = type | SecConst.USER_SENDNOTIFICATION;
199       else
200         type = type & (~SecConst.USER_SENDNOTIFICATION);
201     }
202     
203     public boolean getPrintUserData(){
204         return (type & SecConst.USER_SENDNOTIFICATION) == SecConst.USER_SENDNOTIFICATION;
205       }
206
207     public void setPrintUserData(boolean printUserData){
208         if(printUserData)
209           type = type | SecConst.USER_PRINT;
210         else
211           type = type & (~SecConst.USER_PRINT);
212    }
213
214     /**
215      * @return Returns the extendedinformation.
216      */

217     public ExtendedInformation getExtendedinformation() {
218         // If there is no extended information for this user, we return a new emtpy one
219
if (extendedinformation == null) {
220             return new ExtendedInformation();
221         }
222         return extendedinformation;
223     }
224     /**
225      * @param extendedinformation The extendedinformation to set.
226      */

227     public void setExtendedinformation(ExtendedInformation extendedinformation) {
228         this.extendedinformation = extendedinformation;
229     }
230     
231     
232     /**
233      * Help Method used to create an ExtendedInformation from String representation.
234      * Used when creating an ExtendedInformation from queries.
235      */

236     public static ExtendedInformation getExtendedInformation(String JavaDoc extendedinfostring) {
237         ExtendedInformation returnval = null;
238         if (extendedinfostring != null) {
239             java.beans.XMLDecoder JavaDoc decoder;
240             try {
241                 decoder = new java.beans.XMLDecoder JavaDoc(new java.io.ByteArrayInputStream JavaDoc(extendedinfostring.getBytes("UTF8")));
242                 
243                 HashMap JavaDoc h = (HashMap JavaDoc) decoder.readObject();
244                 decoder.close();
245                 // Handle Base64 encoded string values
246
HashMap JavaDoc data = new Base64GetHashMap(h);
247                 
248                 int type = ((Integer JavaDoc) data.get(ExtendedInformation.TYPE)).intValue();
249                 switch(type){
250                   case ExtendedInformation.TYPE_SCEPRA :
251                     returnval = (ExtendedInformation) UserDataBean.class.getClassLoader().loadClass(SCEPRAExtendedInformation.class.getName()).newInstance();
252                     returnval.loadData(data);
253                     break;
254                   case ExtendedInformation.TYPE_BASIC :
255                     returnval = (ExtendedInformation) UserDataBean.class.getClassLoader().loadClass(ExtendedInformation.class.getName()).newInstance();
256                     returnval.loadData(data);
257                     break;
258
259                 }
260             }catch (Exception JavaDoc e) {
261                 throw new EJBException JavaDoc("Problems generating extended information from String",e);
262             }
263         }
264         return returnval;
265     }
266 }
267
Popular Tags