use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.
the class XMLSmtpAgentConfig method buildPrivateCertStore.
/*
* Build the certificates store that hold private certificates.
*/
protected void buildPrivateCertStore(Node publicCertNode) {
Provider<CertificateResolver> resolverProvider = null;
if (publicCertNode.getNodeType() == Node.ELEMENT_NODE) {
Element certNode = (Element) publicCertNode;
String storeType = certNode.getAttribute("type");
/*
* KeyStore based resolver
*/
if (storeType.equalsIgnoreCase("keystore")) {
resolverProvider = new KeyStoreCertificateStoreProvider(certNode.getAttribute("file"), certNode.getAttribute("filePass"), certNode.getAttribute("privKeyPass"));
} else if (storeType.equalsIgnoreCase("ldap")) {
resolverProvider = buildLdapCertificateStoreProvider(certNode, "LDAPPrivateCertStore");
} else {
throw new SmtpAgentException(SmtpAgentError.InvalidPrivateCertStoreSettings);
}
}
privateCertModule = new PrivateCertStoreModule(resolverProvider);
;
}
use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.
the class XMLSmtpAgentConfig method buildDomains.
/*
* Builds the list of domains managed by the agent.
*/
private void buildDomains(Node domainsNode) {
domains = new ArrayList<String>();
domainPostmasters = new HashMap<String, DomainPostmaster>();
// get all domains
Node domainNode = domainsNode.getFirstChild();
Node anchorStoreNode = null;
Map<String, Collection<String>> incomingAnchorHolder = new HashMap<String, Collection<String>>();
Map<String, Collection<String>> outgoingAnchorHolder = new HashMap<String, Collection<String>>();
do {
// get an individual domain
String domain = "";
String postmasterAddr = "";
if (domainNode.getNodeType() == Node.ELEMENT_NODE) {
if (domainNode.getNodeName().equalsIgnoreCase("domain")) {
Element domainEl = (Element) domainNode;
domain = domainEl.getAttribute("name");
if (domain == null || domain.trim().length() == 0)
throw new SmtpAgentException(SmtpAgentError.MissingDomainName);
postmasterAddr = domainEl.getAttribute("postmaster");
if (postmasterAddr == null || postmasterAddr.trim().length() == 0)
postmasterAddr = DomainPostmaster.getDefaultPostmaster(domain);
domains.add(domain);
try {
domainPostmasters.put(domain.toUpperCase(Locale.getDefault()), new DomainPostmaster(domain, new InternetAddress(postmasterAddr)));
} catch (AddressException e) {
}
// get the trust anchors configured for this domain
Node anchorsNode = domainNode.getFirstChild();
do {
if (anchorsNode.getNodeType() == Node.ELEMENT_NODE) {
/*
* Incoming trust anchors
*/
if (anchorsNode.getNodeName().equalsIgnoreCase("incomingtrustanchors"))
incomingAnchorHolder.put(domain, getConfiguredTrustAnchorNames(anchorsNode));
else /*
* Outgoing trust anchors
*/
if (anchorsNode.getNodeName().equalsIgnoreCase("outgoingtrustanchors"))
outgoingAnchorHolder.put(domain, getConfiguredTrustAnchorNames(anchorsNode));
}
anchorsNode = anchorsNode.getNextSibling();
} while (anchorsNode != null);
} else if (domainNode.getNodeName().equalsIgnoreCase("anchorstore")) {
// save off for later configuration
anchorStoreNode = domainNode;
}
}
domainNode = domainNode.getNextSibling();
} while (domainNode != null);
if (domains.size() == 0)
throw new SmtpAgentException(SmtpAgentError.MissingDomains);
buildTrustAnchorResolver((Element) anchorStoreNode, incomingAnchorHolder, outgoingAnchorHolder);
}
use of org.nhindirect.gateway.smtp.SmtpAgentException 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);
}
use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.
the class RecipAndSenderIsNotLocalTest method testEmptyDomainList.
public void testEmptyDomainList() throws Exception {
final MatcherConfig newConfig = mock(MatcherConfig.class);
when(newConfig.getCondition()).thenReturn("");
RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
boolean exceptionOccured = false;
try {
matcher.init(newConfig);
} catch (SmtpAgentException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.
the class RESTSmtpAgentConfig method buildPublicCertStore.
@Override
@SuppressWarnings("unchecked")
protected void buildPublicCertStore() {
Provider<CertificateResolver> resolverProvider = null;
Collection<Provider<CertificateResolver>> resolverProviders = new ArrayList<Provider<CertificateResolver>>();
Setting setting = null;
String storeTypes;
try {
setting = settingsService.getSetting("PublicStoreType");
} catch (Exception e) {
throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting public store type: " + e.getMessage(), e);
}
if (setting == null || setting.getValue() == null || setting.getValue().isEmpty())
// default to DNS
storeTypes = STORE_TYPE_DNS + "," + STORE_TYPE_PUBLIC_LDAP;
else
storeTypes = setting.getValue();
/*
* KeyStore based resolver
*/
String[] types = storeTypes.split(",");
for (String storeType : types) {
if (storeType.equalsIgnoreCase(STORE_TYPE_KEYSTORE)) {
Setting file;
Setting pass;
Setting privKeyPass;
try {
file = settingsService.getSetting("PublicStoreFile");
pass = settingsService.getSetting("PublicStoreFilePass");
privKeyPass = settingsService.getSetting("PublicStorePrivKeyPass");
} catch (Exception e) {
throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting public store file settings: " + e.getMessage(), e);
}
resolverProvider = new KeyStoreCertificateStoreProvider((file == null) ? "PublicStoreKeyFile" : file.getValue(), (pass == null) ? "DefaultFilePass" : pass.getValue(), (privKeyPass == null) ? "DefaultKeyPass" : privKeyPass.getValue());
} else /*
* DNS resolver
*/
if (storeType.equalsIgnoreCase(STORE_TYPE_DNS)) {
resolverProvider = new DNSCertStoreProvider(Collections.EMPTY_LIST, null, new DNSCertificateStore.DefaultDNSCachePolicy());
} else /*
* Web Services
*/
if (storeType.equalsIgnoreCase(STORE_TYPE_WS)) {
resolverProvider = new ConfigServiceRESTCertificateStoreProvider(certificateService, null, new ConfigServiceCertificateStore.DefaultConfigStoreCachePolicy(), this.storeProvider);
} else /*
* Public LDAP resolver
*/
if (storeType.equalsIgnoreCase(STORE_TYPE_PUBLIC_LDAP)) {
resolverProvider = new PublicLdapCertificateStoreProvider(null, new LDAPCertificateStore.DefaultLDAPCachePolicy());
} else /*
* Default to DNS with a default cache policy
*/
{
resolverProvider = new DNSCertStoreProvider(Collections.EMPTY_LIST, null, new DNSCertificateStore.DefaultDNSCachePolicy());
}
resolverProviders.add(resolverProvider);
}
publicCertModule = new PublicCertStoreModule(resolverProviders);
}
Aggregations