Search in sources :

Example 1 with EmployLdapAuthInformation

use of org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation in project nhin-d by DirectProject.

the class WSSmtpAgentConfig method buildLdapCertificateStoreProvider.

protected LdapCertificateStoreProvider buildLdapCertificateStoreProvider(String type, String cacheStoreName) {
    //required
    Setting ldapURLSetting;
    Setting ldapSearchBaseSetting;
    Setting ldapSearchAttrSetting;
    Setting ldapCertAttrSetting;
    Setting ldapCertFormatSetting;
    //optional	    
    Setting ldapUserSetting;
    Setting ldapPasswordSetting;
    Setting ldapConnTimeoutSetting;
    Setting ldapCertPassphraseSetting;
    try {
        ldapURLSetting = cfService.getSettingByName(type + "LDAPUrl");
        ldapSearchBaseSetting = cfService.getSettingByName(type + "LDAPSearchBase");
        ldapSearchAttrSetting = cfService.getSettingByName(type + "LDAPSearchAttr");
        ldapCertAttrSetting = cfService.getSettingByName(type + "LDAPCertAttr");
        ldapCertFormatSetting = cfService.getSettingByName(type + "LDAPCertFormat");
        //optional	    
        ldapUserSetting = cfService.getSettingByName(type + "LDAPUser");
        ldapPasswordSetting = cfService.getSettingByName(type + "LDAPPassword");
        ldapConnTimeoutSetting = cfService.getSettingByName(type + "LDAPConnTimeout");
        ldapCertPassphraseSetting = cfService.getSettingByName(type + "LDAPCertPassphrase");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting LDAP store settings: " + e.getMessage(), e);
    }
    if (ldapURLSetting == null || ldapURLSetting.getValue() == null || ldapURLSetting.getValue().isEmpty())
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "Missing LDAP URL");
    String ldapSearchBase = (ldapSearchBaseSetting == null) ? null : ldapSearchBaseSetting.getValue();
    String ldapSearchAttr = (ldapSearchAttrSetting == null) ? null : ldapSearchAttrSetting.getValue();
    String ldapCertAttr = (ldapCertAttrSetting == null) ? null : ldapCertAttrSetting.getValue();
    String ldapCertFormat = (ldapCertFormatSetting == null) ? null : ldapCertFormatSetting.getValue();
    String[] ldapURL = ldapURLSetting.getValue().split(",");
    if (ldapURL[0].isEmpty() || ldapSearchBase.isEmpty() || ldapSearchAttr.isEmpty() || ldapCertAttr.isEmpty() || ldapCertFormat.isEmpty()) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "Missing required LDAP parameters.");
    }
    String ldapUser = (ldapUserSetting == null) ? null : ldapUserSetting.getValue();
    String ldapPassword = (ldapPasswordSetting == null) ? null : ldapPasswordSetting.getValue();
    String ldapConnTimeout = (ldapConnTimeoutSetting == null) ? null : ldapConnTimeoutSetting.getValue();
    String ldapCertPassphrase = (ldapCertPassphraseSetting == null) ? null : ldapCertPassphraseSetting.getValue();
    if (ldapCertFormat.equalsIgnoreCase("pkcs12") && (ldapCertPassphrase == null || ldapCertPassphrase.isEmpty())) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat);
    }
    LdapStoreConfiguration ldapStoreConfiguration = new LdapStoreConfiguration(ldapURL, ldapSearchBase, ldapSearchAttr, ldapCertAttr, ldapCertFormat);
    if (ldapUser != null && !ldapUser.isEmpty() && ldapPassword != null && !ldapPassword.isEmpty()) {
        ldapStoreConfiguration.setEmployLdapAuthInformation(new EmployLdapAuthInformation(ldapUser, ldapPassword));
    }
    if (ldapConnTimeout != null && !ldapConnTimeout.isEmpty()) {
        ldapStoreConfiguration.setLdapConnectionTimeOut(ldapConnTimeout);
    }
    if (ldapCertPassphrase != null && !ldapCertPassphrase.isEmpty()) {
        ldapStoreConfiguration.setLdapCertPassphrase(ldapCertPassphrase);
    }
    LdapCertificateStoreProvider ldapCertificateStoreProvider = new LdapCertificateStoreProvider(ldapStoreConfiguration, null, new LDAPCertificateStore.DefaultLDAPCachePolicy());
    return ldapCertificateStoreProvider;
}
Also used : LdapStoreConfiguration(org.nhindirect.stagent.cert.impl.LdapStoreConfiguration) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) EmployLdapAuthInformation(org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation) Setting(org.nhind.config.Setting) LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) LdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider) 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)

Example 2 with EmployLdapAuthInformation

use of org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation in project nhin-d by DirectProject.

the class XMLSmtpAgentConfig method buildLdapCertificateStoreProvider.

/**
	 * This will build an LdapCertificateStoreProvider to be used to grab certificates from the LDAP store.
	 * @param anchorStoreNode - The Element node in the xml file that contains anchor information
	 * @param cacheStoreName - The name of the bootstrap cacheStore used when cache and LDAP are unreachable.
	 * @return
	 */
protected LdapCertificateStoreProvider buildLdapCertificateStoreProvider(Element anchorStoreNode, String cacheStoreName) {
    //required
    String[] ldapURL = anchorStoreNode.getAttribute("ldapURL").split(",");
    String ldapSearchBase = anchorStoreNode.getAttribute("ldapSearchBase");
    String ldapSearchAttr = anchorStoreNode.getAttribute("ldapSearchAttr");
    String ldapCertAttr = anchorStoreNode.getAttribute("ldapCertAttr");
    String ldapCertFormat = anchorStoreNode.getAttribute("ldapCertFormat");
    if (ldapURL[0].isEmpty() || ldapSearchBase.isEmpty() || ldapSearchAttr.isEmpty() || ldapCertAttr.isEmpty() || ldapCertFormat.isEmpty()) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat);
    }
    //optional	    
    String ldapUser = anchorStoreNode.getAttribute("ldapUser");
    String ldapPassword = anchorStoreNode.getAttribute("ldapPassword");
    String ldapConnTimeout = anchorStoreNode.getAttribute("ldapConnTimeout");
    String ldapCertPassphrase = anchorStoreNode.getAttribute("ldapCertPassphrase");
    if (ldapCertFormat.equalsIgnoreCase("pkcs12") && ldapCertPassphrase.isEmpty()) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat);
    }
    LdapStoreConfiguration ldapStoreConfiguration = new LdapStoreConfiguration(ldapURL, ldapSearchBase, ldapSearchAttr, ldapCertAttr, ldapCertFormat);
    if (!(ldapUser.isEmpty() && ldapPassword.isEmpty())) {
        ldapStoreConfiguration.setEmployLdapAuthInformation(new EmployLdapAuthInformation(ldapUser, ldapPassword));
    }
    if (!ldapConnTimeout.isEmpty()) {
        ldapStoreConfiguration.setLdapConnectionTimeOut(ldapConnTimeout);
    }
    if (!ldapCertPassphrase.isEmpty()) {
        ldapStoreConfiguration.setLdapCertPassphrase(ldapCertPassphrase);
    }
    LdapCertificateStoreProvider ldapCertificateStoreProvider = new LdapCertificateStoreProvider(ldapStoreConfiguration, null, new DefaultCertStoreCachePolicy());
    return ldapCertificateStoreProvider;
}
Also used : LdapStoreConfiguration(org.nhindirect.stagent.cert.impl.LdapStoreConfiguration) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) DefaultCertStoreCachePolicy(org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy) EmployLdapAuthInformation(org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation) LdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider)

Example 3 with EmployLdapAuthInformation

use of org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation in project nhin-d by DirectProject.

the class RESTSmtpAgentConfig method buildLdapCertificateStoreProvider.

@Override
protected LdapCertificateStoreProvider buildLdapCertificateStoreProvider(String type, String cacheStoreName) {
    //required
    Setting ldapURLSetting;
    Setting ldapSearchBaseSetting;
    Setting ldapSearchAttrSetting;
    Setting ldapCertAttrSetting;
    Setting ldapCertFormatSetting;
    //optional	    
    Setting ldapUserSetting;
    Setting ldapPasswordSetting;
    Setting ldapConnTimeoutSetting;
    Setting ldapCertPassphraseSetting;
    try {
        ldapURLSetting = settingsService.getSetting(type + "LDAPUrl");
        ldapSearchBaseSetting = settingsService.getSetting(type + "LDAPSearchBase");
        ldapSearchAttrSetting = settingsService.getSetting(type + "LDAPSearchAttr");
        ldapCertAttrSetting = settingsService.getSetting(type + "LDAPCertAttr");
        ldapCertFormatSetting = settingsService.getSetting(type + "LDAPCertFormat");
        //optional	    
        ldapUserSetting = settingsService.getSetting(type + "LDAPUser");
        ldapPasswordSetting = settingsService.getSetting(type + "LDAPPassword");
        ldapConnTimeoutSetting = settingsService.getSetting(type + "LDAPConnTimeout");
        ldapCertPassphraseSetting = settingsService.getSetting(type + "LDAPCertPassphrase");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting LDAP store settings: " + e.getMessage(), e);
    }
    if (ldapURLSetting == null || ldapURLSetting.getValue() == null || ldapURLSetting.getValue().isEmpty())
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "Missing LDAP URL");
    String ldapSearchBase = (ldapSearchBaseSetting == null) ? null : ldapSearchBaseSetting.getValue();
    String ldapSearchAttr = (ldapSearchAttrSetting == null) ? null : ldapSearchAttrSetting.getValue();
    String ldapCertAttr = (ldapCertAttrSetting == null) ? null : ldapCertAttrSetting.getValue();
    String ldapCertFormat = (ldapCertFormatSetting == null) ? null : ldapCertFormatSetting.getValue();
    String[] ldapURL = ldapURLSetting.getValue().split(",");
    if (ldapURL[0].isEmpty() || ldapSearchBase.isEmpty() || ldapSearchAttr.isEmpty() || ldapCertAttr.isEmpty() || ldapCertFormat.isEmpty()) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "Missing required LDAP parameters.");
    }
    String ldapUser = (ldapUserSetting == null) ? null : ldapUserSetting.getValue();
    String ldapPassword = (ldapPasswordSetting == null) ? null : ldapPasswordSetting.getValue();
    String ldapConnTimeout = (ldapConnTimeoutSetting == null) ? null : ldapConnTimeoutSetting.getValue();
    String ldapCertPassphrase = (ldapCertPassphraseSetting == null) ? null : ldapCertPassphraseSetting.getValue();
    if (ldapCertFormat.equalsIgnoreCase("pkcs12") && (ldapCertPassphrase == null || ldapCertPassphrase.isEmpty())) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat);
    }
    LdapStoreConfiguration ldapStoreConfiguration = new LdapStoreConfiguration(ldapURL, ldapSearchBase, ldapSearchAttr, ldapCertAttr, ldapCertFormat);
    if (ldapUser != null && !ldapUser.isEmpty() && ldapPassword != null && !ldapPassword.isEmpty()) {
        ldapStoreConfiguration.setEmployLdapAuthInformation(new EmployLdapAuthInformation(ldapUser, ldapPassword));
    }
    if (ldapConnTimeout != null && !ldapConnTimeout.isEmpty()) {
        ldapStoreConfiguration.setLdapConnectionTimeOut(ldapConnTimeout);
    }
    if (ldapCertPassphrase != null && !ldapCertPassphrase.isEmpty()) {
        ldapStoreConfiguration.setLdapCertPassphrase(ldapCertPassphrase);
    }
    LdapCertificateStoreProvider ldapCertificateStoreProvider = new LdapCertificateStoreProvider(ldapStoreConfiguration, null, new LDAPCertificateStore.DefaultLDAPCachePolicy());
    return ldapCertificateStoreProvider;
}
Also used : LdapStoreConfiguration(org.nhindirect.stagent.cert.impl.LdapStoreConfiguration) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) EmployLdapAuthInformation(org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation) Setting(org.nhindirect.config.model.Setting) LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) LdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Aggregations

SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)3 EmployLdapAuthInformation (org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation)3 LdapStoreConfiguration (org.nhindirect.stagent.cert.impl.LdapStoreConfiguration)3 LdapCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider)3 AddressException (javax.mail.internet.AddressException)2 PolicyParseException (org.nhindirect.policy.PolicyParseException)2 LDAPCertificateStore (org.nhindirect.stagent.cert.impl.LDAPCertificateStore)2 PublicLdapCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider)2 IOException (java.io.IOException)1 CertificateException (java.security.cert.CertificateException)1 Setting (org.nhind.config.Setting)1 Setting (org.nhindirect.config.model.Setting)1 DefaultCertStoreCachePolicy (org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy)1