From 6b3886bb1c2509f663193286261b23441c0bc45c Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 11 Dec 2012 00:00:56 +0000 Subject: [PATCH] correclty use archiva configuration for ldap connection git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1419916 13f79535-47bb-0310-9956-ffa450edef68 --- .../ldap/ArchivaLdapConnectionFactory.java | 59 ++++++++++++++++++- .../webapp/WEB-INF/applicationContext.xml | 5 +- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/runtime/ldap/ArchivaLdapConnectionFactory.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/runtime/ldap/ArchivaLdapConnectionFactory.java index c350edddb..31087baf8 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/runtime/ldap/ArchivaLdapConnectionFactory.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/runtime/ldap/ArchivaLdapConnectionFactory.java @@ -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 map ) + { + Properties properties = new Properties(); + if ( map == null ) + { + return properties; + } + for ( Map.Entry 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; } } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/WEB-INF/applicationContext.xml b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/WEB-INF/applicationContext.xml index b9a62bfe9..48705284d 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/WEB-INF/applicationContext.xml +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/WEB-INF/applicationContext.xml @@ -139,9 +139,8 @@ - - - + +