JavaTM 2 Platform
Standard Ed. 6

java.security.cert
类 CertStore

java.lang.Object
  继承者 java.security.cert.CertStore

public class CertStore
extends Object

用于从存储库中获取 CertificateCRL 的类。

此类使用基于提供者的架构。要创建一个 CertStore,可调用其中一个静态 getInstance 方法,并传入所需的 CertStore 类型、任何适用的初始化参数,以及所需提供者名称(可选)。

创建了 CertStore 以后,就可以通过调用其 getCertificatesgetCRLs 方法来获取 CertificateCRL

CertStore 与 KeyStore 不同,KeyStore 提供对私钥和可信任证书缓存的访问,而 CertStore 提供对不可信任证书和 CRL 存储库(可能很大)的访问。例如,CertStore 的 LDAP 实现使用 LDAP 协议和 RFC 服务属性中定义的方案,提供对存储在一个或多个目录中的证书和 CRL 的访问。有关标准 CertStore 类型的更多信息,请参见 Java Certification Path API Programmer's Guide 中的附录 A。

并发访问

所有 CertStore 对象的公共方法必须是线程安全的。也就是说,多个线程可以在单个 CertStore 对象(或多个对象)上并发调用这些方法,而不产生任何不良影响。例如,允许 CertPathBuilder 在搜索 CRL 的同时搜索其他证书。

还应确保此类的静态方法是线程安全的。多个线程可以并发调用此类中所定义的静态方法,而不产生任何不良影响。

从以下版本开始:
1.4

构造方法摘要
protected CertStore(CertStoreSpi storeSpi, Provider provider, String type, CertStoreParameters params)
          创建一个给定类型的 CertStore 对象,并在其中封装给定提供者实现(SPI 对象)。
 
方法摘要
 Collection<? extends Certificate> getCertificates(CertSelector selector)
          返回与指定选择器匹配的 CertificateCollection
 CertStoreParameters getCertStoreParameters()
          返回初始化此 CertStore 所用的参数。
 Collection<? extends CRL> getCRLs(CRLSelector selector)
          返回与指定选择器匹配的 CRLCollection
static String getDefaultType()
          返回 Java 安全属性文件中指定的默认 CertStore 类型;如果没有此属性,则返回字符串 "LDAP"。
static CertStore getInstance(String type, CertStoreParameters params)
          返回一个实现指定 CertStore 类型,并已使用指定参数初始化的 CertStore 对象。
static CertStore getInstance(String type, CertStoreParameters params, Provider provider)
          返回一个实现指定 CertStore 类型的 CertStore 对象。
static CertStore getInstance(String type, CertStoreParameters params, String provider)
          返回一个实现指定 CertStore 类型的 CertStore 对象。
 Provider getProvider()
          返回此 CertStore 的提供者。
 String getType()
          返回此 CertStore 的类型。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

CertStore

protected CertStore(CertStoreSpi storeSpi,
                    Provider provider,
                    String type,
                    CertStoreParameters params)
创建一个给定类型的 CertStore 对象,并在其中封装给定提供者实现(SPI 对象)。

参数:
storeSpi - 提供者实现
provider - 提供者
type - 类型
params - 初始化参数(可以为 null
方法详细信息

getCertificates

public final Collection<? extends Certificate> getCertificates(CertSelector selector)
                                                        throws CertStoreException
返回与指定选择器匹配的 CertificateCollection。如果没有与此选择器匹配的 Certificate,则返回一个空 Collection

对于某些 CertStore 类型,得到的 Collection 可能并不包含与选择器匹配的所有 Certificate。例如,LDAP CertStore 可能并不搜索目录中的所有条目。相反,它只搜索那些可能包含要查找的 Certificate 的条目。

如果没有提供一个包含用于查找证书的特定标准的非 null CertSelector,那么某些 CertStore 实现(特别是 LDAP CertStore)将抛出 CertStoreException。发布方和/或主体名称是特别有用的标准。

参数:
selector - 用于选择应该返回哪些 CertificateCertSelector。指定 null 表示返回所有 Certificate(如果支持)。
返回:
与指定选择器匹配的 CertificateCollection(不为 null
抛出:
CertStoreException - 如果发生异常

getCRLs

public final Collection<? extends CRL> getCRLs(CRLSelector selector)
                                        throws CertStoreException
返回与指定选择器匹配的 CRLCollection。如果没有与此选择器匹配的 CRL,则返回一个空 Collection

对于某些 CertStore 类型,得到的 Collection 可能并不包含与选择器匹配的所有 CRL。例如,LDAP CertStore 可能并不搜索目录中的所有条目。相反,它只搜索那些可能包含要查找的 CRL 的条目。

如果没有提供一个包含用于查找 CRL 的特定标准的非 null CRLSelector,那么某些 CertStore 实现(特别是 LDAP CertStore)将抛出 CertStoreException。发布方名称和/或要检查的证书特别有用。

参数:
selector - 用于选择应该返回哪些 CRLCRLSelector。指定 null 表示返回所有 CRL(如果支持)。
返回:
与指定选择器匹配的 CRLCollection(不为 null
抛出:
CertStoreException - 如果发生异常

getInstance

public static CertStore getInstance(String type,
                                    CertStoreParameters params)
                             throws InvalidAlgorithmParameterException,
                                    NoSuchAlgorithmException
返回一个实现指定 CertStore 类型,并已使用指定参数初始化的 CertStore 对象。

此方法从首选 Provider 开始遍历已注册安全提供者列表。返回一个封装 CertStoreSpi 实现的新 CertStore 对象,该实现取自第一个支持指定类型的 Provider。

注意,可以通过 Security.getProviders() 方法获取已注册提供者列表。

使用指定的 CertStoreParameters 初始化返回的 CertStore。不同类型的 CertStore 所需的参数类型有所不同。注意,指定的 CertStoreParameters 对象将被复制。

参数:
type - 请求的 CertStore 类型的名称。有关标准类型的信息,请参阅 Java Certification Path API Programmer's Guide 中的附录 A。
params - 初始化参数(可以为 null)。
返回:
实现指定 CertStore 类型的 CertStore 对象。
抛出:
NoSuchAlgorithmException - 如果没有 Provider 支持指定类型的 CertStoreSpi 实现。
InvalidAlgorithmParameterException - 如果指定的初始化参数不适合此 CertStore
另请参见:
Provider

getInstance

public static CertStore getInstance(String type,
                                    CertStoreParameters params,
                                    String provider)
                             throws InvalidAlgorithmParameterException,
                                    NoSuchAlgorithmException,
                                    NoSuchProviderException
返回一个实现指定 CertStore 类型的 CertStore 对象。

返回一个封装 CertStoreSpi 实现的新 CertStore 对象,该实现取自指定提供者。指定提供者必须在安全提供者列表中注册。

注意,可以通过 Security.getProviders() 方法获取已注册提供者列表。

使用指定的 CertStoreParameters 初始化返回的 CertStore。不同类型的 CertStore 所需的参数类型有所不同。注意,指定的 CertStoreParameters 对象将被复制。

参数:
type - 请求的 CertStore 类型。有关标准类型的信息,请参阅 Java Certification Path API Programmer's Guide 中的附录 A。
params - 初始化参数(可以为 null)。
provider - 提供者名称。
返回:
实现指定类型的 CertStore 对象。
抛出:
NoSuchAlgorithmException - 如果不能从指定的提供者获得指定类型的 CertStoreSpi 实现。
InvalidAlgorithmParameterException - 如果指定的初始化参数不适合此 CertStore
NoSuchProviderException - 如果指定的提供者未在安全提供者列表中注册。
IllegalArgumentException - 如果 provider 为 null 或空。
另请参见:
Provider

getInstance

public static CertStore getInstance(String type,
                                    CertStoreParameters params,
                                    Provider provider)
                             throws NoSuchAlgorithmException,
                                    InvalidAlgorithmParameterException
返回一个实现指定 CertStore 类型的 CertStore 对象。

返回一个封装 CertStoreSpi 实现的新 CertStore 对象,该实现取自指定 Provider 对象。注意,指定 Provider 对象无需在提供者列表中注册。

使用指定的 CertStoreParameters 初始化返回的 CertStore。不同类型的 CertStore 所需的参数类型有所不同。注意,指定的 CertStoreParameters 对象将被复制。

参数:
type - 请求的 CertStore 类型。有关标准类型的信息,请参阅 Java Certification Path API Programmer's Guide 中的附录 A。
params - 初始化参数(可以为 null)。
provider - 提供者。
返回:
实现指定类型的 CertStore 对象。
抛出:
NoSuchAlgorithmException - 如果不能从指定 Provider 对象获得指定类型的 CertStoreSpi 实现。
InvalidAlgorithmParameterException - 如果指定的初始化参数不适合此 CertStore
IllegalArgumentException - 如果 provider 为 null。
另请参见:
Provider

getCertStoreParameters

public final CertStoreParameters getCertStoreParameters()
返回初始化此 CertStore 所用的参数。注意,CertStoreParameters 对象返回之前将被复制。

返回:
初始化此 CertStore 所用的参数(可以为 null

getType

public final String getType()
返回此 CertStore 的类型。

返回:
CertStore 的类型

getProvider

public final Provider getProvider()
返回此 CertStore 的提供者。

返回:
CertStore 的提供者

getDefaultType

public static final String getDefaultType()
返回 Java 安全属性文件中指定的默认 CertStore 类型;如果没有此属性,则返回字符串 "LDAP"。Java 安全属性文件位于指定的 <JAVA_HOME>/lib/security/java.security 文件中。<JAVA_HOME> 引用 java.home 系统属性的值,并指定安装 JRE 的目录。

调用某个 getInstance 方法时不希望使用固定编码 (hard-coded) CertStore 类型的应用程序,以及用户未指定所用 CertStore 类型时希望提供默认 CertStore 类型的应用程序可以使用默认 CertStore 类型。

通过将 "certstore.type" 安全属性(在 Java 安全属性文件中)的值设置为所需的类型,可以更改默认的 CertStore 类型。

返回:
Java 安全属性文件中指定的默认 CertStore 类型;如果没有此属性,则返回字符串 "LDAP"。

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only