1 13 14 package org.ejbca.core.model.ra; 15 16 import java.io.Serializable ; 17 import java.util.Date ; 18 import java.util.HashMap ; 19 20 import javax.ejb.EJBException ; 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 34 public class UserDataVO implements Serializable { 35 36 45 private static final long serialVersionUID = 3837505643343885941L; 46 47 public static final int NO_ENDENTITYPROFILE = 0; 49 public static final int NO_CERTIFICATEPROFILE = 0; 50 51 52 private String username; 53 private String subjectDN; 54 private int caid; 55 private String subjectAltName; 56 private String subjectEmail; 57 private String password; 58 private int status; 59 60 private int type; 61 private int endentityprofileid; 62 private int certificateprofileid; 63 private Date timecreated; 64 private Date timemodified; 65 private int tokentype; 66 private int hardtokenissuerid; 67 private ExtendedInformation extendedinformation; 68 69 70 public UserDataVO() { 71 } 72 73 90 public UserDataVO(String user, String dn, int caid, String subjectaltname, String email, int status, int type, int endentityprofileid, int certificateprofileid, 91 Date timecreated, Date 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 124 public UserDataVO(String user, String dn, int caid, String subjectaltname, String 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 user) { this.username=StringTools.putBase64String(StringTools.strip(user));} 142 public String getUsername() {return StringTools.getBase64String(username);} 143 public void setDN(String dn) {this.subjectDN=StringTools.putBase64String(dn);} 144 public String 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 subjectaltname) { this.subjectAltName=StringTools.putBase64String(subjectaltname); } 148 public String getSubjectAltName() {return StringTools.getBase64String(subjectAltName);} 149 public void setEmail(String email) {this.subjectEmail = StringTools.putBase64String(email);} 150 public String getEmail() {return StringTools.getBase64String(subjectEmail);} 151 public void setPassword(String pwd) {this.password = StringTools.putBase64String(pwd);} 152 public String 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 timecreated) { this.timecreated=timecreated; } 162 public Date getTimeCreated() {return this.timecreated;} 163 public void setTimeModified(Date timemodified) { this.timemodified=timemodified; } 164 public Date 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 217 public ExtendedInformation getExtendedinformation() { 218 if (extendedinformation == null) { 220 return new ExtendedInformation(); 221 } 222 return extendedinformation; 223 } 224 227 public void setExtendedinformation(ExtendedInformation extendedinformation) { 228 this.extendedinformation = extendedinformation; 229 } 230 231 232 236 public static ExtendedInformation getExtendedInformation(String extendedinfostring) { 237 ExtendedInformation returnval = null; 238 if (extendedinfostring != null) { 239 java.beans.XMLDecoder decoder; 240 try { 241 decoder = new java.beans.XMLDecoder (new java.io.ByteArrayInputStream (extendedinfostring.getBytes("UTF8"))); 242 243 HashMap h = (HashMap ) decoder.readObject(); 244 decoder.close(); 245 HashMap data = new Base64GetHashMap(h); 247 248 int type = ((Integer ) 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 e) { 261 throw new EJBException ("Problems generating extended information from String",e); 262 } 263 } 264 return returnval; 265 } 266 } 267 | Popular Tags |