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
20 * Licensed to the Apache Software Foundation (ASF) under one
21 * or more contributor license agreements. See the NOTICE file
22 * distributed with this work for additional information
23 * regarding copyright ownership. The ASF licenses this file
24 * to you under the Apache License, Version 2.0 (the
25 * "License"); you may not use this file except in compliance
26 * with the License. You may obtain a copy of the License at
28 * http://www.apache.org/licenses/LICENSE-2.0
29 * Unless required by applicable law or agreed to in writing,
30 * software distributed under the License is distributed on an
31 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
32 * KIND, either express or implied. See the License for the
33 * specific language governing permissions and limitations
37 import io.swagger.v3.oas.annotations.media.Schema;
39 import javax.xml.bind.annotation.XmlRootElement;
40 import java.io.Serializable;
41 import java.util.ArrayList;
42 import java.util.List;
44 import java.util.Objects;
45 import java.util.TreeMap;
48 * @author Martin Stockhammer <martin_s@apache.org>
51 @XmlRootElement(name="ldapConfiguration")
52 @Schema(name="LdapConfiguration", description = "LDAP configuration attributes")
53 public class LdapConfiguration implements Serializable
55 private static final long serialVersionUID = -4736767846016398583L;
57 private String hostName = "";
58 private int port = 389;
59 private String baseDn = "";
60 private String groupsBaseDn = "";
61 private String bindDn = "";
62 private String bindPassword = "";
63 private String authenticationMethod = "none";
64 private String contextFactory;
65 private boolean sslEnabled = false;
66 private boolean bindAuthenticatorEnabled = true;
67 private boolean useRoleNameAsGroup = false;
68 private Map<String, String> properties = new TreeMap<>();
69 private boolean writable = false;
70 private List<String> availableContextFactories;
72 public LdapConfiguration( )
76 public static LdapConfiguration of( org.apache.archiva.admin.model.beans.LdapConfiguration ldapConfiguration ) {
77 LdapConfiguration newCfg = new LdapConfiguration( );
78 newCfg.setAuthenticationMethod( ldapConfiguration.getAuthenticationMethod( ) );
79 newCfg.setBaseDn( ldapConfiguration.getBaseDn( ) );
80 newCfg.setGroupsBaseDn( ldapConfiguration.getBaseGroupsDn() );
81 newCfg.setBindDn( ldapConfiguration.getBindDn() );
82 newCfg.setBindPassword( ldapConfiguration.getPassword() );
83 newCfg.setBindAuthenticatorEnabled( ldapConfiguration.isBindAuthenticatorEnabled() );
84 newCfg.setHostName( ldapConfiguration.getHostName( ) );
85 newCfg.setSslEnabled( ldapConfiguration.isSsl() );
86 newCfg.setContextFactory( ldapConfiguration.getContextFactory() );
87 if (ldapConfiguration.getPort()<=0) {
88 newCfg.setPort( newCfg.isSslEnabled() ? 636 : 389 );
91 newCfg.setPort( ldapConfiguration.getPort( ) );
93 newCfg.setProperties( ldapConfiguration.getExtraProperties( ) );
94 newCfg.setWritable( ldapConfiguration.isWritable() );
98 @Schema(name="host_name", description = "The hostname to use to connect to the LDAP server")
99 public String getHostName( )
104 public void setHostName( String hostName )
106 this.hostName = hostName==null?"":hostName;
109 @Schema(description = "The port to use to connect to the LDAP server")
110 public int getPort( )
115 public void setPort( int port )
120 @Schema(name="context_factory",description = "The class name of the LDAP context factory")
121 public String getContextFactory( )
123 return contextFactory;
126 public void setContextFactory( String contextFactory )
128 this.contextFactory = contextFactory;
132 @Schema(name="ssl_enabled", description = "True, if SSL/TLS should be used for connecting the LDAP server")
133 public boolean isSslEnabled( )
138 public void setSslEnabled( boolean sslEnabled )
140 this.sslEnabled = sslEnabled;
143 @Schema(name="base_dn", description = "The BASE DN used for the LDAP server")
144 public String getBaseDn( )
149 public void setBaseDn( String baseDn )
151 this.baseDn = baseDn == null ? "" : baseDn;
154 @Schema(name="bind_dn", description = "The distinguished name of the bind user which is used to bind to the LDAP server")
155 public String getBindDn( )
160 public void setBindDn( String bindDn )
162 this.bindDn = bindDn == null ? "" : bindDn;
165 @Schema(name="bind_password", description = "The password used to bind to the ldap server")
166 public String getBindPassword( )
171 public void setBindPassword( String bindPassword )
173 this.bindPassword = bindPassword==null?"":bindPassword;
176 @Schema(name="groups_base_dn", description = "The distinguished name of the base to use for searching group.")
177 public String getGroupsBaseDn( )
182 public void setGroupsBaseDn( String groupsBaseDn )
184 this.groupsBaseDn = groupsBaseDn==null?"":groupsBaseDn;
187 @Schema(name="authentication_method", description = "The authentication method used to bind to the LDAP server (PLAINTEXT, SASL, ...)")
188 public String getAuthenticationMethod( )
190 return authenticationMethod;
193 public void setAuthenticationMethod( String authenticationMethod )
195 this.authenticationMethod = authenticationMethod==null?"":authenticationMethod;
198 @Schema(name="bind_authenticator_enabled", description = "True, if the LDAP bind authentication is used for logging in to Archiva")
199 public boolean isBindAuthenticatorEnabled( )
201 return bindAuthenticatorEnabled;
204 public void setBindAuthenticatorEnabled( boolean bindAuthenticatorEnabled )
206 this.bindAuthenticatorEnabled = bindAuthenticatorEnabled;
209 @Schema(name="user_role_name_as_group", description = "True, if the archiva role name is also the LDAP group name")
210 public boolean isUseRoleNameAsGroup( )
212 return useRoleNameAsGroup;
215 public void setUseRoleNameAsGroup( boolean useRoleNameAsGroup )
217 this.useRoleNameAsGroup = useRoleNameAsGroup;
220 @Schema(description = "LDAP ConnectionFactory environment properties")
221 public Map<String, String> getProperties( )
226 public void setProperties( Map<String, String> properties )
228 this.properties = new TreeMap<>( properties );
231 public void addProperty(String key, String value) {
232 this.properties.put( key, value );
235 @Schema(description = "True, if attributes in the the LDAP server can be edited by Archiva")
236 public boolean isWritable( )
241 public void setWritable( boolean writable )
243 this.writable = writable;
246 @Schema(name="available_context_factories", description = "The LDAP context factories that are known and available")
247 public List<String> getAvailableContextFactories( )
249 return availableContextFactories;
252 public void setAvailableContextFactories( List<String> availableContextFactories )
254 this.availableContextFactories = new ArrayList<>( availableContextFactories );
257 public void addAvailableContextFactory(String contextFactory) {
258 if (!this.availableContextFactories.contains( contextFactory ) ) {
259 this.availableContextFactories.add( contextFactory );
266 public boolean equals( Object o )
268 if ( this == o ) return true;
269 if ( o == null || getClass( ) != o.getClass( ) ) return false;
271 LdapConfiguration that = (LdapConfiguration) o;
273 if ( port != that.port ) return false;
274 if ( sslEnabled != that.sslEnabled ) return false;
275 if ( bindAuthenticatorEnabled != that.bindAuthenticatorEnabled ) return false;
276 if ( useRoleNameAsGroup != that.useRoleNameAsGroup ) return false;
277 if ( writable != that.writable ) return false;
278 if ( !Objects.equals( hostName, that.hostName ) ) return false;
279 if ( !Objects.equals( baseDn, that.baseDn ) ) return false;
280 if ( !Objects.equals( bindDn, that.bindDn ) ) return false;
281 if ( !Objects.equals( groupsBaseDn, that.groupsBaseDn ) )
283 if ( !Objects.equals( bindPassword, that.bindPassword ) ) return false;
284 if ( !Objects.equals( authenticationMethod, that.authenticationMethod ) )
286 return properties.equals( that.properties );
290 public int hashCode( )
292 int result = hostName != null ? hostName.hashCode( ) : 0;
293 result = 31 * result + port;
294 result = 31 * result + ( sslEnabled ? 1 : 0 );
295 result = 31 * result + ( baseDn != null ? baseDn.hashCode( ) : 0 );
296 result = 31 * result + ( bindDn != null ? bindDn.hashCode( ) : 0 );
297 result = 31 * result + ( groupsBaseDn != null ? groupsBaseDn.hashCode( ) : 0 );
298 result = 31 * result + ( bindPassword != null ? bindPassword.hashCode( ) : 0 );
299 result = 31 * result + ( authenticationMethod != null ? authenticationMethod.hashCode( ) : 0 );
300 result = 31 * result + ( bindAuthenticatorEnabled ? 1 : 0 );
301 result = 31 * result + ( useRoleNameAsGroup ? 1 : 0 );
302 result = 31 * result + properties.hashCode( );
303 result = 31 * result + ( writable ? 1 : 0 );
307 @SuppressWarnings( "StringBufferReplaceableByString" )
309 public String toString( )
311 final StringBuilder sb = new StringBuilder( "LdapConfiguration{" );
312 sb.append( "host_name='" ).append( hostName ).append( '\'' );
313 sb.append( ", port=" ).append( port );
314 sb.append( ", ssl_enabled=" ).append( sslEnabled );
315 sb.append( ", base_dn='" ).append( baseDn ).append( '\'' );
316 sb.append( ", groups_base_dn='" ).append( groupsBaseDn ).append( '\'' );
317 sb.append( ", bind_dn='" ).append( bindDn ).append( '\'' );
318 sb.append( ", bind_password='" ).append( bindPassword ).append( '\'' );
319 sb.append( ", authentication_method='" ).append( authenticationMethod ).append( '\'' );
320 sb.append( ", bind_authenticator_enabled=" ).append( bindAuthenticatorEnabled );
321 sb.append( ", use_role_name_as_group=" ).append( useRoleNameAsGroup );
322 sb.append( ", properties=" ).append( properties );
323 sb.append( ", writable=" ).append( writable );
325 return sb.toString( );