use of org.nhindirect.stagent.cert.impl.KeyStoreCertificateStore in project nhin-d by DirectProject.
the class XMLSmtpAgentConfig method buildTrustAnchorResolver.
/*
* Builds the resolver used to find trust anchors.
*/
protected void buildTrustAnchorResolver(Element anchorStoreNode, Map<String, Collection<String>> incomingAnchorHolder, Map<String, Collection<String>> outgoingAnchorHolder) {
Provider<TrustAnchorResolver> provider = null;
String storeType = anchorStoreNode.getAttribute("storeType");
Map<String, Collection<X509Certificate>> incomingAnchors = new HashMap<String, Collection<X509Certificate>>();
Map<String, Collection<X509Certificate>> outgoingAnchors = new HashMap<String, Collection<X509Certificate>>();
/*
* anchors are store in a key store
*/
if (storeType.equalsIgnoreCase("keystore")) {
KeyStoreCertificateStore store = new KeyStoreCertificateStore(anchorStoreNode.getAttribute("file"), anchorStoreNode.getAttribute("filePass"), anchorStoreNode.getAttribute("privKeyPass"));
// get incoming anchors
for (Entry<String, Collection<String>> entries : incomingAnchorHolder.entrySet()) {
Collection<X509Certificate> certs = new ArrayList<X509Certificate>();
for (String alias : entries.getValue()) {
X509Certificate cert = store.getByAlias(alias);
if (cert != null) {
certs.add(cert);
}
}
incomingAnchors.put(entries.getKey(), certs);
}
// get outgoing anchors
for (Entry<String, Collection<String>> entries : outgoingAnchorHolder.entrySet()) {
Collection<X509Certificate> certs = new ArrayList<X509Certificate>();
for (String alias : entries.getValue()) {
X509Certificate cert = store.getByAlias(alias);
if (cert != null) {
certs.add(cert);
}
}
outgoingAnchors.put(entries.getKey(), certs);
}
} else if (storeType.equalsIgnoreCase("ldap")) {
ldapCertificateStore = (LDAPCertificateStore) buildLdapCertificateStoreProvider(anchorStoreNode, "LDAPTrustAnchorStore").get();
// get incoming anchors
for (Entry<String, Collection<String>> entries : incomingAnchorHolder.entrySet()) {
Collection<X509Certificate> certs = new ArrayList<X509Certificate>();
for (String alias : entries.getValue()) {
//TODO what if 2nd entry has no certs? Fail?
//each alias could have multiple certificates
certs.addAll(ldapCertificateStore.getCertificates(alias));
}
incomingAnchors.put(entries.getKey(), certs);
}
// get outgoing anchors
for (Entry<String, Collection<String>> entries : outgoingAnchorHolder.entrySet()) {
Collection<X509Certificate> certs = new ArrayList<X509Certificate>();
for (String alias : entries.getValue()) {
certs.addAll(ldapCertificateStore.getCertificates(alias));
}
outgoingAnchors.put(entries.getKey(), certs);
}
}
// determine what module to load to inject the trust anchor resolver implementation
String type = anchorStoreNode.getAttribute("type");
/*
* Uniform trust anchor
*/
if (type.equalsIgnoreCase("uniform")) {
// this is uniform... doesn't really matter what we use for incoming or outgoing because in theory they should be
// the same... just get the first collection in the incoming map
provider = new UniformTrustAnchorResolverProvider(incomingAnchors.values().iterator().next());
} else if (type.equalsIgnoreCase("multidomain")) {
provider = new MultiDomainTrustAnchorResolverProvider(incomingAnchors, outgoingAnchors);
} else {
throw new SmtpAgentException(SmtpAgentError.InvalidTrustAnchorSettings);
}
certAnchorModule = TrustAnchorModule.create(provider);
}
Aggregations