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.ca.certificateprofiles;
013:
014: import java.io.Serializable;
015:
016: import org.apache.commons.lang.StringUtils;
017: import org.bouncycastle.asn1.x509.PolicyQualifierId;
018:
019: /** Class encapsulating the CertificatePolicy X509 certificate extensions. See rfc3280.
020: * Contains an OID and optionally a policy qualifier. Several CertificatePolicy classes
021: * can be created with the same oid, for different qualifiers
022: *
023: * @author Nuno Ponte of MultiCert
024: * @version $Id: CertificatePolicy.java,v 1.3 2007/11/14 06:05:25 anatom Exp $
025: */
026: public class CertificatePolicy implements Serializable, Cloneable {
027:
028: /** Warning changing this value will cause upgrades to fail, because
029: * it has been serialized in the database (in XML).
030: * DONT CHANGE THIS!
031: */
032: private static final long serialVersionUID = -6384137742329979249L;
033:
034: // Policy qualifier Ids are taken from BC classes
035: public static final String id_qt_cps = PolicyQualifierId.id_qt_cps
036: .getId();
037: public static final String id_qt_unotice = PolicyQualifierId.id_qt_unotice
038: .getId();
039:
040: /**
041: * The special <code>anyPolicy</code> policy OID.
042: */
043: public static final String ANY_POLICY_OID = "2.5.29.32.0";
044:
045: private String policyID;
046: /** CPS uri */
047: private String qualifierId;
048: /** user notice text */
049: private String qualifier;
050:
051: public CertificatePolicy() {
052: super ();
053: }
054:
055: /**
056: *
057: * @param policyID
058: * @param notice user notice text
059: * @param uri cps uri
060: */
061: public CertificatePolicy(String policyID, String qualifierId,
062: String qualifier) {
063: this .policyID = policyID;
064: this .qualifierId = qualifierId;
065: this .qualifier = qualifier;
066: }
067:
068: /**
069: * @return the policyID
070: */
071: public String getPolicyID() {
072: return this .policyID;
073: }
074:
075: /**
076: * @param policyID the policyID to set
077: */
078: public void setPolicyID(String policyID) {
079: this .policyID = policyID;
080: }
081:
082: /**
083: * @return the qualifier string
084: */
085: public String getQualifier() {
086: return this .qualifier;
087: }
088:
089: /**
090: * @param uri the uri to set
091: */
092: public void setQualifier(String qualifier) {
093: this .qualifier = qualifier;
094: }
095:
096: /**
097: * @return the QualifierId
098: */
099: public String getQualifierId() {
100: return this .qualifierId;
101: }
102:
103: /**
104: * @param qualifierId the QualifierId to set
105: */
106: public void setQualifierId(String qualifierId) {
107: this .qualifierId = qualifierId;
108: }
109:
110: /**
111: * @see java.lang.Object#clone()
112: */
113: protected Object clone() {
114: return new CertificatePolicy(this .policyID, this .qualifierId,
115: this .qualifier);
116: }
117:
118: /**
119: * @see java.lang.Object#toString()
120: */
121: public String toString() {
122: StringBuffer strBuffer = new StringBuffer("CertificatePolicy(");
123:
124: strBuffer.append("policyID=");
125: strBuffer.append(this .policyID);
126: strBuffer.append(", qualifierId=");
127: strBuffer.append(this .qualifierId);
128: strBuffer.append(", qualifier=");
129: strBuffer.append(this .qualifier);
130: strBuffer.append(")");
131:
132: return strBuffer.toString();
133: }
134:
135: /**
136: * @see java.lang.Object#equals(java.lang.Object)
137: */
138: public boolean equals(Object obj) {
139: if ((obj == null) || !(obj instanceof CertificatePolicy)) {
140: return false;
141: }
142: CertificatePolicy policy = (CertificatePolicy) obj;
143:
144: // We want to let both null and "" be the same value here, i.e. an empty value
145: // Simply because, especially in gui code, it is somewhat tricky to trust which is a non-existant value
146: boolean policyeq = false;
147: if (StringUtils.isEmpty(policy.getPolicyID())
148: && StringUtils.isEmpty(this .policyID)) {
149: policyeq = true;
150: } else if (StringUtils.equals(policy.getPolicyID(),
151: this .policyID)) {
152: policyeq = true;
153: }
154: boolean qualifierideq = false;
155: if (StringUtils.isEmpty(policy.getQualifierId())
156: && StringUtils.isEmpty(this .qualifierId)) {
157: qualifierideq = true;
158: } else if (StringUtils.equals(policy.getQualifierId(),
159: this .qualifierId)) {
160: qualifierideq = true;
161: }
162: boolean qualifier = false;
163: if (StringUtils.isEmpty(policy.getQualifier())
164: && StringUtils.isEmpty(this .qualifier)) {
165: qualifier = true;
166: } else if (StringUtils.equals(policy.getQualifier(),
167: this .qualifier)) {
168: qualifier = true;
169: }
170: return policyeq && qualifierideq && qualifier;
171: }
172:
173: /**
174: * @see java.lang.Object#hashCode()
175: */
176: public int hashCode() {
177: return this.toString().hashCode();
178: }
179:
180: }
|