< prev index next >

src/java.base/share/classes/java/security/cert/CertPathValidator.java

Print this page
rev 15967 : [mq]: GetInstance


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.security.cert;
  27 
  28 import java.security.AccessController;
  29 import java.security.InvalidAlgorithmParameterException;
  30 import java.security.NoSuchAlgorithmException;
  31 import java.security.NoSuchProviderException;
  32 import java.security.PrivilegedAction;
  33 import java.security.Provider;
  34 import java.security.Security;
  35 import sun.security.util.Debug;
  36 
  37 import sun.security.jca.*;
  38 import sun.security.jca.GetInstance.Instance;
  39 
  40 /**
  41  * A class for validating certification paths (also known as certificate
  42  * chains).
  43  * <p>
  44  * This class uses a provider-based architecture.
  45  * To create a {@code CertPathValidator},
  46  * call one of the static {@code getInstance} methods, passing in the
  47  * algorithm name of the {@code CertPathValidator} desired and
  48  * optionally the name of the provider desired.
  49  *
  50  * <p>Once a {@code CertPathValidator} object has been created, it can
  51  * be used to validate certification paths by calling the {@link #validate
  52  * validate} method and passing it the {@code CertPath} to be validated
  53  * and an algorithm-specific set of parameters. If successful, the result is
  54  * returned in an object that implements the
  55  * {@code CertPathValidatorResult} interface.


 141      * Provider that supports the specified algorithm is returned.
 142      *
 143      * <p> Note that the list of registered providers may be retrieved via
 144      * the {@link Security#getProviders() Security.getProviders()} method.
 145      *
 146      * @implNote
 147      * The JDK Reference Implementation additionally uses the
 148      * {@code jdk.security.provider.preferred}
 149      * {@link Security#getProperty(String) Security} property to determine
 150      * the preferred provider order for the specified algorithm. This
 151      * may be different than the order of providers returned by
 152      * {@link Security#getProviders() Security.getProviders()}.
 153      *
 154      * @param algorithm the name of the requested {@code CertPathValidator}
 155      *  algorithm. See the CertPathValidator section in the <a href=
 156      *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
 157      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 158      * for information about standard algorithm names.
 159      *
 160      * @return a {@code CertPathValidator} object that implements the
 161      *          specified algorithm.
 162      *
 163      * @exception NoSuchAlgorithmException if no Provider supports a
 164      *          CertPathValidatorSpi implementation for the
 165      *          specified algorithm.


 166      *
 167      * @see java.security.Provider
 168      */
 169     public static CertPathValidator getInstance(String algorithm)
 170             throws NoSuchAlgorithmException {

 171         Instance instance = GetInstance.getInstance("CertPathValidator",
 172             CertPathValidatorSpi.class, algorithm);
 173         return new CertPathValidator((CertPathValidatorSpi)instance.impl,
 174             instance.provider, algorithm);
 175     }
 176 
 177     /**
 178      * Returns a {@code CertPathValidator} object that implements the
 179      * specified algorithm.
 180      *
 181      * <p> A new CertPathValidator object encapsulating the
 182      * CertPathValidatorSpi implementation from the specified provider
 183      * is returned.  The specified provider must be registered
 184      * in the security provider list.
 185      *
 186      * <p> Note that the list of registered providers may be retrieved via
 187      * the {@link Security#getProviders() Security.getProviders()} method.
 188      *
 189      * @param algorithm the name of the requested {@code CertPathValidator}
 190      *  algorithm. See the CertPathValidator section in the <a href=
 191      *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
 192      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 193      * for information about standard algorithm names.
 194      *
 195      * @param provider the name of the provider.
 196      *
 197      * @return a {@code CertPathValidator} object that implements the
 198      *          specified algorithm.
 199      *
 200      * @exception NoSuchAlgorithmException if a CertPathValidatorSpi



 201      *          implementation for the specified algorithm is not
 202      *          available from the specified provider.
 203      *
 204      * @exception NoSuchProviderException if the specified provider is not
 205      *          registered in the security provider list.
 206      *
 207      * @exception IllegalArgumentException if the {@code provider} is
 208      *          null or empty.
 209      *
 210      * @see java.security.Provider
 211      */
 212     public static CertPathValidator getInstance(String algorithm,
 213             String provider) throws NoSuchAlgorithmException,
 214             NoSuchProviderException {

 215         Instance instance = GetInstance.getInstance("CertPathValidator",
 216             CertPathValidatorSpi.class, algorithm, provider);
 217         return new CertPathValidator((CertPathValidatorSpi)instance.impl,
 218             instance.provider, algorithm);
 219     }
 220 
 221     /**
 222      * Returns a {@code CertPathValidator} object that implements the
 223      * specified algorithm.
 224      *
 225      * <p> A new CertPathValidator object encapsulating the
 226      * CertPathValidatorSpi implementation from the specified Provider
 227      * object is returned.  Note that the specified Provider object
 228      * does not have to be registered in the provider list.
 229      *
 230      * @param algorithm the name of the requested {@code CertPathValidator}
 231      * algorithm. See the CertPathValidator section in the <a href=
 232      * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
 233      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 234      * for information about standard algorithm names.
 235      *
 236      * @param provider the provider.
 237      *
 238      * @return a {@code CertPathValidator} object that implements the
 239      *          specified algorithm.



 240      *
 241      * @exception NoSuchAlgorithmException if a CertPathValidatorSpi
 242      *          implementation for the specified algorithm is not available
 243      *          from the specified Provider object.
 244      *
 245      * @exception IllegalArgumentException if the {@code provider} is
 246      *          null.
 247      *
 248      * @see java.security.Provider
 249      */
 250     public static CertPathValidator getInstance(String algorithm,
 251             Provider provider) throws NoSuchAlgorithmException {

 252         Instance instance = GetInstance.getInstance("CertPathValidator",
 253             CertPathValidatorSpi.class, algorithm, provider);
 254         return new CertPathValidator((CertPathValidatorSpi)instance.impl,
 255             instance.provider, algorithm);
 256     }
 257 
 258     /**
 259      * Returns the {@code Provider} of this
 260      * {@code CertPathValidator}.
 261      *
 262      * @return the {@code Provider} of this {@code CertPathValidator}
 263      */
 264     public final Provider getProvider() {
 265         return this.provider;
 266     }
 267 
 268     /**
 269      * Returns the algorithm name of this {@code CertPathValidator}.
 270      *
 271      * @return the algorithm name of this {@code CertPathValidator}




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.security.cert;
  27 
  28 import java.security.AccessController;
  29 import java.security.InvalidAlgorithmParameterException;
  30 import java.security.NoSuchAlgorithmException;
  31 import java.security.NoSuchProviderException;
  32 import java.security.PrivilegedAction;
  33 import java.security.Provider;
  34 import java.security.Security;
  35 import java.util.Objects;
  36 
  37 import sun.security.jca.*;
  38 import sun.security.jca.GetInstance.Instance;
  39 
  40 /**
  41  * A class for validating certification paths (also known as certificate
  42  * chains).
  43  * <p>
  44  * This class uses a provider-based architecture.
  45  * To create a {@code CertPathValidator},
  46  * call one of the static {@code getInstance} methods, passing in the
  47  * algorithm name of the {@code CertPathValidator} desired and
  48  * optionally the name of the provider desired.
  49  *
  50  * <p>Once a {@code CertPathValidator} object has been created, it can
  51  * be used to validate certification paths by calling the {@link #validate
  52  * validate} method and passing it the {@code CertPath} to be validated
  53  * and an algorithm-specific set of parameters. If successful, the result is
  54  * returned in an object that implements the
  55  * {@code CertPathValidatorResult} interface.


 141      * Provider that supports the specified algorithm is returned.
 142      *
 143      * <p> Note that the list of registered providers may be retrieved via
 144      * the {@link Security#getProviders() Security.getProviders()} method.
 145      *
 146      * @implNote
 147      * The JDK Reference Implementation additionally uses the
 148      * {@code jdk.security.provider.preferred}
 149      * {@link Security#getProperty(String) Security} property to determine
 150      * the preferred provider order for the specified algorithm. This
 151      * may be different than the order of providers returned by
 152      * {@link Security#getProviders() Security.getProviders()}.
 153      *
 154      * @param algorithm the name of the requested {@code CertPathValidator}
 155      *  algorithm. See the CertPathValidator section in the <a href=
 156      *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
 157      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 158      * for information about standard algorithm names.
 159      *
 160      * @return a {@code CertPathValidator} object that implements the
 161      *         specified algorithm
 162      *
 163      * @throws NoSuchAlgorithmException if no {@code Provider} supports a
 164      *         {@code CertPathValidatorSpi} implementation for the
 165      *         specified algorithm
 166      *
 167      * @throws NullPointerException if {@code algorithm} is {@code null}
 168      *
 169      * @see java.security.Provider
 170      */
 171     public static CertPathValidator getInstance(String algorithm)
 172             throws NoSuchAlgorithmException {
 173         Objects.requireNonNull(algorithm, "null algorithm name");
 174         Instance instance = GetInstance.getInstance("CertPathValidator",
 175             CertPathValidatorSpi.class, algorithm);
 176         return new CertPathValidator((CertPathValidatorSpi)instance.impl,
 177             instance.provider, algorithm);
 178     }
 179 
 180     /**
 181      * Returns a {@code CertPathValidator} object that implements the
 182      * specified algorithm.
 183      *
 184      * <p> A new CertPathValidator object encapsulating the
 185      * CertPathValidatorSpi implementation from the specified provider
 186      * is returned.  The specified provider must be registered
 187      * in the security provider list.
 188      *
 189      * <p> Note that the list of registered providers may be retrieved via
 190      * the {@link Security#getProviders() Security.getProviders()} method.
 191      *
 192      * @param algorithm the name of the requested {@code CertPathValidator}
 193      *  algorithm. See the CertPathValidator section in the <a href=
 194      *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
 195      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 196      * for information about standard algorithm names.
 197      *
 198      * @param provider the name of the provider.
 199      *
 200      * @return a {@code CertPathValidator} object that implements the
 201      *         specified algorithm
 202      *
 203      * @throws IllegalArgumentException if the {@code provider} is
 204      *         {@code null} or empty
 205      *
 206      * @throws NoSuchAlgorithmException if a {@code CertPathValidatorSpi}
 207      *         implementation for the specified algorithm is not
 208      *         available from the specified provider
 209      *
 210      * @throws NoSuchProviderException if the specified provider is not
 211      *         registered in the security provider list
 212      *
 213      * @throws NullPointerException if {@code algorithm} is {@code null}

 214      *
 215      * @see java.security.Provider
 216      */
 217     public static CertPathValidator getInstance(String algorithm,
 218             String provider) throws NoSuchAlgorithmException,
 219             NoSuchProviderException {
 220         Objects.requireNonNull(algorithm, "null algorithm name");
 221         Instance instance = GetInstance.getInstance("CertPathValidator",
 222             CertPathValidatorSpi.class, algorithm, provider);
 223         return new CertPathValidator((CertPathValidatorSpi)instance.impl,
 224             instance.provider, algorithm);
 225     }
 226 
 227     /**
 228      * Returns a {@code CertPathValidator} object that implements the
 229      * specified algorithm.
 230      *
 231      * <p> A new CertPathValidator object encapsulating the
 232      * CertPathValidatorSpi implementation from the specified Provider
 233      * object is returned.  Note that the specified Provider object
 234      * does not have to be registered in the provider list.
 235      *
 236      * @param algorithm the name of the requested {@code CertPathValidator}
 237      * algorithm. See the CertPathValidator section in the <a href=
 238      * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
 239      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 240      * for information about standard algorithm names.
 241      *
 242      * @param provider the provider.
 243      *
 244      * @return a {@code CertPathValidator} object that implements the
 245      *          specified algorithm
 246      *
 247      * @throws IllegalArgumentException if the {@code provider} is
 248      *         {@code null}
 249      *
 250      * @throws NoSuchAlgorithmException if a {@code CertPathValidatorSpi}
 251      *         implementation for the specified algorithm is not available
 252      *         from the specified Provider object
 253      *
 254      * @throws NullPointerException if {@code algorithm} is {@code null}

 255      *
 256      * @see java.security.Provider
 257      */
 258     public static CertPathValidator getInstance(String algorithm,
 259             Provider provider) throws NoSuchAlgorithmException {
 260         Objects.requireNonNull(algorithm, "null algorithm name");
 261         Instance instance = GetInstance.getInstance("CertPathValidator",
 262             CertPathValidatorSpi.class, algorithm, provider);
 263         return new CertPathValidator((CertPathValidatorSpi)instance.impl,
 264             instance.provider, algorithm);
 265     }
 266 
 267     /**
 268      * Returns the {@code Provider} of this
 269      * {@code CertPathValidator}.
 270      *
 271      * @return the {@code Provider} of this {@code CertPathValidator}
 272      */
 273     public final Provider getProvider() {
 274         return this.provider;
 275     }
 276 
 277     /**
 278      * Returns the algorithm name of this {@code CertPathValidator}.
 279      *
 280      * @return the algorithm name of this {@code CertPathValidator}


< prev index next >