1 13 14 package org.ejbca.core.ejb.ca.store; 15 16 import java.io.UnsupportedEncodingException ; 17 import java.security.cert.Certificate ; 18 import java.security.cert.X509Certificate ; 19 import java.util.Date ; 20 21 import javax.ejb.CreateException ; 22 import javax.ejb.EJBException ; 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 89 public abstract class CertReqHistoryDataBean extends BaseEntityBean { 90 91 private static final Logger log = Logger.getLogger(CertReqHistoryDataBean.class); 92 93 101 public abstract String getIssuerDN(); 102 103 108 public abstract void setIssuerDN(String issuerDN); 109 110 119 public abstract String getFingerprint(); 120 121 127 public abstract void setFingerprint(String fingerprint); 128 129 136 public abstract String getSerialNumber(); 137 138 144 public abstract void setSerialNumber(String serialNumber); 145 146 153 public abstract long getTimestamp(); 154 155 161 public abstract void setTimestamp(long timestamp); 162 163 164 171 public abstract String getUserDataVO(); 172 173 179 public abstract void setUserDataVO(String userDataVO); 180 181 188 public abstract String getUsername(); 189 190 198 public abstract void setUsername(String username); 199 200 204 212 public CertReqHistory getCertReqHistory() { 213 214 java.beans.XMLDecoder decoder; 215 try { 216 decoder = 217 new java.beans.XMLDecoder ( 218 new java.io.ByteArrayInputStream (getUserDataVO().getBytes("UTF8"))); 219 } catch (UnsupportedEncodingException e) { 220 throw new EJBException (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 (this.getTimestamp()), 227 useradmindata); 228 } 229 230 234 243 public CertReqHistoryDataPK ejbCreate(Certificate incert, UserDataVO useradmindata) 244 throws CreateException { 245 X509Certificate tmpcert; 247 248 tmpcert = (X509Certificate ) incert; 249 String 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 ().getTime()); 255 256 setUsername(useradmindata.getUsername()); 257 try { 258 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream (); 260 261 java.beans.XMLEncoder encoder = new java.beans.XMLEncoder (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 e) { 270 throw new EJBException (e); 271 } 272 return null; 273 } 274 275 281 public void ejbPostCreate(Certificate incert, UserDataVO useradmindata) { 282 } 284 } 285 | Popular Tags |