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.X509AttributeCertStoreSelector;
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: * attribute certificates from an LDAP directory.
19: *
20: * @see org.bouncycastle.x509.X509Store
21: */
22: public class X509StoreLDAPAttrCerts extends X509StoreSpi {
23:
24: private LDAPStoreHelper helper;
25:
26: public X509StoreLDAPAttrCerts() {
27: }
28:
29: /**
30: * Initializes this LDAP attribute cert store implementation.
31: *
32: * @param parameters <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 parameters) {
37: if (!(parameters 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) parameters);
45: }
46:
47: /**
48: * Returns a collection of matching attribute certificates from the LDAP
49: * location.
50: * <p/>
51: * The selector must be a of type
52: * <code>X509AttributeCertStoreSelector</code>. If it is not an empty
53: * collection is returned.
54: * <p/>
55: * <p/>
56: * The subject and the serial number should be reasonable criterias for a
57: * selector.
58: *
59: * @param selector The selector to use for finding.
60: * @return A collection with the matches.
61: * @throws StoreException if an exception occurs while searching.
62: */
63: public Collection engineGetMatches(Selector selector)
64: throws StoreException {
65: if (!(selector instanceof X509AttributeCertStoreSelector)) {
66: return Collections.EMPTY_SET;
67: }
68: X509AttributeCertStoreSelector xselector = (X509AttributeCertStoreSelector) selector;
69: Set set = new HashSet();
70: set.addAll(helper.getAACertificates(xselector));
71: set.addAll(helper.getAttributeCertificateAttributes(xselector));
72: set
73: .addAll(helper
74: .getAttributeDescriptorCertificates(xselector));
75: return set;
76: }
77:
78: }
|