equal
deleted
inserted
replaced
118 throws InvalidAlgorithmParameterException |
118 throws InvalidAlgorithmParameterException |
119 { |
119 { |
120 setTrustAnchors(trustAnchors); |
120 setTrustAnchors(trustAnchors); |
121 |
121 |
122 this.unmodInitialPolicies = Collections.<String>emptySet(); |
122 this.unmodInitialPolicies = Collections.<String>emptySet(); |
123 this.certPathCheckers = new ArrayList<PKIXCertPathChecker>(); |
123 this.certPathCheckers = new ArrayList<>(); |
124 this.certStores = new ArrayList<CertStore>(); |
124 this.certStores = new ArrayList<>(); |
125 } |
125 } |
126 |
126 |
127 /** |
127 /** |
128 * Creates an instance of {@code PKIXParameters} that |
128 * Creates an instance of {@code PKIXParameters} that |
129 * populates the set of most-trusted CAs from the trusted |
129 * populates the set of most-trusted CAs from the trusted |
142 throws KeyStoreException, InvalidAlgorithmParameterException |
142 throws KeyStoreException, InvalidAlgorithmParameterException |
143 { |
143 { |
144 if (keystore == null) |
144 if (keystore == null) |
145 throw new NullPointerException("the keystore parameter must be " + |
145 throw new NullPointerException("the keystore parameter must be " + |
146 "non-null"); |
146 "non-null"); |
147 Set<TrustAnchor> hashSet = new HashSet<TrustAnchor>(); |
147 Set<TrustAnchor> hashSet = new HashSet<>(); |
148 Enumeration<String> aliases = keystore.aliases(); |
148 Enumeration<String> aliases = keystore.aliases(); |
149 while (aliases.hasMoreElements()) { |
149 while (aliases.hasMoreElements()) { |
150 String alias = aliases.nextElement(); |
150 String alias = aliases.nextElement(); |
151 if (keystore.isCertificateEntry(alias)) { |
151 if (keystore.isCertificateEntry(alias)) { |
152 Certificate cert = keystore.getCertificate(alias); |
152 Certificate cert = keystore.getCertificate(alias); |
154 hashSet.add(new TrustAnchor((X509Certificate)cert, null)); |
154 hashSet.add(new TrustAnchor((X509Certificate)cert, null)); |
155 } |
155 } |
156 } |
156 } |
157 setTrustAnchors(hashSet); |
157 setTrustAnchors(hashSet); |
158 this.unmodInitialPolicies = Collections.<String>emptySet(); |
158 this.unmodInitialPolicies = Collections.<String>emptySet(); |
159 this.certPathCheckers = new ArrayList<PKIXCertPathChecker>(); |
159 this.certPathCheckers = new ArrayList<>(); |
160 this.certStores = new ArrayList<CertStore>(); |
160 this.certStores = new ArrayList<>(); |
161 } |
161 } |
162 |
162 |
163 /** |
163 /** |
164 * Returns an immutable {@code Set} of the most-trusted |
164 * Returns an immutable {@code Set} of the most-trusted |
165 * CAs. |
165 * CAs. |
205 throw new ClassCastException("all elements of set must be " |
205 throw new ClassCastException("all elements of set must be " |
206 + "of type java.security.cert.TrustAnchor"); |
206 + "of type java.security.cert.TrustAnchor"); |
207 } |
207 } |
208 } |
208 } |
209 this.unmodTrustAnchors = Collections.unmodifiableSet |
209 this.unmodTrustAnchors = Collections.unmodifiableSet |
210 (new HashSet<TrustAnchor>(trustAnchors)); |
210 (new HashSet<>(trustAnchors)); |
211 } |
211 } |
212 |
212 |
213 /** |
213 /** |
214 * Returns an immutable {@code Set} of initial |
214 * Returns an immutable {@code Set} of initial |
215 * policy identifiers (OID strings), indicating that any one of these |
215 * policy identifiers (OID strings), indicating that any one of these |
254 if (!(i.next() instanceof String)) |
254 if (!(i.next() instanceof String)) |
255 throw new ClassCastException("all elements of set must be " |
255 throw new ClassCastException("all elements of set must be " |
256 + "of type java.lang.String"); |
256 + "of type java.lang.String"); |
257 } |
257 } |
258 this.unmodInitialPolicies = |
258 this.unmodInitialPolicies = |
259 Collections.unmodifiableSet(new HashSet<String>(initialPolicies)); |
259 Collections.unmodifiableSet(new HashSet<>(initialPolicies)); |
260 } else |
260 } else |
261 this.unmodInitialPolicies = Collections.<String>emptySet(); |
261 this.unmodInitialPolicies = Collections.<String>emptySet(); |
262 } |
262 } |
263 |
263 |
264 /** |
264 /** |
278 * |
278 * |
279 * @see #getCertStores |
279 * @see #getCertStores |
280 */ |
280 */ |
281 public void setCertStores(List<CertStore> stores) { |
281 public void setCertStores(List<CertStore> stores) { |
282 if (stores == null) { |
282 if (stores == null) { |
283 this.certStores = new ArrayList<CertStore>(); |
283 this.certStores = new ArrayList<>(); |
284 } else { |
284 } else { |
285 for (Iterator<CertStore> i = stores.iterator(); i.hasNext();) { |
285 for (Iterator<CertStore> i = stores.iterator(); i.hasNext();) { |
286 if (!(i.next() instanceof CertStore)) { |
286 if (!(i.next() instanceof CertStore)) { |
287 throw new ClassCastException("all elements of list must be " |
287 throw new ClassCastException("all elements of list must be " |
288 + "of type java.security.cert.CertStore"); |
288 + "of type java.security.cert.CertStore"); |
289 } |
289 } |
290 } |
290 } |
291 this.certStores = new ArrayList<CertStore>(stores); |
291 this.certStores = new ArrayList<>(stores); |
292 } |
292 } |
293 } |
293 } |
294 |
294 |
295 /** |
295 /** |
296 * Adds a {@code CertStore} to the end of the list of |
296 * Adds a {@code CertStore} to the end of the list of |
314 * |
314 * |
315 * @see #setCertStores |
315 * @see #setCertStores |
316 */ |
316 */ |
317 public List<CertStore> getCertStores() { |
317 public List<CertStore> getCertStores() { |
318 return Collections.unmodifiableList |
318 return Collections.unmodifiableList |
319 (new ArrayList<CertStore>(this.certStores)); |
319 (new ArrayList<>(this.certStores)); |
320 } |
320 } |
321 |
321 |
322 /** |
322 /** |
323 * Sets the RevocationEnabled flag. If this flag is true, the default |
323 * Sets the RevocationEnabled flag. If this flag is true, the default |
324 * revocation checking mechanism of the underlying PKIX service provider |
324 * revocation checking mechanism of the underlying PKIX service provider |
542 * are not of type {@code java.security.cert.PKIXCertPathChecker} |
542 * are not of type {@code java.security.cert.PKIXCertPathChecker} |
543 * @see #getCertPathCheckers |
543 * @see #getCertPathCheckers |
544 */ |
544 */ |
545 public void setCertPathCheckers(List<PKIXCertPathChecker> checkers) { |
545 public void setCertPathCheckers(List<PKIXCertPathChecker> checkers) { |
546 if (checkers != null) { |
546 if (checkers != null) { |
547 List<PKIXCertPathChecker> tmpList = |
547 List<PKIXCertPathChecker> tmpList = new ArrayList<>(); |
548 new ArrayList<PKIXCertPathChecker>(); |
|
549 for (PKIXCertPathChecker checker : checkers) { |
548 for (PKIXCertPathChecker checker : checkers) { |
550 tmpList.add((PKIXCertPathChecker)checker.clone()); |
549 tmpList.add((PKIXCertPathChecker)checker.clone()); |
551 } |
550 } |
552 this.certPathCheckers = tmpList; |
551 this.certPathCheckers = tmpList; |
553 } else { |
552 } else { |
554 this.certPathCheckers = new ArrayList<PKIXCertPathChecker>(); |
553 this.certPathCheckers = new ArrayList<>(); |
555 } |
554 } |
556 } |
555 } |
557 |
556 |
558 /** |
557 /** |
559 * Returns the {@code List} of certification path checkers. |
558 * Returns the {@code List} of certification path checkers. |
565 * {@code PKIXCertPathChecker}s (may be empty, but not |
564 * {@code PKIXCertPathChecker}s (may be empty, but not |
566 * {@code null}) |
565 * {@code null}) |
567 * @see #setCertPathCheckers |
566 * @see #setCertPathCheckers |
568 */ |
567 */ |
569 public List<PKIXCertPathChecker> getCertPathCheckers() { |
568 public List<PKIXCertPathChecker> getCertPathCheckers() { |
570 List<PKIXCertPathChecker> tmpList = new ArrayList<PKIXCertPathChecker>(); |
569 List<PKIXCertPathChecker> tmpList = new ArrayList<>(); |
571 for (PKIXCertPathChecker ck : certPathCheckers) { |
570 for (PKIXCertPathChecker ck : certPathCheckers) { |
572 tmpList.add((PKIXCertPathChecker)ck.clone()); |
571 tmpList.add((PKIXCertPathChecker)ck.clone()); |
573 } |
572 } |
574 return Collections.unmodifiableList(tmpList); |
573 return Collections.unmodifiableList(tmpList); |
575 } |
574 } |
665 try { |
664 try { |
666 PKIXParameters copy = (PKIXParameters)super.clone(); |
665 PKIXParameters copy = (PKIXParameters)super.clone(); |
667 |
666 |
668 // must clone these because addCertStore, et al. modify them |
667 // must clone these because addCertStore, et al. modify them |
669 if (certStores != null) { |
668 if (certStores != null) { |
670 copy.certStores = new ArrayList<CertStore>(certStores); |
669 copy.certStores = new ArrayList<>(certStores); |
671 } |
670 } |
672 if (certPathCheckers != null) { |
671 if (certPathCheckers != null) { |
673 copy.certPathCheckers = |
672 copy.certPathCheckers = |
674 new ArrayList<PKIXCertPathChecker>(certPathCheckers.size()); |
673 new ArrayList<>(certPathCheckers.size()); |
675 for (PKIXCertPathChecker checker : certPathCheckers) { |
674 for (PKIXCertPathChecker checker : certPathCheckers) { |
676 copy.certPathCheckers.add( |
675 copy.certPathCheckers.add( |
677 (PKIXCertPathChecker)checker.clone()); |
676 (PKIXCertPathChecker)checker.clone()); |
678 } |
677 } |
679 } |
678 } |