You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LdapConfiguration.java 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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
  9. *
  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
  16. * under the License.
  17. */
  18. import io.swagger.v3.oas.annotations.media.Schema;
  19. import javax.xml.bind.annotation.XmlRootElement;
  20. import java.io.Serializable;
  21. import java.util.Map;
  22. import java.util.Objects;
  23. import java.util.TreeMap;
  24. /**
  25. * @author Martin Stockhammer <martin_s@apache.org>
  26. */
  27. @XmlRootElement(name="ldapConfiguration")
  28. public class LdapConfiguration implements Serializable
  29. {
  30. private static final long serialVersionUID = -4736767846016398583L;
  31. private String hostName = "";
  32. private int port = 389;
  33. private boolean sslEnabled = false;
  34. private String baseDn = "";
  35. private String groupsBaseDn = "";
  36. private String bindDn = "";
  37. private String bindPassword = "";
  38. private String authenticationMethod = "";
  39. private boolean bindAuthenticatorEnabled = true;
  40. private boolean useRoleNameAsGroup = false;
  41. private final Map<String, String> properties = new TreeMap<>();
  42. private boolean writable = false;
  43. public LdapConfiguration( )
  44. {
  45. }
  46. public static LdapConfiguration of( org.apache.archiva.admin.model.beans.LdapConfiguration ldapConfiguration ) {
  47. LdapConfiguration newCfg = new LdapConfiguration( );
  48. newCfg.setAuthenticationMethod( ldapConfiguration.getAuthenticationMethod( ) );
  49. newCfg.setBaseDn( ldapConfiguration.getBaseDn( ) );
  50. newCfg.setGroupsBaseDn( ldapConfiguration.getBaseGroupsDn() );
  51. newCfg.setBindDn( ldapConfiguration.getBindDn() );
  52. newCfg.setBindPassword( ldapConfiguration.getPassword() );
  53. newCfg.setBindAuthenticatorEnabled( ldapConfiguration.isBindAuthenticatorEnabled() );
  54. newCfg.setHostName( ldapConfiguration.getHostName( ) );
  55. newCfg.setPort( ldapConfiguration.getPort( ) );
  56. newCfg.setProperties( ldapConfiguration.getExtraProperties( ) );
  57. newCfg.setSslEnabled( ldapConfiguration.isSsl() );
  58. newCfg.setWritable( ldapConfiguration.isWritable() );
  59. return newCfg;
  60. }
  61. @Schema(description = "The hostname to use to connect to the LDAP server")
  62. public String getHostName( )
  63. {
  64. return hostName;
  65. }
  66. public void setHostName( String hostName )
  67. {
  68. this.hostName = hostName;
  69. }
  70. @Schema(description = "The port to use to connect to the LDAP server")
  71. public int getPort( )
  72. {
  73. return port;
  74. }
  75. public void setPort( int port )
  76. {
  77. this.port = port;
  78. }
  79. @Schema(description = "If SSL should be used for connecting the LDAP server")
  80. public boolean isSslEnabled( )
  81. {
  82. return sslEnabled;
  83. }
  84. public void setSslEnabled( boolean sslEnabled )
  85. {
  86. this.sslEnabled = sslEnabled;
  87. }
  88. @Schema(description = "The BASE DN used for the LDAP server")
  89. public String getBaseDn( )
  90. {
  91. return baseDn;
  92. }
  93. public void setBaseDn( String baseDn )
  94. {
  95. this.baseDn = baseDn;
  96. }
  97. @Schema(description = "The distinguished name of the bind user which is used to bind to the LDAP server")
  98. public String getBindDn( )
  99. {
  100. return bindDn;
  101. }
  102. public void setBindDn( String bindDn )
  103. {
  104. this.bindDn = bindDn;
  105. }
  106. @Schema(description = "The password used to bind to the ldap server")
  107. public String getBindPassword( )
  108. {
  109. return bindPassword;
  110. }
  111. public void setBindPassword( String bindPassword )
  112. {
  113. this.bindPassword = bindPassword;
  114. }
  115. @Schema(description = "The distinguished name of the base to use for searching group.")
  116. public String getGroupsBaseDn( )
  117. {
  118. return groupsBaseDn;
  119. }
  120. public void setGroupsBaseDn( String groupsBaseDn )
  121. {
  122. this.groupsBaseDn = groupsBaseDn;
  123. }
  124. @Schema(description = "The authentication method used to bind to the LDAP server (PLAINTEXT, SASL, ...)")
  125. public String getAuthenticationMethod( )
  126. {
  127. return authenticationMethod;
  128. }
  129. public void setAuthenticationMethod( String authenticationMethod )
  130. {
  131. this.authenticationMethod = authenticationMethod;
  132. }
  133. @Schema(description = "True, if the LDAP bind authentication is used for logging in to Archiva")
  134. public boolean isBindAuthenticatorEnabled( )
  135. {
  136. return bindAuthenticatorEnabled;
  137. }
  138. public void setBindAuthenticatorEnabled( boolean bindAuthenticatorEnabled )
  139. {
  140. this.bindAuthenticatorEnabled = bindAuthenticatorEnabled;
  141. }
  142. @Schema(description = "True, if the archiva role name is also the LDAP group name")
  143. public boolean isUseRoleNameAsGroup( )
  144. {
  145. return useRoleNameAsGroup;
  146. }
  147. public void setUseRoleNameAsGroup( boolean useRoleNameAsGroup )
  148. {
  149. this.useRoleNameAsGroup = useRoleNameAsGroup;
  150. }
  151. @Schema(description = "Map of additional properties")
  152. public Map<String, String> getProperties( )
  153. {
  154. return properties;
  155. }
  156. public void setProperties( Map<String, String> properties )
  157. {
  158. this.properties.clear();
  159. this.properties.putAll( properties );
  160. }
  161. @Schema(description = "True, if attributes in the the LDAP server can be edited by Archiva")
  162. public boolean isWritable( )
  163. {
  164. return writable;
  165. }
  166. public void setWritable( boolean writable )
  167. {
  168. this.writable = writable;
  169. }
  170. @Override
  171. public boolean equals( Object o )
  172. {
  173. if ( this == o ) return true;
  174. if ( o == null || getClass( ) != o.getClass( ) ) return false;
  175. LdapConfiguration that = (LdapConfiguration) o;
  176. if ( port != that.port ) return false;
  177. if ( sslEnabled != that.sslEnabled ) return false;
  178. if ( bindAuthenticatorEnabled != that.bindAuthenticatorEnabled ) return false;
  179. if ( useRoleNameAsGroup != that.useRoleNameAsGroup ) return false;
  180. if ( writable != that.writable ) return false;
  181. if ( !Objects.equals( hostName, that.hostName ) ) return false;
  182. if ( !Objects.equals( baseDn, that.baseDn ) ) return false;
  183. if ( !Objects.equals( bindDn, that.bindDn ) ) return false;
  184. if ( !Objects.equals( groupsBaseDn, that.groupsBaseDn ) )
  185. return false;
  186. if ( !Objects.equals( bindPassword, that.bindPassword ) ) return false;
  187. if ( !Objects.equals( authenticationMethod, that.authenticationMethod ) )
  188. return false;
  189. return properties.equals( that.properties );
  190. }
  191. @Override
  192. public int hashCode( )
  193. {
  194. int result = hostName != null ? hostName.hashCode( ) : 0;
  195. result = 31 * result + port;
  196. result = 31 * result + ( sslEnabled ? 1 : 0 );
  197. result = 31 * result + ( baseDn != null ? baseDn.hashCode( ) : 0 );
  198. result = 31 * result + ( bindDn != null ? bindDn.hashCode( ) : 0 );
  199. result = 31 * result + ( groupsBaseDn != null ? groupsBaseDn.hashCode( ) : 0 );
  200. result = 31 * result + ( bindPassword != null ? bindPassword.hashCode( ) : 0 );
  201. result = 31 * result + ( authenticationMethod != null ? authenticationMethod.hashCode( ) : 0 );
  202. result = 31 * result + ( bindAuthenticatorEnabled ? 1 : 0 );
  203. result = 31 * result + ( useRoleNameAsGroup ? 1 : 0 );
  204. result = 31 * result + properties.hashCode( );
  205. result = 31 * result + ( writable ? 1 : 0 );
  206. return result;
  207. }
  208. @SuppressWarnings( "StringBufferReplaceableByString" )
  209. @Override
  210. public String toString( )
  211. {
  212. final StringBuilder sb = new StringBuilder( "LdapConfiguration{" );
  213. sb.append( "hostName='" ).append( hostName ).append( '\'' );
  214. sb.append( ", port=" ).append( port );
  215. sb.append( ", sslEnabled=" ).append( sslEnabled );
  216. sb.append( ", baseDn='" ).append( baseDn ).append( '\'' );
  217. sb.append( ", groupsBaseDn='" ).append( groupsBaseDn ).append( '\'' );
  218. sb.append( ", bindDn='" ).append( bindDn ).append( '\'' );
  219. sb.append( ", bindPassword='" ).append( bindPassword ).append( '\'' );
  220. sb.append( ", authenticationMethod='" ).append( authenticationMethod ).append( '\'' );
  221. sb.append( ", bindAuthenticatorEnabled=" ).append( bindAuthenticatorEnabled );
  222. sb.append( ", useRoleNameAsGroup=" ).append( useRoleNameAsGroup );
  223. sb.append( ", properties=" ).append( properties );
  224. sb.append( ", writable=" ).append( writable );
  225. sb.append( '}' );
  226. return sb.toString( );
  227. }
  228. }