001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.core.service.wp;
028:
029: import java.io.Serializable;
030: import java.security.cert.Certificate;
031:
032: /**
033: * A Cert holds the certification for an {@link AddressEntry}.
034: * <p>
035: * There are currently four built-in certs:<ul>
036: * <li>{@link #NULL}</li>
037: * <li>{@link #PROXY}</li>
038: * <li>{@link Cert.Direct}</li>
039: * <li>{@link Cert.Indirect}</li>
040: * </ul>
041: * User-defined Cert subclasses are also permitted, which
042: * must be <u>immutable</u>.
043: */
044: public abstract class Cert implements Serializable {
045:
046: /**
047: * A "null" cert indicates that the client should contact the
048: * entry address with no security (ie "in the open").
049: */
050: public static final Cert NULL = new Cert() {
051: private Object readResolve() {
052: return NULL;
053: }
054:
055: public String toString() {
056: return "null_cert";
057: }
058: };
059:
060: /**
061: * A "proxy" cert indicates that the client should contact
062: * the agent with the name "CertProvider".
063: * <p>
064: * The cert provider agent will never specify a PROXY cert.
065: */
066: public static final Cert PROXY = new Cert() {
067: private Object readResolve() {
068: return PROXY;
069: }
070:
071: public String toString() {
072: return "proxy_cert";
073: }
074: };
075:
076: /**
077: * A "direct" cert contains a JAAS Crypto certificate.
078: */
079: public static final class Direct extends Cert {
080: private final Certificate cert;
081: private transient int _hc;
082:
083: public Direct(Certificate cert) {
084: this .cert = cert;
085: if (cert == null) {
086: throw new IllegalArgumentException("null cert");
087: }
088: }
089:
090: public Certificate getCertificate() {
091: return cert;
092: }
093:
094: public String toString() {
095: return "(cert=" + cert + ")";
096: }
097:
098: public boolean equals(Object o) {
099: return (o == this || (o instanceof Direct && cert
100: .equals(((Direct) o).cert)));
101: }
102:
103: public int hashCode() {
104: if (_hc == 0)
105: _hc = cert.hashCode();
106: return _hc;
107: }
108: }
109:
110: /**
111: * An "indirect" cert contains a query string which the client
112: * should use to lookup the certificate.
113: * <p>
114: * The lookup location is application specific, but typically
115: * refers to either a local file name, a distributed certificate
116: * authority, or a yellow pages.
117: */
118: public static final class Indirect extends Cert {
119: private final String query;
120:
121: public Indirect(String query) {
122: this .query = query;
123: if (query == null) {
124: throw new IllegalArgumentException("null query");
125: }
126: }
127:
128: public String getQuery() {
129: return query;
130: }
131:
132: public String toString() {
133: return "(query=" + query + ")";
134: }
135:
136: public boolean equals(Object o) {
137: return (o == this || (o instanceof Indirect && query
138: .equals(((Indirect) o).query)));
139: }
140:
141: public int hashCode() {
142: return query.hashCode();
143: }
144: }
145: }
|