This project has retired. For details please refer to its
Attic page.
ArchivaLdapConnectionFactory xref
1 package org.apache.archiva.web.runtime.ldap;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
29
30 import javax.annotation.PostConstruct;
31 import javax.inject.Inject;
32 import javax.naming.InvalidNameException;
33 import java.util.Map;
34 import java.util.Properties;
35
36
37
38
39
40 @Service( "ldapConnectionFactory#archiva" )
41 public class ArchivaLdapConnectionFactory
42 extends ConfigurableLdapConnectionFactory
43 {
44
45 private final Logger log = LoggerFactory.getLogger(ArchivaLdapConnectionFactory.class);
46
47 private boolean valid = false;
48
49 @Inject
50 private RedbackRuntimeConfigurationAdmin redbackRuntimeConfigurationAdmin;
51
52 private LdapConnectionConfiguration ldapConnectionConfiguration;
53
54 @PostConstruct
55 @Override
56 public void initialize()
57 {
58 try
59 {
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() ) );
72 valid=true;
73 }
74 catch ( InvalidNameException e )
75 {
76 log.error("Error during initialization of LdapConnectionFactory "+e.getMessage(),e);
77
78 }
79 catch ( RepositoryAdminException e )
80 {
81 throw new RuntimeException( "Error while initializing ldapConnectionConfiguration: " + e.getMessage(), e );
82 }
83 }
84
85 private Properties toProperties( Map<String, String> map )
86 {
87 Properties properties = new Properties();
88 if ( map == null )
89 {
90 return properties;
91 }
92 for ( Map.Entry<String, String> entry : map.entrySet() )
93 {
94 properties.put( entry.getKey(), entry.getValue() );
95 }
96 return properties;
97 }
98
99 @Override
100 public LdapConnectionConfiguration getLdapConnectionConfiguration()
101 {
102 return this.ldapConnectionConfiguration;
103 }
104
105 @Override
106 public void setLdapConnectionConfiguration( LdapConnectionConfiguration ldapConnectionConfiguration )
107 {
108 this.ldapConnectionConfiguration = ldapConnectionConfiguration;
109 }
110
111 @Override
112 public boolean isValid() {
113 return valid;
114 }
115 }