Search in sources :

Example 1 with LdapConnectionConfiguration

use of org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration in project archiva by apache.

the class ArchivaLdapConnectionFactory method initialize.

@PostConstruct
@Override
public void initialize() {
    try {
        LdapConfiguration ldapConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getLdapConfiguration();
        ldapConnectionConfiguration = new LdapConnectionConfiguration();
        ldapConnectionConfiguration.setHostname(ldapConfiguration.getHostName());
        ldapConnectionConfiguration.setPort(ldapConfiguration.getPort());
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
        ldapConnectionConfiguration.setBaseDn(ldapConfiguration.getBaseDn());
        ldapConnectionConfiguration.setContextFactory(ldapConfiguration.getContextFactory());
        ldapConnectionConfiguration.setBindDn(ldapConfiguration.getBindDn());
        ldapConnectionConfiguration.setPassword(ldapConfiguration.getPassword());
        ldapConnectionConfiguration.setAuthenticationMethod(ldapConfiguration.getAuthenticationMethod());
        ldapConnectionConfiguration.setExtraProperties(toProperties(ldapConfiguration.getExtraProperties()));
        valid = true;
    } catch (InvalidNameException e) {
        log.error("Error during initialization of LdapConnectionFactory {}", e.getMessage(), e);
    // throw new RuntimeException( "Error while initializing connection factory.", e );
    } catch (RepositoryAdminException e) {
        throw new RuntimeException("Error while initializing ldapConnectionConfiguration: " + e.getMessage(), e);
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) PostConstruct(javax.annotation.PostConstruct)

Example 2 with LdapConnectionConfiguration

use of org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationService method checkLdapConnection.

@Override
public Boolean checkLdapConnection(LdapConfiguration ldapConfiguration) throws ArchivaRestServiceException {
    LdapConnection ldapConnection = null;
    try {
        LdapConnectionConfiguration ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getExtraProperties()));
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
        ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
        ldapConnection.close();
        // verify groups dn value too
        ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseGroupsDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getExtraProperties()));
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
        ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
    } catch (InvalidNameException e) {
        log.warn("fail to get ldapConnection: {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (LdapException e) {
        log.warn("fail to get ldapConnection: {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        if (ldapConnection != null) {
            ldapConnection.close();
        }
    }
    return Boolean.TRUE;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) LdapConnection(org.apache.archiva.redback.common.ldap.connection.LdapConnection)

Aggregations

InvalidNameException (javax.naming.InvalidNameException)2 LdapConnectionConfiguration (org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration)2 PostConstruct (javax.annotation.PostConstruct)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 LdapConfiguration (org.apache.archiva.admin.model.beans.LdapConfiguration)1 LdapConnection (org.apache.archiva.redback.common.ldap.connection.LdapConnection)1 LdapException (org.apache.archiva.redback.common.ldap.connection.LdapException)1 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)1