Search in sources :

Example 1 with PublicCertStoreModule

use of org.nhindirect.stagent.module.PublicCertStoreModule 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);
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) Setting(org.nhindirect.config.model.Setting) PublicCertStoreModule(org.nhindirect.stagent.module.PublicCertStoreModule) ArrayList(java.util.ArrayList) ConfigServiceRESTCertificateStoreProvider(org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceRESTCertificateStoreProvider) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) ConfigServiceRESTCertificateStoreProvider(org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceRESTCertificateStoreProvider) KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) MultiDomainTrustAnchorResolverProvider(org.nhindirect.stagent.trust.provider.MultiDomainTrustAnchorResolverProvider) UniformTrustAnchorResolverProvider(org.nhindirect.stagent.trust.provider.UniformTrustAnchorResolverProvider) DNSCertStoreProvider(org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) DomainPolicyResolverProvider(org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider) LdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider) Provider(com.google.inject.Provider) DNSCertificateStore(org.nhindirect.stagent.cert.impl.DNSCertificateStore) LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) DNSCertStoreProvider(org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver)

Example 2 with PublicCertStoreModule

use of org.nhindirect.stagent.module.PublicCertStoreModule in project nhin-d by DirectProject.

the class WSSmtpAgentConfig method buildPublicCertStore.

/*
	 * Build the certificate resolver for public certificates
	 */
@SuppressWarnings("unchecked")
protected void buildPublicCertStore() {
    Provider<CertificateResolver> resolverProvider = null;
    Collection<Provider<CertificateResolver>> resolverProviders = new ArrayList<Provider<CertificateResolver>>();
    Setting setting = null;
    String storeTypes;
    try {
        setting = cfService.getSettingByName("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 = cfService.getSettingByName("PublicStoreFile");
                pass = cfService.getSettingByName("PublicStoreFilePass");
                privKeyPass = cfService.getSettingByName("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 ConfigServiceCertificateStoreProvider(cfService, 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);
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) ConfigServiceCertificateStoreProvider(org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceCertificateStoreProvider) KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) Setting(org.nhind.config.Setting) PublicCertStoreModule(org.nhindirect.stagent.module.PublicCertStoreModule) ArrayList(java.util.ArrayList) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) DefaultSmtpAgentProvider(org.nhindirect.gateway.smtp.provider.DefaultSmtpAgentProvider) KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) ConfigServiceCertificateStoreProvider(org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceCertificateStoreProvider) MultiDomainTrustAnchorResolverProvider(org.nhindirect.stagent.trust.provider.MultiDomainTrustAnchorResolverProvider) UniformTrustAnchorResolverProvider(org.nhindirect.stagent.trust.provider.UniformTrustAnchorResolverProvider) DNSCertStoreProvider(org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) DomainPolicyResolverProvider(org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider) LdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider) Provider(com.google.inject.Provider) DNSCertificateStore(org.nhindirect.stagent.cert.impl.DNSCertificateStore) LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) DNSCertStoreProvider(org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver)

Example 3 with PublicCertStoreModule

use of org.nhindirect.stagent.module.PublicCertStoreModule in project nhin-d by DirectProject.

the class XMLSmtpAgentConfig method buildAgentInjector.

/*
	 * Initializes all of the modules needed to build an agent using this configuration
	 * This is implemented using a simple DOM document loaded from a know XML schema
	 * Later versions may use POJOs build from XML (JAXB) or other configuration methods
	 */
private Injector buildAgentInjector() {
    // simple node iteration
    Node docNode = doc.getFirstChild().getFirstChild();
    do {
        /*
			 * Domain information
			 */
        if (docNode.getNodeName().equalsIgnoreCase("domains")) {
            buildDomains(docNode);
        } else /*
			 * public cert store
			 */
        if (docNode.getNodeName().equalsIgnoreCase("publiccertstore")) {
            buildPublicCertStore(docNode);
            publicCertModule = new PublicCertStoreModule(resolverProviders);
        } else /*
			 * public cert store
			 */
        if (docNode.getNodeName().equalsIgnoreCase("publiccertstores")) {
            buildPublicCertStores(docNode);
            publicCertModule = new PublicCertStoreModule(resolverProviders);
        } else /*
			 * private cert store
			 */
        if (docNode.getNodeName().equalsIgnoreCase("privatecertstore")) {
            buildPrivateCertStore(docNode);
        } else /*
			 * Raw messages
			 */
        if (docNode.getNodeName().equalsIgnoreCase("rawmessagesettings")) {
            buildRawMessageSettings(docNode);
        } else /*
			 * Incoming messages
			 */
        if (docNode.getNodeName().equalsIgnoreCase("incomingmessagessettings")) {
            buildIncomingMessageSettings(docNode);
        } else /*
			 * Outgoing messages
			 */
        if (docNode.getNodeName().equalsIgnoreCase("outgoingmessagessettings")) {
            buildOutgoingMessageSettings(docNode);
        } else /*
			 * Bad messages
			 */
        if (docNode.getNodeName().equalsIgnoreCase("badmessagessettings")) {
            buildBadMessageSettings(docNode);
        } else /*
			 * MDN settings
			 */
        if (docNode.getNodeName().equalsIgnoreCase("mdnsettings")) {
            buildMDNSettings(docNode);
        }
        docNode = docNode.getNextSibling();
    } while (docNode != null);
    if (domains == null)
        throw new SmtpAgentException(SmtpAgentError.MissingDomains);
    SmtpAgentSettings settings = new SmtpAgentSettings(domainPostmasters, rawSettings, outgoingSettings, incomingSettings, badSettings, notificationProducer);
    if (smtpAgentProvider == null)
        smtpAgentProvider = new DefaultSmtpAgentProvider(settings);
    AgentModule agentModule;
    if (agentProvider == null)
        agentModule = AgentModule.create(domains, publicCertModule, privateCertModule, certAnchorModule);
    else
        agentModule = AgentModule.create(agentProvider);
    return Guice.createInjector(agentModule, SmtpAgentModule.create(smtpAgentProvider));
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) SmtpAgentModule(org.nhindirect.gateway.smtp.module.SmtpAgentModule) AgentModule(org.nhindirect.stagent.module.AgentModule) Node(org.w3c.dom.Node) PublicCertStoreModule(org.nhindirect.stagent.module.PublicCertStoreModule) DefaultSmtpAgentProvider(org.nhindirect.gateway.smtp.provider.DefaultSmtpAgentProvider) SmtpAgentSettings(org.nhindirect.gateway.smtp.SmtpAgentSettings)

Aggregations

SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)3 PublicCertStoreModule (org.nhindirect.stagent.module.PublicCertStoreModule)3 Provider (com.google.inject.Provider)2 ArrayList (java.util.ArrayList)2 AddressException (javax.mail.internet.AddressException)2 DefaultSmtpAgentProvider (org.nhindirect.gateway.smtp.provider.DefaultSmtpAgentProvider)2 PolicyParseException (org.nhindirect.policy.PolicyParseException)2 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)2 DNSCertificateStore (org.nhindirect.stagent.cert.impl.DNSCertificateStore)2 LDAPCertificateStore (org.nhindirect.stagent.cert.impl.LDAPCertificateStore)2 DNSCertStoreProvider (org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider)2 KeyStoreCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider)2 LdapCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider)2 PublicLdapCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider)2 DomainPolicyResolverProvider (org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider)2 MultiDomainTrustAnchorResolverProvider (org.nhindirect.stagent.trust.provider.MultiDomainTrustAnchorResolverProvider)2 UniformTrustAnchorResolverProvider (org.nhindirect.stagent.trust.provider.UniformTrustAnchorResolverProvider)2 IOException (java.io.IOException)1 CertificateException (java.security.cert.CertificateException)1 Setting (org.nhind.config.Setting)1