Search in sources :

Example 1 with ConfigServiceRESTCertificateStoreProvider

use of org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceRESTCertificateStoreProvider in project nhin-d by DirectProject.

the class RESTSmtpAgentConfig method buildPrivateCertStore.

protected void buildPrivateCertStore() {
    Provider<CertificateResolver> resolverProvider = null;
    Setting setting = null;
    String storeType;
    try {
        setting = settingsService.getSetting("PrivateStoreType");
    } 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 WS
        storeType = STORE_TYPE_WS;
    else
        storeType = setting.getValue();
    /*
		 * KeyStore based resolver
		 */
    if (storeType.equalsIgnoreCase(STORE_TYPE_KEYSTORE)) {
        Setting file;
        Setting pass;
        Setting privKeyPass;
        try {
            file = settingsService.getSetting("PrivateStoreFile");
            pass = settingsService.getSetting("PrivateStoreFilePass");
            privKeyPass = settingsService.getSetting("PrivateStorePrivKeyPass");
        } catch (Exception e) {
            throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting private store file settings: " + e.getMessage(), e);
        }
        resolverProvider = new KeyStoreCertificateStoreProvider((file == null) ? null : file.getValue(), (pass == null) ? null : pass.getValue(), (privKeyPass == null) ? null : privKeyPass.getValue());
    } else if (storeType.equalsIgnoreCase(STORE_TYPE_LDAP)) {
        resolverProvider = buildLdapCertificateStoreProvider("PrivateStore", "LDAPPrivateCertStore");
    } else if (storeType.equalsIgnoreCase(STORE_TYPE_WS)) {
        resolverProvider = new ConfigServiceRESTCertificateStoreProvider(certificateService, null, new ConfigServiceCertificateStore.DefaultConfigStoreCachePolicy(), this.storeProvider);
    } else {
        throw new SmtpAgentException(SmtpAgentError.InvalidPrivateCertStoreSettings);
    }
    privateCertModule = new PrivateCertStoreModule(resolverProvider);
}
Also used : PrivateCertStoreModule(org.nhindirect.stagent.module.PrivateCertStoreModule) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) Setting(org.nhindirect.config.model.Setting) ConfigServiceRESTCertificateStoreProvider(org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceRESTCertificateStoreProvider) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 2 with ConfigServiceRESTCertificateStoreProvider

use of org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceRESTCertificateStoreProvider 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)

Aggregations

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