Search in sources :

Example 6 with LDAPCertificateStore

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

the class LdapCertificateStoreProvider method get.

public CertificateResolver get() {
    final Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, LDAP_FACTORY);
    String[] ldapURLs = ldapConfiguration.getLdapURLs();
    String ldapProviderUrl = null;
    for (String ldapURL : ldapURLs) {
        if (ldapProviderUrl == null) {
            ldapProviderUrl = ldapURL + " ";
        } else {
            ldapProviderUrl += ldapURL + " ";
        }
    }
    env.put(Context.PROVIDER_URL, ldapProviderUrl);
    if (ldapConfiguration.getLdapConnectionTimeOut() != null) {
        try {
            int connectionTimeOut = Integer.parseInt(ldapConfiguration.getLdapConnectionTimeOut());
            if (connectionTimeOut < 1) {
                LOGGER.error("Connection timeout must be a positive integer");
                throw new NHINDException("Invalid value for the LDAP connection timeout");
            }
        } catch (NumberFormatException nfe) {
            LOGGER.error("Connection timeout string is not a valid number.");
            throw new NHINDException("Invalid value for the LDAP connection timeout", nfe);
        }
        env.put(LDAP_TIMEOUT, ldapConfiguration.getLdapConnectionTimeOut());
    }
    if (ldapConfiguration.getEmployLdapAuthInformation() != null) {
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, ldapConfiguration.getEmployLdapAuthInformation().getLdapPrincipal());
        env.put(Context.SECURITY_CREDENTIALS, ldapConfiguration.getEmployLdapAuthInformation().getLdapPassword());
    } else {
        env.put(Context.SECURITY_AUTHENTICATION, "none");
    }
    LdapEnvironment ldapEnvironment = new LdapEnvironment(env, ldapConfiguration.getReturningCertAttribute(), ldapConfiguration.getLdapSearchBase(), ldapConfiguration.getLdapSearchAttribute());
    LdapCertUtilImpl ldapcertUtilImpl = new LdapCertUtilImpl(ldapEnvironment, ldapConfiguration.getLdapCertPassphrase(), ldapConfiguration.getCertificateFormat());
    return new LDAPCertificateStore(ldapcertUtilImpl, bootstrapStore, policy);
}
Also used : LdapEnvironment(org.nhindirect.stagent.cert.impl.LdapEnvironment) Hashtable(java.util.Hashtable) LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) LdapCertUtilImpl(org.nhindirect.stagent.cert.impl.LdapCertUtilImpl) NHINDException(org.nhindirect.stagent.NHINDException)

Example 7 with LDAPCertificateStore

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

the class PublicLdapCertifictaeStoreProvider_getResolver_Test method testGetResolverFromProvider.

public void testGetResolverFromProvider() throws Exception {
    PublicLdapCertificateStoreProvider provider = new PublicLdapCertificateStoreProvider(null, null);
    CertificateResolver resolver = provider.get();
    assertNotNull(resolver);
    assertTrue(resolver instanceof LDAPCertificateStore);
}
Also used : LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver)

Aggregations

LDAPCertificateStore (org.nhindirect.stagent.cert.impl.LDAPCertificateStore)7 X509Certificate (java.security.cert.X509Certificate)5 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)3 KeyStoreCertificateStore (org.nhindirect.stagent.cert.impl.KeyStoreCertificateStore)3 Hashtable (java.util.Hashtable)2 AddressException (javax.mail.internet.AddressException)2 PolicyParseException (org.nhindirect.policy.PolicyParseException)2 File (java.io.File)1 IOException (java.io.IOException)1 CertificateException (java.security.cert.CertificateException)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 InternetAddress (javax.mail.internet.InternetAddress)1 InitialContext (javax.naming.InitialContext)1 NamingEnumeration (javax.naming.NamingEnumeration)1 Attribute (javax.naming.directory.Attribute)1 Attributes (javax.naming.directory.Attributes)1 BasicAttribute (javax.naming.directory.BasicAttribute)1