Search in sources :

Example 1 with LdapConnectionProvider

use of org.gluu.persist.ldap.operation.impl.LdapConnectionProvider in project oxTrust by GluuFederation.

the class ManagePersonAuthenticationAction method testLdapConnection.

public String testLdapConnection(GluuLdapConfiguration ldapConfig) {
    try {
        FileConfiguration configuration = new FileConfiguration(ConfigurationFactory.LDAP_PROPERTIES_FILE);
        if (!configuration.isLoaded()) {
            configuration = new FileConfiguration(ConfigurationFactory.LDAP_DEFAULT_PROPERTIES_FILE);
        }
        Properties properties = configuration.getProperties();
        properties.setProperty("bindDN", ldapConfig.getBindDN());
        properties.setProperty("bindPassword", ldapConfig.getBindPassword());
        properties.setProperty("servers", buildServersString(ldapConfig.getServers()));
        properties.setProperty("useSSL", Boolean.toString(ldapConfig.isUseSSL()));
        LdapConnectionProvider connectionProvider = new LdapConnectionProvider(PropertiesDecrypter.decryptProperties(properties, configurationFactory.getCryptoConfigurationSalt()));
        if (connectionProvider.isConnected()) {
            connectionProvider.closeConnectionPool();
            facesMessages.add(FacesMessage.SEVERITY_INFO, "LDAP Connection Test succeeded!");
            return OxTrustConstants.RESULT_SUCCESS;
        }
        if (connectionProvider.getConnectionPool() != null) {
            connectionProvider.closeConnectionPool();
        }
    } catch (Exception ex) {
        log.error("Could not connect to LDAP", ex);
    }
    facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to connect to LDAP server");
    return OxTrustConstants.RESULT_FAILURE;
}
Also used : FileConfiguration(org.xdi.util.properties.FileConfiguration) LdapConnectionProvider(org.gluu.persist.ldap.operation.impl.LdapConnectionProvider) Properties(java.util.Properties) EncryptionException(org.xdi.util.security.StringEncrypter.EncryptionException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 2 with LdapConnectionProvider

use of org.gluu.persist.ldap.operation.impl.LdapConnectionProvider in project oxCore by GluuFederation.

the class LdapEntryManagerFactory method createEntryManager.

@Override
public LdapEntryManager createEntryManager(Properties conf) {
    LdapConnectionProvider connectionProvider = new LdapConnectionProvider(conf);
    if (!connectionProvider.isCreated()) {
        throw new ConfigurationException(String.format("Failed to create LDAP connection pool! Result code: '%s'", connectionProvider.getCreationResultCode()));
    }
    LOG.debug("Created connectionProvider '{}' with code '{}'", connectionProvider, connectionProvider.getCreationResultCode());
    LdapConnectionProvider bindConnectionProvider = new LdapAuthConnectionProvider(conf);
    if (!bindConnectionProvider.isCreated()) {
        throw new ConfigurationException(String.format("Failed to create LDAP bind connection pool! Result code: '%s'", bindConnectionProvider.getCreationResultCode()));
    }
    LOG.debug("Created bindConnectionProvider '{}' with code '{}'", bindConnectionProvider, bindConnectionProvider.getCreationResultCode());
    LdapEntryManager ldapEntryManager = new LdapEntryManager(new LdapOperationsServiceImpl(connectionProvider, bindConnectionProvider));
    LOG.info("Created LdapEntryManager: {}", ldapEntryManager.getOperationService());
    return ldapEntryManager;
}
Also used : ConfigurationException(org.gluu.persist.exception.operation.ConfigurationException) LdapConnectionProvider(org.gluu.persist.ldap.operation.impl.LdapConnectionProvider) LdapAuthConnectionProvider(org.gluu.persist.ldap.operation.impl.LdapAuthConnectionProvider) LdapOperationsServiceImpl(org.gluu.persist.ldap.operation.impl.LdapOperationsServiceImpl)

Aggregations

LdapConnectionProvider (org.gluu.persist.ldap.operation.impl.LdapConnectionProvider)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)1 JsonParseException (org.codehaus.jackson.JsonParseException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)1 ConfigurationException (org.gluu.persist.exception.operation.ConfigurationException)1 LdapAuthConnectionProvider (org.gluu.persist.ldap.operation.impl.LdapAuthConnectionProvider)1 LdapOperationsServiceImpl (org.gluu.persist.ldap.operation.impl.LdapOperationsServiceImpl)1 FileConfiguration (org.xdi.util.properties.FileConfiguration)1 EncryptionException (org.xdi.util.security.StringEncrypter.EncryptionException)1