diff --git a/config/src/integration-test/java/org/springframework/security/config/annotation/authentication/ldap/LdapAuthenticationProviderConfigurerTests.java b/config/src/integration-test/java/org/springframework/security/config/annotation/authentication/ldap/LdapAuthenticationProviderConfigurerTests.java index a2cdc44e88..a6a39dcffe 100644 --- a/config/src/integration-test/java/org/springframework/security/config/annotation/authentication/ldap/LdapAuthenticationProviderConfigurerTests.java +++ b/config/src/integration-test/java/org/springframework/security/config/annotation/authentication/ldap/LdapAuthenticationProviderConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.security.config.annotation.authentication.ldap; import org.junit.Rule; import org.junit.Test; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; @@ -61,6 +62,14 @@ public class LdapAuthenticationProviderConfigurerTests { .andExpect(authenticated().withUsername("bob").withAuthorities(singleton(new SimpleGrantedAuthority("ROL_DEVELOPERS")))); } + @Test + public void authenticationManagerWhenPortZeroThenAuthenticates() throws Exception { + this.spring.register(LdapWithRandomPortConfig.class).autowire(); + + this.mockMvc.perform(formLogin().user("bob").password("bobspassword")) + .andExpect(authenticated().withUsername("bob")); + } + @EnableWebSecurity static class MultiLdapAuthenticationProvidersConfig extends WebSecurityConfigurerAdapter { // @formatter:off @@ -98,4 +107,18 @@ public class LdapAuthenticationProviderConfigurerTests { } // @formatter:on } + + @EnableWebSecurity + static class LdapWithRandomPortConfig extends WebSecurityConfigurerAdapter { + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth + .ldapAuthentication() + .groupSearchBase("ou=groups") + .groupSearchFilter("(member={0})") + .userDnPatterns("uid={0},ou=people") + .contextSource() + .port(0); + } + } } diff --git a/config/src/integration-test/java/org/springframework/security/config/ldap/LdapProviderBeanDefinitionParserTests.java b/config/src/integration-test/java/org/springframework/security/config/ldap/LdapProviderBeanDefinitionParserTests.java index eefa4e2f77..f2a954fed1 100644 --- a/config/src/integration-test/java/org/springframework/security/config/ldap/LdapProviderBeanDefinitionParserTests.java +++ b/config/src/integration-test/java/org/springframework/security/config/ldap/LdapProviderBeanDefinitionParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,11 @@ package org.springframework.security.config.ldap; +import java.text.MessageFormat; + import org.junit.After; import org.junit.Test; + import org.springframework.context.ApplicationContextException; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationProvider; @@ -29,8 +32,6 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.ldap.userdetails.InetOrgPersonContextMapper; -import java.text.MessageFormat; - import static org.assertj.core.api.Assertions.assertThat; public class LdapProviderBeanDefinitionParserTests { @@ -46,7 +47,7 @@ public class LdapProviderBeanDefinitionParserTests { @Test public void simpleProviderAuthenticatesCorrectly() { - appCtx = new InMemoryXmlApplicationContext("" + appCtx = new InMemoryXmlApplicationContext("" + "" + " " + "" @@ -60,7 +61,7 @@ public class LdapProviderBeanDefinitionParserTests { @Test public void multipleProvidersAreSupported() { - appCtx = new InMemoryXmlApplicationContext("" + appCtx = new InMemoryXmlApplicationContext("" + "" + " " + " " @@ -84,7 +85,7 @@ public class LdapProviderBeanDefinitionParserTests { @Test public void supportsPasswordComparisonAuthentication() { - appCtx = new InMemoryXmlApplicationContext("" + appCtx = new InMemoryXmlApplicationContext("" + "" + " " + " " @@ -100,7 +101,7 @@ public class LdapProviderBeanDefinitionParserTests { @Test public void supportsPasswordComparisonAuthenticationWithPasswordEncoder() { - appCtx = new InMemoryXmlApplicationContext("" + appCtx = new InMemoryXmlApplicationContext("" + "" + " " + " " @@ -120,7 +121,7 @@ public class LdapProviderBeanDefinitionParserTests { // SEC-2472 @Test public void supportsCryptoPasswordEncoder() { - appCtx = new InMemoryXmlApplicationContext("" + appCtx = new InMemoryXmlApplicationContext("" + "" + " " + " " @@ -139,7 +140,7 @@ public class LdapProviderBeanDefinitionParserTests { @Test public void inetOrgContextMapperIsSupported() { - appCtx = new InMemoryXmlApplicationContext("" + appCtx = new InMemoryXmlApplicationContext("" + "" + " " + "" diff --git a/config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java b/config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java index 9b2c07cb17..564352400b 100644 --- a/config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java +++ b/config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,12 @@ */ package org.springframework.security.config.ldap; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.IOException; import java.net.ServerSocket; import org.junit.After; import org.junit.Test; + import org.springframework.ldap.core.LdapTemplate; import org.springframework.security.config.BeanIds; import org.springframework.security.config.util.InMemoryXmlApplicationContext; @@ -29,6 +28,8 @@ import org.springframework.security.ldap.DefaultSpringSecurityContextSource; import org.springframework.security.ldap.server.ApacheDSContainer; import org.springframework.test.util.ReflectionTestUtils; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luke Taylor * @author Rob Winch @@ -47,7 +48,7 @@ public class LdapServerBeanDefinitionParserTests { @Test public void embeddedServerCreationContainsExpectedContextSourceAndData() { appCtx = new InMemoryXmlApplicationContext( - ""); + ""); DefaultSpringSecurityContextSource contextSource = (DefaultSpringSecurityContextSource) appCtx .getBean(BeanIds.CONTEXT_SOURCE); @@ -82,7 +83,7 @@ public class LdapServerBeanDefinitionParserTests { @Test public void loadingSpecificLdifFileIsSuccessful() { appCtx = new InMemoryXmlApplicationContext( - ""); + ""); DefaultSpringSecurityContextSource contextSource = (DefaultSpringSecurityContextSource) appCtx .getBean(BeanIds.CONTEXT_SOURCE); diff --git a/config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java index 478076c7d3..a5a45106f9 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.net.ServerSocket; import org.springframework.ldap.core.support.BaseLdapPathContextSource; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationProvider; -import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.config.annotation.ObjectPostProcessor; import org.springframework.security.config.annotation.SecurityConfigurerAdapter; import org.springframework.security.config.annotation.authentication.ProviderManagerBuilder; @@ -29,6 +28,7 @@ import org.springframework.security.config.annotation.web.configurers.ChannelSec import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper; import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper; import org.springframework.security.crypto.password.NoOpPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.ldap.DefaultSpringSecurityContextSource; import org.springframework.security.ldap.authentication.AbstractLdapAuthenticator; import org.springframework.security.ldap.authentication.BindAuthenticator; @@ -478,6 +478,9 @@ public class LdapAuthenticationProviderConfigurer - + diff --git a/itest/ldap/embedded-ldap-mode-apacheds/src/integration-test/resources/applicationContext-security.xml b/itest/ldap/embedded-ldap-mode-apacheds/src/integration-test/resources/applicationContext-security.xml index f980c6ca98..8e3f4b4380 100644 --- a/itest/ldap/embedded-ldap-mode-apacheds/src/integration-test/resources/applicationContext-security.xml +++ b/itest/ldap/embedded-ldap-mode-apacheds/src/integration-test/resources/applicationContext-security.xml @@ -4,6 +4,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd"> - + diff --git a/itest/ldap/embedded-ldap-mode-unboundid/src/integration-test/resources/applicationContext-security.xml b/itest/ldap/embedded-ldap-mode-unboundid/src/integration-test/resources/applicationContext-security.xml index 6254829b43..9ab9bf623f 100644 --- a/itest/ldap/embedded-ldap-mode-unboundid/src/integration-test/resources/applicationContext-security.xml +++ b/itest/ldap/embedded-ldap-mode-unboundid/src/integration-test/resources/applicationContext-security.xml @@ -4,6 +4,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd"> - + diff --git a/itest/ldap/embedded-ldap-none/src/integration-test/resources/applicationContext-security.xml b/itest/ldap/embedded-ldap-none/src/integration-test/resources/applicationContext-security.xml index da547d0b04..b1b80079c5 100644 --- a/itest/ldap/embedded-ldap-none/src/integration-test/resources/applicationContext-security.xml +++ b/itest/ldap/embedded-ldap-none/src/integration-test/resources/applicationContext-security.xml @@ -4,6 +4,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd"> - + diff --git a/itest/ldap/embedded-ldap-unboundid-default/src/integration-test/resources/applicationContext-security.xml b/itest/ldap/embedded-ldap-unboundid-default/src/integration-test/resources/applicationContext-security.xml index da547d0b04..b1b80079c5 100644 --- a/itest/ldap/embedded-ldap-unboundid-default/src/integration-test/resources/applicationContext-security.xml +++ b/itest/ldap/embedded-ldap-unboundid-default/src/integration-test/resources/applicationContext-security.xml @@ -4,6 +4,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd"> - +