01: package org.bouncycastle.jce.provider;
02:
03: import org.bouncycastle.jce.X509LDAPCertStoreParameters;
04: import org.bouncycastle.util.Selector;
05: import org.bouncycastle.util.StoreException;
06: import org.bouncycastle.x509.X509CRLStoreSelector;
07: import org.bouncycastle.x509.X509StoreParameters;
08: import org.bouncycastle.x509.X509StoreSpi;
09: import org.bouncycastle.x509.util.LDAPStoreHelper;
10:
11: import java.util.Collection;
12: import java.util.Collections;
13: import java.util.HashSet;
14: import java.util.Set;
15:
16: /**
17: * A SPI implementation of Bouncy Castle <code>X509Store</code> for getting
18: * certificate revocation lists from an LDAP directory.
19: *
20: * @see org.bouncycastle.x509.X509Store
21: */
22: public class X509StoreLDAPCRLs extends X509StoreSpi {
23:
24: private LDAPStoreHelper helper;
25:
26: public X509StoreLDAPCRLs() {
27: }
28:
29: /**
30: * Initializes this LDAP CRL store implementation.
31: *
32: * @param params <code>X509LDAPCertStoreParameters</code>.
33: * @throws IllegalArgumentException if <code>params</code> is not an instance of
34: * <code>X509LDAPCertStoreParameters</code>.
35: */
36: public void engineInit(X509StoreParameters params) {
37: if (!(params instanceof X509LDAPCertStoreParameters)) {
38: throw new IllegalArgumentException(
39: "Initialization parameters must be an instance of "
40: + X509LDAPCertStoreParameters.class
41: .getName() + ".");
42: }
43: helper = new LDAPStoreHelper(
44: (X509LDAPCertStoreParameters) params);
45: }
46:
47: /**
48: * Returns a collection of matching CRLs from the LDAP location.
49: * <p/>
50: * The selector must be a of type <code>X509CRLStoreSelector</code>. If
51: * it is not an empty collection is returned.
52: * <p/>
53: * The issuer should be a reasonable criteria for a selector.
54: *
55: * @param selector The selector to use for finding.
56: * @return A collection with the matches.
57: * @throws StoreException if an exception occurs while searching.
58: */
59: public Collection engineGetMatches(Selector selector)
60: throws StoreException {
61: if (!(selector instanceof X509CRLStoreSelector)) {
62: return Collections.EMPTY_SET;
63: }
64: X509CRLStoreSelector xselector = (X509CRLStoreSelector) selector;
65: Set set = new HashSet();
66: // test only delta CRLs should be selected
67: if (xselector.isDeltaCRLIndicatorEnabled()) {
68: set.addAll(helper
69: .getDeltaCertificateRevocationLists(xselector));
70: }
71: // nothing specified
72: else {
73: set.addAll(helper
74: .getDeltaCertificateRevocationLists(xselector));
75: set.addAll(helper
76: .getAttributeAuthorityRevocationLists(xselector));
77: set.addAll(helper
78: .getAttributeCertificateRevocationLists(xselector));
79: set.addAll(helper.getAuthorityRevocationLists(xselector));
80: set.addAll(helper.getCertificateRevocationLists(xselector));
81: }
82: return set;
83: }
84: }
|