Skip to content

Commit 6ddb964

Browse files
committed
Remove ApacheDS Support
Closes gh-13852
1 parent 42e24aa commit 6ddb964

File tree

49 files changed

+132
-1400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+132
-1400
lines changed

config/spring-security-config.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ dependencies {
7878
exclude group: 'commons-logging', module: 'commons-logging'
7979
exclude group: 'xml-apis', module: 'xml-apis'
8080
}
81-
testImplementation "org.apache.directory.server:apacheds-core"
82-
testImplementation "org.apache.directory.server:apacheds-core-entry"
83-
testImplementation "org.apache.directory.server:apacheds-protocol-shared"
84-
testImplementation "org.apache.directory.server:apacheds-protocol-ldap"
85-
testImplementation "org.apache.directory.server:apacheds-server-jndi"
86-
testImplementation 'org.apache.directory.shared:shared-ldap'
8781
testImplementation "com.unboundid:unboundid-ldapsdk"
8882
testImplementation 'jakarta.persistence:jakarta.persistence-api'
8983
testImplementation "org.hibernate.orm:hibernate-core"

config/src/integration-test/java/org/springframework/security/config/annotation/authentication/ldap/LdapAuthenticationProviderBuilderSecurityBuilderTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
4545
import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
4646
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider;
47-
import org.springframework.security.ldap.server.ApacheDSContainer;
47+
import org.springframework.security.ldap.server.UnboundIdContainer;
4848
import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator;
4949
import org.springframework.test.util.ReflectionTestUtils;
5050
import org.springframework.test.web.servlet.MockMvc;
@@ -326,11 +326,11 @@ AuthenticationManager authenticationManager(AuthenticationConfiguration authenti
326326
abstract static class BaseLdapServerConfig extends BaseLdapProviderConfig {
327327

328328
@Bean
329-
ApacheDSContainer ldapServer() throws Exception {
330-
ApacheDSContainer apacheDSContainer = new ApacheDSContainer("dc=springframework,dc=org",
329+
UnboundIdContainer ldapServer() throws Exception {
330+
UnboundIdContainer unboundIdContainer = new UnboundIdContainer("dc=springframework,dc=org",
331331
"classpath:/test-server.ldif");
332-
apacheDSContainer.setPort(getPort());
333-
return apacheDSContainer;
332+
unboundIdContainer.setPort(getPort());
333+
return unboundIdContainer;
334334
}
335335

336336
}

config/src/integration-test/java/org/springframework/security/config/ldap/LdapBindAuthenticationManagerFactoryITests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.springframework.security.core.userdetails.User;
4444
import org.springframework.security.core.userdetails.UserDetails;
4545
import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
46-
import org.springframework.security.ldap.server.ApacheDSContainer;
46+
import org.springframework.security.ldap.server.UnboundIdContainer;
4747
import org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator;
4848
import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator;
4949
import org.springframework.security.ldap.userdetails.UserDetailsContextMapper;
@@ -226,18 +226,18 @@ AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSou
226226
@EnableWebSecurity
227227
abstract static class BaseLdapServerConfig implements DisposableBean {
228228

229-
private ApacheDSContainer container;
229+
private UnboundIdContainer container;
230230

231231
@Bean
232-
ApacheDSContainer ldapServer() throws Exception {
233-
this.container = new ApacheDSContainer("dc=springframework,dc=org", "classpath:/test-server.ldif");
232+
UnboundIdContainer ldapServer() {
233+
this.container = new UnboundIdContainer("dc=springframework,dc=org", "classpath:/test-server.ldif");
234234
this.container.setPort(0);
235235
return this.container;
236236
}
237237

238238
@Bean
239-
BaseLdapPathContextSource contextSource(ApacheDSContainer container) {
240-
int port = container.getLocalPort();
239+
BaseLdapPathContextSource contextSource(UnboundIdContainer container) {
240+
int port = container.getPort();
241241
return new DefaultSpringSecurityContextSource("ldap://localhost:" + port + "/dc=springframework,dc=org");
242242
}
243243

config/src/integration-test/java/org/springframework/security/config/ldap/LdapPasswordComparisonAuthenticationManagerFactoryITests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
3232
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
3333
import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
34-
import org.springframework.security.ldap.server.ApacheDSContainer;
34+
import org.springframework.security.ldap.server.UnboundIdContainer;
3535
import org.springframework.test.web.servlet.MockMvc;
3636

3737
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin;
@@ -93,18 +93,18 @@ AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSou
9393
@EnableWebSecurity
9494
abstract static class BaseLdapServerConfig implements DisposableBean {
9595

96-
private ApacheDSContainer container;
96+
private UnboundIdContainer container;
9797

9898
@Bean
99-
ApacheDSContainer ldapServer() throws Exception {
100-
this.container = new ApacheDSContainer("dc=springframework,dc=org", "classpath:/test-server.ldif");
99+
UnboundIdContainer ldapServer() {
100+
this.container = new UnboundIdContainer("dc=springframework,dc=org", "classpath:/test-server.ldif");
101101
this.container.setPort(0);
102102
return this.container;
103103
}
104104

105105
@Bean
106-
BaseLdapPathContextSource contextSource(ApacheDSContainer container) {
107-
int port = container.getLocalPort();
106+
BaseLdapPathContextSource contextSource(UnboundIdContainer container) {
107+
int port = container.getPort();
108108
return new DefaultSpringSecurityContextSource("ldap://localhost:" + port + "/dc=springframework,dc=org");
109109
}
110110

config/src/integration-test/java/org/springframework/security/config/ldap/LdapProviderBeanDefinitionParserTests.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void simpleProviderAuthenticatesCorrectly() {
5656
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER,
5757
AuthenticationManager.class);
5858
Authentication auth = authenticationManager
59-
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("ben", "benspassword"));
59+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("otherben", "otherbenspassword"));
6060
UserDetails ben = (UserDetails) auth.getPrincipal();
6161
assertThat(ben.getAuthorities()).hasSize(3);
6262
}
@@ -127,6 +127,27 @@ public void supportsCryptoPasswordEncoder() {
127127
assertThat(auth).isNotNull();
128128
}
129129

130+
@Test
131+
public void supportsShaPasswordEncoder() {
132+
this.appCtx = new InMemoryXmlApplicationContext("""
133+
<ldap-server ldif='classpath:test-server.ldif' port='0'/>
134+
<authentication-manager>
135+
<ldap-authentication-provider user-dn-pattern='uid={0},ou=people'>
136+
<password-compare>
137+
<password-encoder ref='pe' />
138+
</password-compare>
139+
</ldap-authentication-provider>
140+
</authentication-manager>
141+
<b:bean id='pe' class='org.springframework.security.crypto.password.LdapShaPasswordEncoder' />
142+
""");
143+
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER,
144+
AuthenticationManager.class);
145+
Authentication auth = authenticationManager
146+
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("ben", "benspassword"));
147+
148+
assertThat(auth).isNotNull();
149+
}
150+
130151
@Test
131152
public void inetOrgContextMapperIsSupported() {
132153
this.appCtx = new InMemoryXmlApplicationContext(

config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.security.config.BeanIds;
2727
import org.springframework.security.config.util.InMemoryXmlApplicationContext;
2828
import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
29-
import org.springframework.security.ldap.server.ApacheDSContainer;
29+
import org.springframework.security.ldap.server.UnboundIdContainer;
3030
import org.springframework.test.util.ReflectionTestUtils;
3131

3232
import static org.assertj.core.api.Assertions.assertThat;
@@ -92,9 +92,9 @@ public void loadingSpecificLdifFileIsSuccessful() {
9292
@Test
9393
public void defaultLdifFileIsSuccessful() {
9494
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server/>");
95-
ApacheDSContainer dsContainer = this.appCtx.getBean(ApacheDSContainer.class);
95+
UnboundIdContainer dsContainer = this.appCtx.getBean(UnboundIdContainer.class);
9696

97-
assertThat(ReflectionTestUtils.getField(dsContainer, "ldifResources")).isEqualTo("classpath*:*.ldif");
97+
assertThat(ReflectionTestUtils.getField(dsContainer, "ldif")).isEqualTo("classpath*:*.ldif");
9898
}
9999

100100
private int getDefaultPort() throws IOException {

config/src/integration-test/resources/logback-test.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
<logger name="org.springframework.security" level="${sec.log.level:-WARN}"/>
99

10-
<logger name="org.apache.directory" level="ERROR"/>
1110
<logger name="JdbmTable" level="INFO"/>
1211
<logger name="JdbmIndex" level="INFO"/>
1312
<logger name="org.apache.mina" level="WARN"/>

config/src/main/java/org/springframework/security/config/BeanIds.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public abstract class BeanIds {
5454

5555
public static final String METHOD_SECURITY_METADATA_SOURCE_ADVISOR = PREFIX + "methodSecurityMetadataSourceAdvisor";
5656

57-
public static final String EMBEDDED_APACHE_DS = PREFIX + "apacheDirectoryServerContainer";
58-
5957
public static final String EMBEDDED_UNBOUNDID = PREFIX + "unboundidServerContainer";
6058

6159
public static final String CONTEXT_SOURCE = PREFIX + "securityContextSource";

config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.springframework.security.ldap.authentication.PasswordComparisonAuthenticator;
3838
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch;
3939
import org.springframework.security.ldap.search.LdapUserSearch;
40-
import org.springframework.security.ldap.server.ApacheDSContainer;
4140
import org.springframework.security.ldap.server.UnboundIdContainer;
4241
import org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator;
4342
import org.springframework.security.ldap.userdetails.InetOrgPersonContextMapper;
@@ -60,12 +59,8 @@
6059
public class LdapAuthenticationProviderConfigurer<B extends ProviderManagerBuilder<B>>
6160
extends SecurityConfigurerAdapter<AuthenticationManager, B> {
6261

63-
private static final String APACHEDS_CLASSNAME = "org.apache.directory.server.core.DefaultDirectoryService";
64-
6562
private static final String UNBOUNDID_CLASSNAME = "com.unboundid.ldap.listener.InMemoryDirectoryServer";
6663

67-
private static final boolean apacheDsPresent;
68-
6964
private static final boolean unboundIdPresent;
7065

7166
private String groupRoleAttribute = "cn";
@@ -100,7 +95,6 @@ public class LdapAuthenticationProviderConfigurer<B extends ProviderManagerBuild
10095

10196
static {
10297
ClassLoader classLoader = LdapAuthenticationProviderConfigurer.class.getClassLoader();
103-
apacheDsPresent = ClassUtils.isPresent(APACHEDS_CLASSNAME, classLoader);
10498
unboundIdPresent = ClassUtils.isPresent(UNBOUNDID_CLASSNAME, classLoader);
10599
}
106100

@@ -467,8 +461,6 @@ private PasswordCompareConfigurer() {
467461
*/
468462
public final class ContextSourceBuilder {
469463

470-
private static final String APACHEDS_CLASSNAME = "org.apache.directory.server.core.DefaultDirectoryService";
471-
472464
private static final String UNBOUNDID_CLASSNAME = "com.unboundid.ldap.listener.InMemoryDirectoryServer";
473465

474466
private static final int DEFAULT_PORT = 33389;
@@ -584,14 +576,8 @@ private DefaultSpringSecurityContextSource build() throws Exception {
584576
return contextSource;
585577
}
586578

587-
private void startEmbeddedLdapServer() throws Exception {
588-
if (apacheDsPresent) {
589-
ApacheDSContainer apacheDsContainer = new ApacheDSContainer(this.root, this.ldif);
590-
apacheDsContainer.setPort(getPort());
591-
postProcess(apacheDsContainer);
592-
this.port = apacheDsContainer.getLocalPort();
593-
}
594-
else if (unboundIdPresent) {
579+
private void startEmbeddedLdapServer() {
580+
if (unboundIdPresent) {
595581
UnboundIdContainer unboundIdContainer = new UnboundIdContainer(this.root, this.ldif);
596582
unboundIdContainer.setPort(getPort());
597583
postProcess(unboundIdContainer);

config/src/main/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParser.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.springframework.context.ApplicationContextAware;
3333
import org.springframework.security.config.BeanIds;
3434
import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
35-
import org.springframework.security.ldap.server.ApacheDSContainer;
3635
import org.springframework.security.ldap.server.UnboundIdContainer;
3736
import org.springframework.util.ClassUtils;
3837
import org.springframework.util.StringUtils;
@@ -47,7 +46,7 @@ public class LdapServerBeanDefinitionParser implements BeanDefinitionParser {
4746
private static final String CONTEXT_SOURCE_CLASS = "org.springframework.security.ldap.DefaultSpringSecurityContextSource";
4847

4948
/**
50-
* Defines the Url of the ldap server to use. If not specified, an embedded apache DS
49+
* Defines the Url of the ldap server to use. If not specified, an embedded UnboundID
5150
* instance will be created
5251
*/
5352
private static final String ATT_URL = "url";
@@ -78,22 +77,15 @@ public class LdapServerBeanDefinitionParser implements BeanDefinitionParser {
7877

7978
private static final int DEFAULT_PORT = 33389;
8079

81-
private static final String APACHEDS_CLASSNAME = "org.apache.directory.server.core.DefaultDirectoryService";
82-
8380
private static final String UNBOUNID_CLASSNAME = "com.unboundid.ldap.listener.InMemoryDirectoryServer";
8481

85-
private static final String APACHEDS_CONTAINER_CLASSNAME = "org.springframework.security.ldap.server.ApacheDSContainer";
86-
8782
private static final String UNBOUNDID_CONTAINER_CLASSNAME = "org.springframework.security.ldap.server.UnboundIdContainer";
8883

8984
private static final boolean unboundIdPresent;
9085

91-
private static final boolean apacheDsPresent;
92-
9386
static {
9487
ClassLoader classLoader = LdapServerBeanDefinitionParser.class.getClassLoader();
9588
unboundIdPresent = ClassUtils.isPresent(UNBOUNID_CLASSNAME, classLoader);
96-
apacheDsPresent = ClassUtils.isPresent(APACHEDS_CLASSNAME, classLoader);
9789
}
9890

9991
@Override
@@ -128,10 +120,9 @@ public BeanDefinition parse(Element elt, ParserContext parserContext) {
128120
/**
129121
* Will be called if no url attribute is supplied.
130122
*
131-
* Registers beans to create an embedded apache directory server.
123+
* Registers beans to create an embedded UnboundID Server.
132124
* @return the BeanDefinition for the ContextSource for the embedded server.
133125
*
134-
* @see ApacheDSContainer
135126
* @see UnboundIdContainer
136127
*/
137128
private RootBeanDefinition createEmbeddedServer(Element element, ParserContext parserContext) {
@@ -162,8 +153,7 @@ private RootBeanDefinition createEmbeddedServer(Element element, ParserContext p
162153
}
163154
ldapContainer.getConstructorArgumentValues().addGenericArgumentValue(ldifs);
164155
ldapContainer.getPropertyValues().addPropertyValue("port", getPort(element));
165-
if (parserContext.getRegistry().containsBeanDefinition(BeanIds.EMBEDDED_APACHE_DS)
166-
|| parserContext.getRegistry().containsBeanDefinition(BeanIds.EMBEDDED_UNBOUNDID)) {
156+
if (parserContext.getRegistry().containsBeanDefinition(BeanIds.EMBEDDED_UNBOUNDID)) {
167157
parserContext.getReaderContext()
168158
.error("Only one embedded server bean is allowed per application context", element);
169159
}
@@ -175,29 +165,19 @@ private RootBeanDefinition createEmbeddedServer(Element element, ParserContext p
175165
}
176166

177167
private RootBeanDefinition getRootBeanDefinition(String mode) {
178-
if (isApacheDsEnabled(mode)) {
179-
return new RootBeanDefinition(APACHEDS_CONTAINER_CLASSNAME, null, null);
180-
}
181168
if (isUnboundidEnabled(mode)) {
182169
return new RootBeanDefinition(UNBOUNDID_CONTAINER_CLASSNAME, null, null);
183170
}
184171
throw new IllegalStateException("Embedded LDAP server is not provided");
185172
}
186173

187174
private String resolveBeanId(String mode) {
188-
if (isApacheDsEnabled(mode)) {
189-
return BeanIds.EMBEDDED_APACHE_DS;
190-
}
191175
if (isUnboundidEnabled(mode)) {
192176
return BeanIds.EMBEDDED_UNBOUNDID;
193177
}
194178
return null;
195179
}
196180

197-
private boolean isApacheDsEnabled(String mode) {
198-
return "apacheds".equals(mode) || apacheDsPresent;
199-
}
200-
201181
private boolean isUnboundidEnabled(String mode) {
202182
return "unboundid".equals(mode) || unboundIdPresent;
203183
}
@@ -233,10 +213,6 @@ private DefaultSpringSecurityContextSource createEmbeddedContextSource(String su
233213
}
234214

235215
private int getPort() {
236-
if (apacheDsPresent) {
237-
ApacheDSContainer apacheDSContainer = this.applicationContext.getBean(ApacheDSContainer.class);
238-
return apacheDSContainer.getLocalPort();
239-
}
240216
if (unboundIdPresent) {
241217
UnboundIdContainer unboundIdContainer = this.applicationContext.getBean(UnboundIdContainer.class);
242218
return unboundIdContainer.getPort();

0 commit comments

Comments
 (0)