001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.core.model.approval;
013:
014: import java.io.Externalizable;
015: import java.io.IOException;
016: import java.io.ObjectInput;
017: import java.io.ObjectOutput;
018: import java.math.BigInteger;
019: import java.security.cert.X509Certificate;
020: import java.util.Date;
021:
022: import org.ejbca.util.CertTools;
023:
024: /**
025: * Class representing one approval of a request data.
026: * Includes information like:
027: * Approval admin certificate
028: * isApproved (rejected otherwise)
029: * ApprovalDate
030: * Comment
031: *
032: *
033: * Approvals is sorted by dates.
034: *
035: * @author Philip Vendil
036: * @version $Id: Approval.java,v 1.2 2006/07/30 18:19:02 herrvendil Exp $
037: */
038:
039: public class Approval implements Comparable, Externalizable {
040:
041: private static final long serialVersionUID = -1L;
042:
043: private static final int LATEST_VERSION = 1;
044:
045: private String adminCertIssuerDN = null;
046: private String adminCertSerialNumber = null;
047: private boolean approved = false;
048: private Date approvalDate = null;
049: private String comment = null;
050: private String approvalSignature = null;
051: private String username = null;
052:
053: /**
054: * @param approved
055: * @param apDate
056: * @param comment
057: */
058: public Approval(String comment) {
059: super ();
060: this .approvalDate = new Date();
061: this .comment = comment;
062: }
063:
064: /**
065: * Constuctor used in externaliziation only
066: */
067: public Approval() {
068: }
069:
070: /**
071: * @return Returns the adminCertIssuerDN.
072: */
073: public String getAdminCertIssuerDN() {
074: return adminCertIssuerDN;
075: }
076:
077: /**
078: * @return Returns the adminCertSerialNumber.
079: */
080: public BigInteger getAdminCertSerialNumber() {
081: return new BigInteger(adminCertSerialNumber, 16);
082: }
083:
084: /**
085: * @return Returns the approvalDate.
086: */
087: public Date getApprovalDate() {
088: return approvalDate;
089: }
090:
091: /**
092: * @return Returns the approved.
093: */
094: public boolean isApproved() {
095: return approved;
096: }
097:
098: /**
099: * @return Returns the comment.
100: */
101: public String getComment() {
102: return comment;
103: }
104:
105: /**
106: * @return Returns the username of the approving administrator
107: */
108: public String getUsername() {
109: return username;
110: }
111:
112: /**
113: * The cert and username of the approving administrator. Should only be set
114: * by the ApprovalSessionBean
115: *
116: *
117: */
118: public void setApprovalCertificateAndUsername(boolean approved,
119: X509Certificate approvalAdminCert, String username) {
120: this .approved = approved;
121: this .adminCertSerialNumber = approvalAdminCert
122: .getSerialNumber().toString(16);
123: this .adminCertIssuerDN = CertTools
124: .getIssuerDN(approvalAdminCert);
125: this .username = username;
126: }
127:
128: /**
129: * Sort by approval date
130: */
131: public int compareTo(Object arg0) {
132: return approvalDate.compareTo(((Approval) arg0).approvalDate);
133: }
134:
135: public void writeExternal(ObjectOutput out) throws IOException {
136: out.writeInt(LATEST_VERSION);
137: out.writeObject(this .adminCertIssuerDN);
138: out.writeObject(this .adminCertSerialNumber);
139: out.writeBoolean(this .approved);
140: out.writeObject(this .approvalDate);
141: out.writeObject(this .comment);
142: out.writeObject(this .approvalSignature);
143: out.writeObject(this .username);
144: }
145:
146: public void readExternal(ObjectInput in) throws IOException,
147: ClassNotFoundException {
148:
149: int version = in.readInt();
150: if (version == 1) {
151: this .adminCertIssuerDN = (String) in.readObject();
152: this .adminCertSerialNumber = (String) in.readObject();
153: this .approved = in.readBoolean();
154: this .approvalDate = (Date) in.readObject();
155: this .comment = (String) in.readObject();
156: this .approvalSignature = (String) in.readObject();
157: this .username = (String) in.readObject();
158: }
159:
160: }
161:
162: }
|