1 13 package org.ejbca.core.model.approval; 14 15 import java.io.Externalizable ; 16 import java.io.IOException ; 17 import java.io.ObjectInput ; 18 import java.io.ObjectOutput ; 19 import java.math.BigInteger ; 20 import java.security.cert.X509Certificate ; 21 import java.util.Date ; 22 23 24 import org.ejbca.util.CertTools; 25 26 27 28 42 43 public class Approval implements Comparable , Externalizable { 44 45 private static final long serialVersionUID = -1L; 46 47 private static final int LATEST_VERSION = 1; 48 49 private String adminCertIssuerDN = null; 50 private String adminCertSerialNumber = null; 51 private boolean approved = false; 52 private Date approvalDate = null; 53 private String comment = null; 54 private String approvalSignature = null; 55 private String username = null; 56 57 58 63 public Approval(String comment) { 64 super(); 65 this.approvalDate = new Date (); 66 this.comment = comment; 67 } 68 69 72 public Approval(){} 73 74 77 public String getAdminCertIssuerDN() { 78 return adminCertIssuerDN; 79 } 80 81 82 85 public BigInteger getAdminCertSerialNumber() { 86 return new BigInteger (adminCertSerialNumber,16); 87 } 88 89 90 93 public Date getApprovalDate() { 94 return approvalDate; 95 } 96 97 98 101 public boolean isApproved() { 102 return approved; 103 } 104 105 106 109 public String getComment() { 110 return comment; 111 } 112 113 116 public String getUsername() { 117 return username; 118 } 119 120 126 public void setApprovalCertificateAndUsername(boolean approved, X509Certificate approvalAdminCert, String username) { 127 this.approved = approved; 128 this.adminCertSerialNumber = approvalAdminCert.getSerialNumber().toString(16); 129 this.adminCertIssuerDN = CertTools.getIssuerDN(approvalAdminCert); 130 this.username = username; 131 } 132 133 136 public int compareTo(Object arg0) { 137 return approvalDate.compareTo(((Approval) arg0).approvalDate); 138 } 139 140 public void writeExternal(ObjectOutput out) throws IOException { 141 out.writeInt(LATEST_VERSION); 142 out.writeObject(this.adminCertIssuerDN); 143 out.writeObject(this.adminCertSerialNumber); 144 out.writeBoolean(this.approved); 145 out.writeObject(this.approvalDate); 146 out.writeObject(this.comment); 147 out.writeObject(this.approvalSignature); 148 out.writeObject(this.username); 149 } 150 151 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 152 153 int version = in.readInt(); 154 if(version == 1){ 155 this.adminCertIssuerDN = (String ) in.readObject(); 156 this.adminCertSerialNumber = (String ) in.readObject(); 157 this.approved = in.readBoolean(); 158 this.approvalDate = (Date ) in.readObject(); 159 this.comment = (String ) in.readObject(); 160 this.approvalSignature = (String ) in.readObject(); 161 this.username = (String ) in.readObject(); 162 } 163 164 } 165 166 167 168 169 } 170 | Popular Tags |