mirror of https://github.com/apache/archiva.git
correclty use archiva configuration for ldap connection
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1419916 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
504abcf697
commit
6b3886bb1c
|
@ -18,13 +18,20 @@ package org.apache.archiva.web.runtime.ldap;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
||||
import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
|
||||
import org.apache.archiva.admin.model.beans.LdapConfiguration;
|
||||
import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
|
||||
import org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory;
|
||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.InvalidNameException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
|
@ -38,9 +45,59 @@ public class ArchivaLdapConnectionFactory
|
|||
@Inject
|
||||
private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
|
||||
|
||||
private LdapConnectionConfiguration ldapConnectionConfiguration;
|
||||
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
{
|
||||
// no op
|
||||
try
|
||||
{
|
||||
LdapConfiguration ldapConfiguration =
|
||||
archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration().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() ) );
|
||||
}
|
||||
catch ( InvalidNameException e )
|
||||
{
|
||||
throw new RuntimeException( "Error while initializing connection factory.", e );
|
||||
}
|
||||
catch ( RepositoryAdminException e )
|
||||
{
|
||||
throw new RuntimeException( "Error while initializing ldapConnectionConfiguration: " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
private Properties toProperties( Map<String, String> map )
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
if ( map == null )
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
for ( Map.Entry<String, String> entry : map.entrySet() )
|
||||
{
|
||||
properties.put( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LdapConnectionConfiguration getLdapConnectionConfiguration()
|
||||
{
|
||||
return this.ldapConnectionConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLdapConnectionConfiguration( LdapConnectionConfiguration ldapConnectionConfiguration )
|
||||
{
|
||||
this.ldapConnectionConfiguration = ldapConnectionConfiguration;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,9 +139,8 @@
|
|||
|
||||
<alias name="userManager#archiva" alias="userManager#configurable"/>
|
||||
|
||||
<bean name="ldapConnectionFactory" class="org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory">
|
||||
<property name="userConf" ref="userConfiguration#default"/>
|
||||
</bean>
|
||||
<alias name="ldapConnectionFactory#archiva" alias="ldapConnectionFactory"/>
|
||||
<alias name="ldapConnectionFactory#archiva" alias="ldapConnectionFactory#configurable"/>
|
||||
|
||||
<!-- <component>
|
||||
<role>org.apache.archiva.webdav.util.MimeTypes</role>
|
||||
|
|
Loading…
Reference in New Issue