< prev index next >

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

Print this page
rev 15967 : [mq]: GetInstance


  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.Collection;

  36 
  37 import sun.security.jca.*;
  38 import sun.security.jca.GetInstance.Instance;
  39 
  40 /**
  41  * A class for retrieving {@code Certificate}s and {@code CRL}s
  42  * from a repository.
  43  * <p>
  44  * This class uses a provider-based architecture.
  45  * To create a {@code CertStore}, call one of the static
  46  * {@code getInstance} methods, passing in the type of
  47  * {@code CertStore} desired, any applicable initialization parameters
  48  * and optionally the name of the provider desired.
  49  * <p>
  50  * Once the {@code CertStore} has been created, it can be used to
  51  * retrieve {@code Certificate}s and {@code CRL}s by calling its
  52  * {@link #getCertificates(CertSelector selector) getCertificates} and
  53  * {@link #getCRLs(CRLSelector selector) getCRLs} methods.
  54  * <p>
  55  * Unlike a {@link java.security.KeyStore KeyStore}, which provides access


 201      * Note that the specified {@code CertStoreParameters} object is
 202      * cloned.
 203      *
 204      * @implNote
 205      * The JDK Reference Implementation additionally uses the
 206      * {@code jdk.security.provider.preferred}
 207      * {@link Security#getProperty(String) Security} property to determine
 208      * the preferred provider order for the specified algorithm. This
 209      * may be different than the order of providers returned by
 210      * {@link Security#getProviders() Security.getProviders()}.
 211      *
 212      * @param type the name of the requested {@code CertStore} type.
 213      * See the CertStore section in the <a href=
 214      * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertStore">
 215      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 216      * for information about standard types.
 217      *
 218      * @param params the initialization parameters (may be {@code null}).
 219      *
 220      * @return a {@code CertStore} object that implements the specified
 221      *          {@code CertStore} type.
 222      *
 223      * @throws NoSuchAlgorithmException if no Provider supports a
 224      *          CertStoreSpi implementation for the specified type.
 225      *
 226      * @throws InvalidAlgorithmParameterException if the specified
 227      *          initialization parameters are inappropriate for this
 228      *          {@code CertStore}.





 229      *
 230      * @see java.security.Provider
 231      */
 232     public static CertStore getInstance(String type, CertStoreParameters params)
 233             throws InvalidAlgorithmParameterException,
 234             NoSuchAlgorithmException {

 235         try {
 236             Instance instance = GetInstance.getInstance("CertStore",
 237                 CertStoreSpi.class, type, params);
 238             return new CertStore((CertStoreSpi)instance.impl,
 239                 instance.provider, type, params);
 240         } catch (NoSuchAlgorithmException e) {
 241             return handleException(e);
 242         }
 243     }
 244 
 245     private static CertStore handleException(NoSuchAlgorithmException e)
 246             throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {

 247         Throwable cause = e.getCause();
 248         if (cause instanceof InvalidAlgorithmParameterException) {
 249             throw (InvalidAlgorithmParameterException)cause;
 250         }
 251         throw e;
 252     }
 253 
 254     /**
 255      * Returns a {@code CertStore} object that implements the specified
 256      * {@code CertStore} type.
 257      *
 258      * <p> A new CertStore object encapsulating the
 259      * CertStoreSpi implementation from the specified provider
 260      * is returned.  The specified provider must be registered
 261      * in the security provider list.
 262      *
 263      * <p> Note that the list of registered providers may be retrieved via
 264      * the {@link Security#getProviders() Security.getProviders()} method.
 265      *
 266      * <p>The {@code CertStore} that is returned is initialized with the
 267      * specified {@code CertStoreParameters}. The type of parameters
 268      * needed may vary between different types of {@code CertStore}s.
 269      * Note that the specified {@code CertStoreParameters} object is
 270      * cloned.
 271      *
 272      * @param type the requested {@code CertStore} type.
 273      * See the CertStore section in the <a href=
 274      * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertStore">
 275      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 276      * for information about standard types.
 277      *
 278      * @param params the initialization parameters (may be {@code null}).
 279      *
 280      * @param provider the name of the provider.
 281      *
 282      * @return a {@code CertStore} object that implements the
 283      *          specified type.
 284      *
 285      * @throws NoSuchAlgorithmException if a CertStoreSpi
 286      *          implementation for the specified type is not
 287      *          available from the specified provider.
 288      *
 289      * @throws InvalidAlgorithmParameterException if the specified
 290      *          initialization parameters are inappropriate for this
 291      *          {@code CertStore}.




 292      *
 293      * @throws NoSuchProviderException if the specified provider is not
 294      *          registered in the security provider list.
 295      *
 296      * @exception IllegalArgumentException if the {@code provider} is
 297      *          null or empty.
 298      *
 299      * @see java.security.Provider
 300      */
 301     public static CertStore getInstance(String type,
 302             CertStoreParameters params, String provider)
 303             throws InvalidAlgorithmParameterException,
 304             NoSuchAlgorithmException, NoSuchProviderException {

 305         try {
 306             Instance instance = GetInstance.getInstance("CertStore",
 307                 CertStoreSpi.class, type, params, provider);
 308             return new CertStore((CertStoreSpi)instance.impl,
 309                 instance.provider, type, params);
 310         } catch (NoSuchAlgorithmException e) {
 311             return handleException(e);
 312         }
 313     }
 314 
 315     /**
 316      * Returns a {@code CertStore} object that implements the specified
 317      * {@code CertStore} type.
 318      *
 319      * <p> A new CertStore object encapsulating the
 320      * CertStoreSpi implementation from the specified Provider
 321      * object is returned.  Note that the specified Provider object
 322      * does not have to be registered in the provider list.
 323      *
 324      * <p>The {@code CertStore} that is returned is initialized with the
 325      * specified {@code CertStoreParameters}. The type of parameters
 326      * needed may vary between different types of {@code CertStore}s.
 327      * Note that the specified {@code CertStoreParameters} object is
 328      * cloned.
 329      *
 330      * @param type the requested {@code CertStore} type.
 331      * See the CertStore section in the <a href=
 332      * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertStore">
 333      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 334      * for information about standard types.
 335      *
 336      * @param params the initialization parameters (may be {@code null}).
 337      *
 338      * @param provider the provider.
 339      *
 340      * @return a {@code CertStore} object that implements the
 341      *          specified type.
 342      *
 343      * @exception NoSuchAlgorithmException if a CertStoreSpi
 344      *          implementation for the specified type is not available
 345      *          from the specified Provider object.
 346      *
 347      * @throws InvalidAlgorithmParameterException if the specified
 348      *          initialization parameters are inappropriate for this
 349      *          {@code CertStore}
 350      *
 351      * @exception IllegalArgumentException if the {@code provider} is
 352      *          null.



 353      *
 354      * @see java.security.Provider
 355      */
 356     public static CertStore getInstance(String type, CertStoreParameters params,
 357             Provider provider) throws NoSuchAlgorithmException,
 358             InvalidAlgorithmParameterException {

 359         try {
 360             Instance instance = GetInstance.getInstance("CertStore",
 361                 CertStoreSpi.class, type, params, provider);
 362             return new CertStore((CertStoreSpi)instance.impl,
 363                 instance.provider, type, params);
 364         } catch (NoSuchAlgorithmException e) {
 365             return handleException(e);
 366         }
 367     }
 368 
 369     /**
 370      * Returns the parameters used to initialize this {@code CertStore}.
 371      * Note that the {@code CertStoreParameters} object is cloned before
 372      * it is returned.
 373      *
 374      * @return the parameters used to initialize this {@code CertStore}
 375      * (may be {@code null})
 376      */
 377     public final CertStoreParameters getCertStoreParameters() {
 378         return (params == null ? null : (CertStoreParameters) params.clone());




  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.Collection;
  36 import java.util.Objects;
  37 
  38 import sun.security.jca.*;
  39 import sun.security.jca.GetInstance.Instance;
  40 
  41 /**
  42  * A class for retrieving {@code Certificate}s and {@code CRL}s
  43  * from a repository.
  44  * <p>
  45  * This class uses a provider-based architecture.
  46  * To create a {@code CertStore}, call one of the static
  47  * {@code getInstance} methods, passing in the type of
  48  * {@code CertStore} desired, any applicable initialization parameters
  49  * and optionally the name of the provider desired.
  50  * <p>
  51  * Once the {@code CertStore} has been created, it can be used to
  52  * retrieve {@code Certificate}s and {@code CRL}s by calling its
  53  * {@link #getCertificates(CertSelector selector) getCertificates} and
  54  * {@link #getCRLs(CRLSelector selector) getCRLs} methods.
  55  * <p>
  56  * Unlike a {@link java.security.KeyStore KeyStore}, which provides access


 202      * Note that the specified {@code CertStoreParameters} object is
 203      * cloned.
 204      *
 205      * @implNote
 206      * The JDK Reference Implementation additionally uses the
 207      * {@code jdk.security.provider.preferred}
 208      * {@link Security#getProperty(String) Security} property to determine
 209      * the preferred provider order for the specified algorithm. This
 210      * may be different than the order of providers returned by
 211      * {@link Security#getProviders() Security.getProviders()}.
 212      *
 213      * @param type the name of the requested {@code CertStore} type.
 214      * See the CertStore section in the <a href=
 215      * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertStore">
 216      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 217      * for information about standard types.
 218      *
 219      * @param params the initialization parameters (may be {@code null}).
 220      *
 221      * @return a {@code CertStore} object that implements the specified
 222      *          {@code CertStore} type



 223      *
 224      * @throws InvalidAlgorithmParameterException if the specified
 225      *         initialization parameters are inappropriate for this
 226      *         {@code CertStore}
 227      *
 228      * @throws NoSuchAlgorithmException if no {@code Provider} supports a
 229      *         {@code CertStoreSpi} implementation for the specified type
 230      *
 231      * @throws NullPointerException if {@code type} is {@code null}
 232      *
 233      * @see java.security.Provider
 234      */
 235     public static CertStore getInstance(String type, CertStoreParameters params)
 236             throws InvalidAlgorithmParameterException,
 237             NoSuchAlgorithmException {
 238         Objects.requireNonNull(type, "null type name");
 239         try {
 240             Instance instance = GetInstance.getInstance("CertStore",
 241                 CertStoreSpi.class, type, params);
 242             return new CertStore((CertStoreSpi)instance.impl,
 243                 instance.provider, type, params);
 244         } catch (NoSuchAlgorithmException e) {
 245             return handleException(e);
 246         }
 247     }
 248 
 249     private static CertStore handleException(NoSuchAlgorithmException e)
 250             throws NoSuchAlgorithmException,
 251             InvalidAlgorithmParameterException {
 252         Throwable cause = e.getCause();
 253         if (cause instanceof InvalidAlgorithmParameterException) {
 254             throw (InvalidAlgorithmParameterException)cause;
 255         }
 256         throw e;
 257     }
 258 
 259     /**
 260      * Returns a {@code CertStore} object that implements the specified
 261      * {@code CertStore} type.
 262      *
 263      * <p> A new CertStore object encapsulating the
 264      * CertStoreSpi implementation from the specified provider
 265      * is returned.  The specified provider must be registered
 266      * in the security provider list.
 267      *
 268      * <p> Note that the list of registered providers may be retrieved via
 269      * the {@link Security#getProviders() Security.getProviders()} method.
 270      *
 271      * <p>The {@code CertStore} that is returned is initialized with the
 272      * specified {@code CertStoreParameters}. The type of parameters
 273      * needed may vary between different types of {@code CertStore}s.
 274      * Note that the specified {@code CertStoreParameters} object is
 275      * cloned.
 276      *
 277      * @param type the requested {@code CertStore} type.
 278      * See the CertStore section in the <a href=
 279      * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertStore">
 280      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 281      * for information about standard types.
 282      *
 283      * @param params the initialization parameters (may be {@code null}).
 284      *
 285      * @param provider the name of the provider.
 286      *
 287      * @return a {@code CertStore} object that implements the
 288      *          specified type
 289      *
 290      * @throws IllegalArgumentException if the {@code provider} is
 291      *         {@code null} or empty

 292      *
 293      * @throws InvalidAlgorithmParameterException if the specified
 294      *         initialization parameters are inappropriate for this
 295      *         {@code CertStore}
 296      *
 297      * @throws NoSuchAlgorithmException if a {@code CertStoreSpi}
 298      *         implementation for the specified type is not
 299      *         available from the specified provider
 300      *
 301      * @throws NoSuchProviderException if the specified provider is not
 302      *         registered in the security provider list
 303      *
 304      * @throws NullPointerException if {@code type} is {@code null}

 305      *
 306      * @see java.security.Provider
 307      */
 308     public static CertStore getInstance(String type,
 309             CertStoreParameters params, String provider)
 310             throws InvalidAlgorithmParameterException,
 311             NoSuchAlgorithmException, NoSuchProviderException {
 312         Objects.requireNonNull(type, "null type name");
 313         try {
 314             Instance instance = GetInstance.getInstance("CertStore",
 315                 CertStoreSpi.class, type, params, provider);
 316             return new CertStore((CertStoreSpi)instance.impl,
 317                 instance.provider, type, params);
 318         } catch (NoSuchAlgorithmException e) {
 319             return handleException(e);
 320         }
 321     }
 322 
 323     /**
 324      * Returns a {@code CertStore} object that implements the specified
 325      * {@code CertStore} type.
 326      *
 327      * <p> A new CertStore object encapsulating the
 328      * CertStoreSpi implementation from the specified Provider
 329      * object is returned.  Note that the specified Provider object
 330      * does not have to be registered in the provider list.
 331      *
 332      * <p>The {@code CertStore} that is returned is initialized with the
 333      * specified {@code CertStoreParameters}. The type of parameters
 334      * needed may vary between different types of {@code CertStore}s.
 335      * Note that the specified {@code CertStoreParameters} object is
 336      * cloned.
 337      *
 338      * @param type the requested {@code CertStore} type.
 339      * See the CertStore section in the <a href=
 340      * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertStore">
 341      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 342      * for information about standard types.
 343      *
 344      * @param params the initialization parameters (may be {@code null}).
 345      *
 346      * @param provider the provider.
 347      *
 348      * @return a {@code CertStore} object that implements the
 349      *          specified type
 350      *
 351      * @throws IllegalArgumentException if the {@code provider} is
 352      *         null

 353      *
 354      * @throws InvalidAlgorithmParameterException if the specified
 355      *         initialization parameters are inappropriate for this
 356      *         {@code CertStore}
 357      *
 358      * @throws NoSuchAlgorithmException if a {@code CertStoreSpi}
 359      *         implementation for the specified type is not available
 360      *         from the specified Provider object
 361      *
 362      * @throws NullPointerException if {@code type} is {@code null}
 363      *
 364      * @see java.security.Provider
 365      */
 366     public static CertStore getInstance(String type, CertStoreParameters params,
 367             Provider provider) throws NoSuchAlgorithmException,
 368             InvalidAlgorithmParameterException {
 369         Objects.requireNonNull(type, "null type name");
 370         try {
 371             Instance instance = GetInstance.getInstance("CertStore",
 372                 CertStoreSpi.class, type, params, provider);
 373             return new CertStore((CertStoreSpi)instance.impl,
 374                 instance.provider, type, params);
 375         } catch (NoSuchAlgorithmException e) {
 376             return handleException(e);
 377         }
 378     }
 379 
 380     /**
 381      * Returns the parameters used to initialize this {@code CertStore}.
 382      * Note that the {@code CertStoreParameters} object is cloned before
 383      * it is returned.
 384      *
 385      * @return the parameters used to initialize this {@code CertStore}
 386      * (may be {@code null})
 387      */
 388     public final CertStoreParameters getCertStoreParameters() {
 389         return (params == null ? null : (CertStoreParameters) params.clone());


< prev index next >