001 /*
002 * Copyright 2000-2001 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.security.cert;
027
028 import java.security.PublicKey;
029
030 /**
031 * This class represents the successful result of the PKIX certification
032 * path validation algorithm.
033 *
034 * <p>Instances of <code>PKIXCertPathValidatorResult</code> are returned by the
035 * {@link CertPathValidator#validate validate} method of
036 * <code>CertPathValidator</code> objects implementing the PKIX algorithm.
037 *
038 * <p> All <code>PKIXCertPathValidatorResult</code> objects contain the
039 * valid policy tree and subject public key resulting from the
040 * validation algorithm, as well as a <code>TrustAnchor</code> describing
041 * the certification authority (CA) that served as a trust anchor for the
042 * certification path.
043 * <p>
044 * <b>Concurrent Access</b>
045 * <p>
046 * Unless otherwise specified, the methods defined in this class are not
047 * thread-safe. Multiple threads that need to access a single
048 * object concurrently should synchronize amongst themselves and
049 * provide the necessary locking. Multiple threads each manipulating
050 * separate objects need not synchronize.
051 *
052 * @see CertPathValidatorResult
053 *
054 * @version 1.16 05/05/07
055 * @since 1.4
056 * @author Yassir Elley
057 * @author Sean Mullan
058 */
059 public class PKIXCertPathValidatorResult implements
060 CertPathValidatorResult {
061
062 private TrustAnchor trustAnchor;
063 private PolicyNode policyTree;
064 private PublicKey subjectPublicKey;
065
066 /**
067 * Creates an instance of <code>PKIXCertPathValidatorResult</code>
068 * containing the specified parameters.
069 *
070 * @param trustAnchor a <code>TrustAnchor</code> describing the CA that
071 * served as a trust anchor for the certification path
072 * @param policyTree the immutable valid policy tree, or <code>null</code>
073 * if there are no valid policies
074 * @param subjectPublicKey the public key of the subject
075 * @throws NullPointerException if the <code>subjectPublicKey</code> or
076 * <code>trustAnchor</code> parameters are <code>null</code>
077 */
078 public PKIXCertPathValidatorResult(TrustAnchor trustAnchor,
079 PolicyNode policyTree, PublicKey subjectPublicKey) {
080 if (subjectPublicKey == null)
081 throw new NullPointerException(
082 "subjectPublicKey must be non-null");
083 if (trustAnchor == null)
084 throw new NullPointerException(
085 "trustAnchor must be non-null");
086 this .trustAnchor = trustAnchor;
087 this .policyTree = policyTree;
088 this .subjectPublicKey = subjectPublicKey;
089 }
090
091 /**
092 * Returns the <code>TrustAnchor</code> describing the CA that served
093 * as a trust anchor for the certification path.
094 *
095 * @return the <code>TrustAnchor</code> (never <code>null</code>)
096 */
097 public TrustAnchor getTrustAnchor() {
098 return trustAnchor;
099 }
100
101 /**
102 * Returns the root node of the valid policy tree resulting from the
103 * PKIX certification path validation algorithm. The
104 * <code>PolicyNode</code> object that is returned and any objects that
105 * it returns through public methods are immutable.
106 *
107 * <p>Most applications will not need to examine the valid policy tree.
108 * They can achieve their policy processing goals by setting the
109 * policy-related parameters in <code>PKIXParameters</code>. However, more
110 * sophisticated applications, especially those that process policy
111 * qualifiers, may need to traverse the valid policy tree using the
112 * {@link PolicyNode#getParent PolicyNode.getParent} and
113 * {@link PolicyNode#getChildren PolicyNode.getChildren} methods.
114 *
115 * @return the root node of the valid policy tree, or <code>null</code>
116 * if there are no valid policies
117 */
118 public PolicyNode getPolicyTree() {
119 return policyTree;
120 }
121
122 /**
123 * Returns the public key of the subject (target) of the certification
124 * path, including any inherited public key parameters if applicable.
125 *
126 * @return the public key of the subject (never <code>null</code>)
127 */
128 public PublicKey getPublicKey() {
129 return subjectPublicKey;
130 }
131
132 /**
133 * Returns a copy of this object.
134 *
135 * @return the copy
136 */
137 public Object clone() {
138 try {
139 return super .clone();
140 } catch (CloneNotSupportedException e) {
141 /* Cannot happen */
142 throw new InternalError(e.toString());
143 }
144 }
145
146 /**
147 * Return a printable representation of this
148 * <code>PKIXCertPathValidatorResult</code>.
149 *
150 * @return a <code>String</code> describing the contents of this
151 * <code>PKIXCertPathValidatorResult</code>
152 */
153 public String toString() {
154 StringBuffer sb = new StringBuffer();
155 sb.append("PKIXCertPathValidatorResult: [\n");
156 sb.append(" Trust Anchor: " + trustAnchor.toString() + "\n");
157 sb
158 .append(" Policy Tree: " + String.valueOf(policyTree)
159 + "\n");
160 sb.append(" Subject Public Key: " + subjectPublicKey + "\n");
161 sb.append("]");
162 return sb.toString();
163 }
164 }
|