本文整理汇总了Java中java.security.cert.PKIXParameters.setInitialPolicies方法的典型用法代码示例。如果您正苦于以下问题:Java PKIXParameters.setInitialPolicies方法的具体用法?Java PKIXParameters.setInitialPolicies怎么用?Java PKIXParameters.setInitialPolicies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.cert.PKIXParameters
的用法示例。
在下文中一共展示了PKIXParameters.setInitialPolicies方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetInitialPolicies04
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test #4 for <code>setInitialPolicies(Set)</code> method<br>
* Assertion: <code>Set</code> is copied to protect against
* subsequent modifications
*/
public final void testSetInitialPolicies04() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
Set s = new HashSet();
s.add("1.2.3.4.5.6.7");
s.add("1.2.3.4.5.6.8");
PKIXParameters p = new PKIXParameters(taSet);
p.setInitialPolicies(s);
// modify original set
s.clear();
// check that set maintained internally has
// not been changed by the above modification
assertEquals(2, p.getInitialPolicies().size());
}
示例2: testSetInitialPolicies05
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test #5 for <code>setInitialPolicies(Set)</code> method<br>
* Assertion: <code>ClassCastException</code> -
* if any of the elements in the set are not of type <code>String</code>
* @throws InvalidAlgorithmParameterException
*/
public final void testSetInitialPolicies05() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
Set s = new HashSet();
s.add("1.2.3.4.5.6.7");
s.add(new Object());
PKIXParameters p = new PKIXParameters(taSet);
try {
p.setInitialPolicies(s);
fail("ClassCastException expected");
} catch (ClassCastException e) {
}
}
示例3: testSetInitialPolicies01
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test #1 for <code>setInitialPolicies(Set)</code> method<br>
* Assertion: sets the <code>Set</code> of initial policy
* identifiers (OID strings)
* @throws InvalidAlgorithmParameterException
*/
public final void testSetInitialPolicies01() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
Set s = new HashSet();
s.add("1.2.3.4.5.6.7");
PKIXParameters p = new PKIXParameters(taSet);
p.setInitialPolicies(s);
assertEquals(1, p.getInitialPolicies().size());
}
示例4: testSetInitialPolicies02
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test #2 for <code>setInitialPolicies(Set)</code> method<br>
* Assertion: <code>Set</code> may be <code>null</code>
* @throws InvalidAlgorithmParameterException
*/
public final void testSetInitialPolicies02() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
PKIXParameters p = new PKIXParameters(taSet);
p.setInitialPolicies(null);
assertTrue(p.getInitialPolicies().isEmpty());
}
示例5: testSetInitialPolicies03
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test #3 for <code>setInitialPolicies(Set)</code> method<br>
* Assertion: <code>Set</code> may be empty
*/
public final void testSetInitialPolicies03() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
PKIXParameters p = new PKIXParameters(taSet);
p.setInitialPolicies(new HashSet());
assertTrue(p.getInitialPolicies().isEmpty());
}
示例6: testClone01
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test #1 for <code>clone()</code> method<br>
* Assertion: Makes a copy of this <code>PKIXParameters</code> object
* @throws KeyStoreException
* @throws InvalidAlgorithmParameterException
* @throws NoSuchAlgorithmException
*/
public final void testClone01() throws Exception {
KeyStore ks = TestUtils.getKeyStore(true, TestUtils.TRUSTED);
if (ks == null) {
fail(getName() + ": not performed (could not create test KeyStore)");
}
PKIXParameters p1 = new PKIXParameters(ks);
// set to some non-default values
p1.setPolicyQualifiersRejected(false);
p1.setAnyPolicyInhibited(true);
p1.setExplicitPolicyRequired(true);
p1.setPolicyMappingInhibited(true);
p1.setRevocationEnabled(false);
String sigProviderName = "Some Provider";
p1.setSigProvider(sigProviderName);
X509CertSelector x509cs = new X509CertSelector();
p1.setTargetCertConstraints(x509cs);
p1.setCertStores(TestUtils.getCollectionCertStoresList());
PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker();
List l = new ArrayList();
assertTrue("addedOk", l.add(cpc));
p1.setCertPathCheckers(l);
p1.setDate(new Date(555L));
Set s = new HashSet();
s.add("1.2.3.4.5.6.7");
s.add("1.2.3.4.5.6.8");
p1.setInitialPolicies(s);
// TrustAnchors already set
PKIXParameters p2 = (PKIXParameters)p1.clone();
// check that objects match
assertEquals("check1", p1.getPolicyQualifiersRejected(),
p2.getPolicyQualifiersRejected());
assertEquals("check2", p1.isAnyPolicyInhibited(),
p2.isAnyPolicyInhibited());
assertEquals("check3", p1.isExplicitPolicyRequired(),
p2.isExplicitPolicyRequired());
assertEquals("check4", p1.isPolicyMappingInhibited(),
p2.isPolicyMappingInhibited());
assertEquals("check5", p1.isRevocationEnabled(),
p2.isRevocationEnabled());
assertEquals("check6", p1.getSigProvider(), p2.getSigProvider());
// just check that not null
assertNotNull("check7", p2.getTargetCertConstraints());
assertEquals("check8", p1.getCertStores(), p2.getCertStores());
// just check that not empty
assertFalse("check9", p2.getCertPathCheckers().isEmpty());
assertEquals("check10", p1.getDate(), p2.getDate());
assertEquals("check11", p1.getInitialPolicies(),
p2.getInitialPolicies());
assertEquals("check12", p1.getTrustAnchors(), p2.getTrustAnchors());
}
示例7: doTest
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
private PKIXCertPathValidatorResult doTest(
String trustAnchor,
String[] certs,
String[] crls,
Set policies)
throws Exception
{
Set trustedSet = Collections.singleton(getTrustAnchor(trustAnchor));
List certsAndCrls = new ArrayList();
X509Certificate endCert = loadCert(certs[certs.length - 1]);
for (int i = 0; i != certs.length - 1; i++)
{
certsAndCrls.add(loadCert(certs[i]));
}
certsAndCrls.add(endCert);
CertPath certPath = CertificateFactory.getInstance("X.509","BC").generateCertPath(certsAndCrls);
for (int i = 0; i != crls.length; i++)
{
certsAndCrls.add(loadCrl(crls[i]));
}
CertStore store = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certsAndCrls), "BC");
CertPathValidator validator = CertPathValidator.getInstance("PKIX","BC");
PKIXParameters params = new PKIXParameters(trustedSet);
params.addCertStore(store);
params.setRevocationEnabled(true);
params.setDate(new GregorianCalendar(2010, 1, 1).getTime());
if (policies != null)
{
params.setExplicitPolicyRequired(true);
params.setInitialPolicies(policies);
}
return (PKIXCertPathValidatorResult)validator.validate(certPath, params);
}