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.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.stereotype.Service;
30 import javax.annotation.PostConstruct;
31 import javax.inject.Inject;
32 import javax.naming.InvalidNameException;
34 import java.util.Properties;
37 * @author Olivier Lamy
40 @Service( "ldapConnectionFactory#archiva" )
41 public class ArchivaLdapConnectionFactory
42 extends ConfigurableLdapConnectionFactory
45 private final Logger log = LoggerFactory.getLogger(ArchivaLdapConnectionFactory.class);
47 private boolean valid = false;
50 private RedbackRuntimeConfigurationAdmin redbackRuntimeConfigurationAdmin;
52 private LdapConnectionConfiguration ldapConnectionConfiguration;
56 public void initialize()
60 LdapConfiguration ldapConfiguration =
61 redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getLdapConfiguration();
62 ldapConnectionConfiguration = new LdapConnectionConfiguration();
63 ldapConnectionConfiguration.setHostname( ldapConfiguration.getHostName() );
64 ldapConnectionConfiguration.setPort( ldapConfiguration.getPort() );
65 ldapConnectionConfiguration.setSsl( ldapConfiguration.isSsl() );
66 ldapConnectionConfiguration.setBaseDn( ldapConfiguration.getBaseDn() );
67 ldapConnectionConfiguration.setContextFactory( ldapConfiguration.getContextFactory() );
68 ldapConnectionConfiguration.setBindDn( ldapConfiguration.getBindDn() );
69 ldapConnectionConfiguration.setPassword( ldapConfiguration.getPassword() );
70 ldapConnectionConfiguration.setAuthenticationMethod( ldapConfiguration.getAuthenticationMethod() );
71 ldapConnectionConfiguration.setExtraProperties( toProperties( ldapConfiguration.getExtraProperties() ) );
74 catch ( InvalidNameException e )
76 log.error("Error during initialization of LdapConnectionFactory "+e.getMessage(),e);
77 // throw new RuntimeException( "Error while initializing connection factory.", e );
79 catch ( RepositoryAdminException e )
81 throw new RuntimeException( "Error while initializing ldapConnectionConfiguration: " + e.getMessage(), e );
85 private Properties toProperties( Map<String, String> map )
87 Properties properties = new Properties();
92 for ( Map.Entry<String, String> entry : map.entrySet() )
94 properties.put( entry.getKey(), entry.getValue() );
100 public LdapConnectionConfiguration getLdapConnectionConfiguration()
102 return this.ldapConnectionConfiguration;
106 public void setLdapConnectionConfiguration( LdapConnectionConfiguration ldapConnectionConfiguration )
108 this.ldapConnectionConfiguration = ldapConnectionConfiguration;
112 public boolean isValid() {