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.X509CertPairStoreSelector;
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: * cross certificates pairs from an LDAP directory.
19: *
20: * @see org.bouncycastle.x509.X509Store
21: */
22: public class X509StoreLDAPCertPairs extends X509StoreSpi {
23:
24: private LDAPStoreHelper helper;
25:
26: public X509StoreLDAPCertPairs() {
27: }
28:
29: /**
30: * Initializes this LDAP cross certificate pair 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 cross certificate pairs from the LDAP
49: * location.
50: * <p/>
51: * The selector must be a of type <code>X509CertPairStoreSelector</code>.
52: * If it is not an empty collection is returned.
53: * <p/>
54: * <p/>
55: * The subject should be a reasonable criteria for a selector.
56: *
57: * @param selector The selector to use for finding.
58: * @return A collection with the matches.
59: * @throws StoreException if an exception occurs while searching.
60: */
61: public Collection engineGetMatches(Selector selector)
62: throws StoreException {
63: if (!(selector instanceof X509CertPairStoreSelector)) {
64: return Collections.EMPTY_SET;
65: }
66: X509CertPairStoreSelector xselector = (X509CertPairStoreSelector) selector;
67: Set set = new HashSet();
68: set.addAll(helper.getCrossCertificatePairs(xselector));
69: return set;
70: }
71:
72: }
|