1 7 8 package java.security.cert; 9 10 import java.security.AccessController ; 11 import java.security.InvalidAlgorithmParameterException ; 12 import java.security.NoSuchAlgorithmException ; 13 import java.security.NoSuchProviderException ; 14 import java.security.PrivilegedAction ; 15 import java.security.Provider ; 16 import java.security.Security ; 17 import java.util.Collection ; 18 19 import sun.security.jca.*; 20 import sun.security.jca.GetInstance.Instance; 21 22 65 public class CertStore { 66 74 private static final String CERTSTORE_TYPE = "certstore.type"; 75 private CertStoreSpi storeSpi; 76 private Provider provider; 77 private String type; 78 private CertStoreParameters params; 79 80 89 protected CertStore(CertStoreSpi storeSpi, Provider provider, 90 String type, CertStoreParameters params) { 91 this.storeSpi = storeSpi; 92 this.provider = provider; 93 this.type = type; 94 if (params != null) 95 this.params = (CertStoreParameters ) params.clone(); 96 } 97 98 123 public final Collection <? extends Certificate > getCertificates 124 (CertSelector selector) throws CertStoreException { 125 return storeSpi.engineGetCertificates(selector); 126 } 127 128 153 public final Collection <? extends CRL > getCRLs(CRLSelector selector) 154 throws CertStoreException { 155 return storeSpi.engineGetCRLs(selector); 156 } 157 158 186 public static CertStore getInstance(String type, CertStoreParameters params) 187 throws InvalidAlgorithmParameterException , 188 NoSuchAlgorithmException { 189 try { 190 Instance instance = GetInstance.getInstance("CertStore", 191 CertStoreSpi .class, type, params); 192 return new CertStore ((CertStoreSpi )instance.impl, 193 instance.provider, type, params); 194 } catch (NoSuchAlgorithmException e) { 195 return handleException(e); 196 } 197 } 198 199 private static CertStore handleException(NoSuchAlgorithmException e) 200 throws NoSuchAlgorithmException , InvalidAlgorithmParameterException { 201 Throwable cause = e.getCause(); 202 if (cause instanceof InvalidAlgorithmParameterException ) { 203 throw (InvalidAlgorithmParameterException )cause; 204 } 205 throw e; 206 } 207 208 233 public static CertStore getInstance(String type, 234 CertStoreParameters params, String provider) 235 throws InvalidAlgorithmParameterException , 236 NoSuchAlgorithmException , NoSuchProviderException { 237 try { 238 Instance instance = GetInstance.getInstance("CertStore", 239 CertStoreSpi .class, type, params, provider); 240 return new CertStore ((CertStoreSpi )instance.impl, 241 instance.provider, type, params); 242 } catch (NoSuchAlgorithmException e) { 243 return handleException(e); 244 } 245 } 246 247 272 public static CertStore getInstance(String type, CertStoreParameters params, 273 Provider provider) throws NoSuchAlgorithmException , 274 InvalidAlgorithmParameterException { 275 try { 276 Instance instance = GetInstance.getInstance("CertStore", 277 CertStoreSpi .class, type, params, provider); 278 return new CertStore ((CertStoreSpi )instance.impl, 279 instance.provider, type, params); 280 } catch (NoSuchAlgorithmException e) { 281 return handleException(e); 282 } 283 } 284 285 293 public final CertStoreParameters getCertStoreParameters() { 294 return (params == null ? null : (CertStoreParameters ) params.clone()); 295 } 296 297 302 public final String getType() { 303 return this.type; 304 } 305 306 311 public final Provider getProvider() { 312 return this.provider; 313 } 314 315 335 public final static String getDefaultType() { 336 String cstype; 337 cstype = (String )AccessController.doPrivileged(new PrivilegedAction () { 338 public Object run() { 339 return Security.getProperty(CERTSTORE_TYPE); 340 } 341 }); 342 if (cstype == null) { 343 cstype = "LDAP"; 344 } 345 return cstype; 346 } 347 } 348 | Popular Tags |