1 package org.apache.archiva.web.runtime.ldap;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.LdapConfiguration;
23 import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin;
24 import org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory;
25 import org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration;
26 import org.springframework.stereotype.Service;
28 import javax.annotation.PostConstruct;
29 import javax.inject.Inject;
30 import javax.naming.InvalidNameException;
32 import java.util.Properties;
35 * @author Olivier Lamy
38 @Service( "ldapConnectionFactory#archiva" )
39 public class ArchivaLdapConnectionFactory
40 extends ConfigurableLdapConnectionFactory
44 private RedbackRuntimeConfigurationAdmin redbackRuntimeConfigurationAdmin;
46 private LdapConnectionConfiguration ldapConnectionConfiguration;
50 public void initialize()
54 LdapConfiguration ldapConfiguration =
55 redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getLdapConfiguration();
56 ldapConnectionConfiguration = new LdapConnectionConfiguration();
57 ldapConnectionConfiguration.setHostname( ldapConfiguration.getHostName() );
58 ldapConnectionConfiguration.setPort( ldapConfiguration.getPort() );
59 ldapConnectionConfiguration.setSsl( ldapConfiguration.isSsl() );
60 ldapConnectionConfiguration.setBaseDn( ldapConfiguration.getBaseDn() );
61 ldapConnectionConfiguration.setContextFactory( ldapConfiguration.getContextFactory() );
62 ldapConnectionConfiguration.setBindDn( ldapConfiguration.getBindDn() );
63 ldapConnectionConfiguration.setPassword( ldapConfiguration.getPassword() );
64 ldapConnectionConfiguration.setAuthenticationMethod( ldapConfiguration.getAuthenticationMethod() );
65 ldapConnectionConfiguration.setExtraProperties( toProperties( ldapConfiguration.getExtraProperties() ) );
67 catch ( InvalidNameException e )
69 throw new RuntimeException( "Error while initializing connection factory.", e );
71 catch ( RepositoryAdminException e )
73 throw new RuntimeException( "Error while initializing ldapConnectionConfiguration: " + e.getMessage(), e );
77 private Properties toProperties( Map<String, String> map )
79 Properties properties = new Properties();
84 for ( Map.Entry<String, String> entry : map.entrySet() )
86 properties.put( entry.getKey(), entry.getValue() );
92 public LdapConnectionConfiguration getLdapConnectionConfiguration()
94 return this.ldapConnectionConfiguration;
98 public void setLdapConnectionConfiguration( LdapConnectionConfiguration ldapConnectionConfiguration )
100 this.ldapConnectionConfiguration = ldapConnectionConfiguration;