1 package org.apache.archiva.rest.api.model.v2;/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 import io.swagger.v3.oas.annotations.media.Schema;
21 import javax.xml.bind.annotation.XmlRootElement;
22 import java.io.Serializable;
23 import java.util.List;
25 import java.util.Objects;
26 import java.util.TreeMap;
29 * @author Martin Stockhammer <martin_s@apache.org>
32 @XmlRootElement(name="ldapConfiguration")
33 @Schema(name="LdapConfiguration", description = "LDAP configuration attributes")
34 public class LdapConfiguration implements Serializable
36 private static final long serialVersionUID = -4736767846016398583L;
38 private String hostName = "";
39 private int port = 389;
40 private String baseDn = "";
41 private String groupsBaseDn = "";
42 private String bindDn = "";
43 private String bindPassword = "";
44 private String authenticationMethod = "none";
45 private String contextFactory;
46 private boolean sslEnabled = false;
47 private boolean bindAuthenticatorEnabled = true;
48 private boolean useRoleNameAsGroup = false;
49 private final Map<String, String> properties = new TreeMap<>();
50 private boolean writable = false;
51 private List<String> availableContextFactories;
53 public LdapConfiguration( )
57 public static LdapConfiguration of( org.apache.archiva.admin.model.beans.LdapConfiguration ldapConfiguration ) {
58 LdapConfiguration newCfg = new LdapConfiguration( );
59 newCfg.setAuthenticationMethod( ldapConfiguration.getAuthenticationMethod( ) );
60 newCfg.setBaseDn( ldapConfiguration.getBaseDn( ) );
61 newCfg.setGroupsBaseDn( ldapConfiguration.getBaseGroupsDn() );
62 newCfg.setBindDn( ldapConfiguration.getBindDn() );
63 newCfg.setBindPassword( ldapConfiguration.getPassword() );
64 newCfg.setBindAuthenticatorEnabled( ldapConfiguration.isBindAuthenticatorEnabled() );
65 newCfg.setHostName( ldapConfiguration.getHostName( ) );
66 newCfg.setSslEnabled( ldapConfiguration.isSsl() );
67 newCfg.setContextFactory( ldapConfiguration.getContextFactory() );
68 if (ldapConfiguration.getPort()<=0) {
69 newCfg.setPort( newCfg.isSslEnabled() ? 636 : 389 );
72 newCfg.setPort( ldapConfiguration.getPort( ) );
74 newCfg.setProperties( ldapConfiguration.getExtraProperties( ) );
75 newCfg.setWritable( ldapConfiguration.isWritable() );
79 @Schema(name="host_name", description = "The hostname to use to connect to the LDAP server")
80 public String getHostName( )
85 public void setHostName( String hostName )
87 this.hostName = hostName==null?"":hostName;
90 @Schema(description = "The port to use to connect to the LDAP server")
96 public void setPort( int port )
101 @Schema(name="context_factory",description = "The class name of the LDAP context factory")
102 public String getContextFactory( )
104 return contextFactory;
107 public void setContextFactory( String contextFactory )
109 this.contextFactory = contextFactory;
113 @Schema(name="ssl_enabled", description = "True, if SSL/TLS should be used for connecting the LDAP server")
114 public boolean isSslEnabled( )
119 public void setSslEnabled( boolean sslEnabled )
121 this.sslEnabled = sslEnabled;
124 @Schema(name="base_dn", description = "The BASE DN used for the LDAP server")
125 public String getBaseDn( )
130 public void setBaseDn( String baseDn )
132 this.baseDn = baseDn == null ? "" : baseDn;
135 @Schema(name="bind_dn", description = "The distinguished name of the bind user which is used to bind to the LDAP server")
136 public String getBindDn( )
141 public void setBindDn( String bindDn )
143 this.bindDn = bindDn == null ? "" : bindDn;
146 @Schema(name="bind_password", description = "The password used to bind to the ldap server")
147 public String getBindPassword( )
152 public void setBindPassword( String bindPassword )
154 this.bindPassword = bindPassword==null?"":bindPassword;
157 @Schema(name="groups_base_dn", description = "The distinguished name of the base to use for searching group.")
158 public String getGroupsBaseDn( )
163 public void setGroupsBaseDn( String groupsBaseDn )
165 this.groupsBaseDn = groupsBaseDn==null?"":groupsBaseDn;
168 @Schema(name="authentication_method", description = "The authentication method used to bind to the LDAP server (PLAINTEXT, SASL, ...)")
169 public String getAuthenticationMethod( )
171 return authenticationMethod;
174 public void setAuthenticationMethod( String authenticationMethod )
176 this.authenticationMethod = authenticationMethod==null?"":authenticationMethod;
179 @Schema(name="bind_authenticator_enabled", description = "True, if the LDAP bind authentication is used for logging in to Archiva")
180 public boolean isBindAuthenticatorEnabled( )
182 return bindAuthenticatorEnabled;
185 public void setBindAuthenticatorEnabled( boolean bindAuthenticatorEnabled )
187 this.bindAuthenticatorEnabled = bindAuthenticatorEnabled;
190 @Schema(name="user_role_name_as_group", description = "True, if the archiva role name is also the LDAP group name")
191 public boolean isUseRoleNameAsGroup( )
193 return useRoleNameAsGroup;
196 public void setUseRoleNameAsGroup( boolean useRoleNameAsGroup )
198 this.useRoleNameAsGroup = useRoleNameAsGroup;
201 @Schema(description = "LDAP ConnectionFactory environment properties")
202 public Map<String, String> getProperties( )
207 public void setProperties( Map<String, String> properties )
209 this.properties.clear();
210 this.properties.putAll( properties );
213 @Schema(description = "True, if attributes in the the LDAP server can be edited by Archiva")
214 public boolean isWritable( )
219 public void setWritable( boolean writable )
221 this.writable = writable;
224 @Schema(name="available_context_factories", description = "The LDAP context factories that are known and available")
225 public List<String> getAvailableContextFactories( )
227 return availableContextFactories;
230 public void setAvailableContextFactories( List<String> availableContextFactories )
232 this.availableContextFactories = availableContextFactories;
238 public boolean equals( Object o )
240 if ( this == o ) return true;
241 if ( o == null || getClass( ) != o.getClass( ) ) return false;
243 LdapConfiguration that = (LdapConfiguration) o;
245 if ( port != that.port ) return false;
246 if ( sslEnabled != that.sslEnabled ) return false;
247 if ( bindAuthenticatorEnabled != that.bindAuthenticatorEnabled ) return false;
248 if ( useRoleNameAsGroup != that.useRoleNameAsGroup ) return false;
249 if ( writable != that.writable ) return false;
250 if ( !Objects.equals( hostName, that.hostName ) ) return false;
251 if ( !Objects.equals( baseDn, that.baseDn ) ) return false;
252 if ( !Objects.equals( bindDn, that.bindDn ) ) return false;
253 if ( !Objects.equals( groupsBaseDn, that.groupsBaseDn ) )
255 if ( !Objects.equals( bindPassword, that.bindPassword ) ) return false;
256 if ( !Objects.equals( authenticationMethod, that.authenticationMethod ) )
258 return properties.equals( that.properties );
262 public int hashCode( )
264 int result = hostName != null ? hostName.hashCode( ) : 0;
265 result = 31 * result + port;
266 result = 31 * result + ( sslEnabled ? 1 : 0 );
267 result = 31 * result + ( baseDn != null ? baseDn.hashCode( ) : 0 );
268 result = 31 * result + ( bindDn != null ? bindDn.hashCode( ) : 0 );
269 result = 31 * result + ( groupsBaseDn != null ? groupsBaseDn.hashCode( ) : 0 );
270 result = 31 * result + ( bindPassword != null ? bindPassword.hashCode( ) : 0 );
271 result = 31 * result + ( authenticationMethod != null ? authenticationMethod.hashCode( ) : 0 );
272 result = 31 * result + ( bindAuthenticatorEnabled ? 1 : 0 );
273 result = 31 * result + ( useRoleNameAsGroup ? 1 : 0 );
274 result = 31 * result + properties.hashCode( );
275 result = 31 * result + ( writable ? 1 : 0 );
279 @SuppressWarnings( "StringBufferReplaceableByString" )
281 public String toString( )
283 final StringBuilder sb = new StringBuilder( "LdapConfiguration{" );
284 sb.append( "host_name='" ).append( hostName ).append( '\'' );
285 sb.append( ", port=" ).append( port );
286 sb.append( ", ssl_enabled=" ).append( sslEnabled );
287 sb.append( ", base_dn='" ).append( baseDn ).append( '\'' );
288 sb.append( ", groups_base_dn='" ).append( groupsBaseDn ).append( '\'' );
289 sb.append( ", bind_dn='" ).append( bindDn ).append( '\'' );
290 sb.append( ", bind_password='" ).append( bindPassword ).append( '\'' );
291 sb.append( ", authentication_method='" ).append( authenticationMethod ).append( '\'' );
292 sb.append( ", bind_authenticator_enabled=" ).append( bindAuthenticatorEnabled );
293 sb.append( ", use_role_name_as_group=" ).append( useRoleNameAsGroup );
294 sb.append( ", properties=" ).append( properties );
295 sb.append( ", writable=" ).append( writable );
297 return sb.toString( );