use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.
the class PKIXCRLUtil method findCRLs.
/**
* Add to a HashSet any and all CRLs found in the X509Store's that are matching the crlSelect
* criteria.
*
* @param crls the {@link HashSet} to add the CRLs to.
* @param crlSelect a {@link PKIXCRLStoreSelector} object that will be used to select the CRLs
* @param crlStores a List containing only {@link Store} objects. These are used to search for
* CRLs
*/
private static void findCRLs(HashSet crls, PKIXCRLStoreSelector crlSelect, List crlStores) throws AnnotatedException {
AnnotatedException lastException = null;
boolean foundValidStore = false;
Iterator iter = crlStores.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof Store) {
Store store = (Store) obj;
try {
crls.addAll(store.getMatches(crlSelect));
foundValidStore = true;
} catch (StoreException e) {
lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
}
} else {
CertStore store = (CertStore) obj;
try {
crls.addAll(PKIXCRLStoreSelector.getCRLs(crlSelect, store));
foundValidStore = true;
} catch (CertStoreException e) {
lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
}
}
}
if (!foundValidStore && lastException != null) {
throw lastException;
}
}
use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.
the class CertPathValidatorUtilities method findCertificates.
protected static Collection findCertificates(X509AttributeCertStoreSelector certSelect, List certStores) throws AnnotatedException {
Set certs = new HashSet();
Iterator iter = certStores.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof X509Store) {
X509Store certStore = (X509Store) obj;
try {
certs.addAll(certStore.getMatches(certSelect));
} catch (StoreException e) {
throw new AnnotatedException("Problem while picking certificates from X.509 store.", e);
}
}
}
return certs;
}
use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.
the class CertPathValidatorUtilities method findCertificates.
protected static Collection findCertificates(PKIXCertStoreSelector certSelect, List certStores) throws AnnotatedException {
Set certs = new HashSet();
Iterator iter = certStores.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof Store) {
Store certStore = (Store) obj;
try {
certs.addAll(certStore.getMatches(certSelect));
} catch (StoreException e) {
throw new AnnotatedException("Problem while picking certificates from X.509 store.", e);
}
} else {
CertStore certStore = (CertStore) obj;
try {
certs.addAll(PKIXCertStoreSelector.getCertificates(certSelect, certStore));
} catch (CertStoreException e) {
throw new AnnotatedException("Problem while picking certificates from certificate store.", e);
}
}
}
return certs;
}
use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.
the class LDAPStoreHelper method search.
/**
* Returns a <code>List</code> of encodings of the certificates, attribute certificates, CRL or
* certificate pairs.
*
* @param attributeNames The attribute names to look for in the LDAP.
* @param attributeValue The value the attribute name must have.
* @param attrs The attributes in the LDAP which hold the certificate, attribute
* certificate, certificate pair or CRL in a found entry.
* @return A <code>List</code> of byte arrays with the encodings.
* @throws StoreException if an error occurs getting the results from the LDAP directory.
*/
private List search(String[] attributeNames, String attributeValue, String[] attrs) throws StoreException {
String filter = null;
if (attributeNames == null) {
filter = null;
} else {
filter = "";
if (attributeValue.equals("**")) {
attributeValue = "*";
}
for (int i = 0; i < attributeNames.length; i++) {
filter += "(" + attributeNames[i] + "=" + attributeValue + ")";
}
filter = "(|" + filter + ")";
}
String filter2 = "";
for (int i = 0; i < attrs.length; i++) {
filter2 += "(" + attrs[i] + "=*)";
}
filter2 = "(|" + filter2 + ")";
String filter3 = "(&" + filter + "" + filter2 + ")";
if (filter == null) {
filter3 = filter2;
}
List list;
list = getFromCache(filter3);
if (list != null) {
return list;
}
DirContext ctx = null;
list = new ArrayList();
try {
ctx = connectLDAP();
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
constraints.setCountLimit(0);
constraints.setReturningAttributes(attrs);
NamingEnumeration results = ctx.search(params.getBaseDN(), filter3, constraints);
while (results.hasMoreElements()) {
SearchResult sr = (SearchResult) results.next();
NamingEnumeration enumeration = ((Attribute) (sr.getAttributes().getAll().next())).getAll();
while (enumeration.hasMore()) {
list.add(enumeration.next());
}
}
addToCache(filter3, list);
} catch (NamingException e) {
// skip exception, unfortunately if an attribute type is not
// supported an exception is thrown
} finally {
try {
if (null != ctx) {
ctx.close();
}
} catch (Exception e) {
}
}
return list;
}
use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.
the class PKIXAttrCertPathBuilderSpi method findCertificates.
protected static Collection findCertificates(X509AttributeCertStoreSelector certSelect, List certStores) throws AnnotatedException {
Set certs = new HashSet();
Iterator iter = certStores.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof Store) {
Store certStore = (Store) obj;
try {
certs.addAll(certStore.getMatches(certSelect));
} catch (StoreException e) {
throw new AnnotatedException("Problem while picking certificates from X.509 store.", e);
}
}
}
return certs;
}
Aggregations