Skip to content

Commit c411014

Browse files
author
Rob Winch
committed
SEC-2533: Global AuthenticationManagerBuilder disables clearing child credentials
1 parent cb0549a commit c411014

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

config/src/main/java/org/springframework/security/config/annotation/authentication/builders/AuthenticationManagerBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public AuthenticationManagerBuilder(ObjectPostProcessor<Object> objectPostProces
7878
*/
7979
public AuthenticationManagerBuilder parentAuthenticationManager(
8080
AuthenticationManager authenticationManager) {
81+
if(authenticationManager instanceof ProviderManager) {
82+
eraseCredentials(((ProviderManager) authenticationManager).isEraseCredentialsAfterAuthentication());
83+
}
8184
this.parentAuthenticationManager = authenticationManager;
8285
return this;
8386
}

config/src/test/groovy/org/springframework/security/config/annotation/authentication/NamespaceAuthenticationManagerTests.groovy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.security.config.annotation.authentication
1717

18+
import org.springframework.beans.factory.annotation.Autowired
1819
import org.springframework.context.annotation.Bean
1920
import org.springframework.context.annotation.Configuration
2021
import org.springframework.security.authentication.AuthenticationManager
@@ -89,4 +90,25 @@ class NamespaceAuthenticationManagerTests extends BaseSpringSpec {
8990
return super.authenticationManagerBean();
9091
}
9192
}
93+
94+
def "SEC-2533: global authentication-manager@erase-credentials=false"() {
95+
when:
96+
loadConfig(GlobalEraseCredentialsFalseConfig)
97+
Authentication auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("user","password"))
98+
then:
99+
auth.credentials == "password"
100+
auth.principal.password == "password"
101+
}
102+
103+
@EnableWebSecurity
104+
@Configuration
105+
static class GlobalEraseCredentialsFalseConfig extends WebSecurityConfigurerAdapter {
106+
@Autowired
107+
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
108+
auth
109+
.eraseCredentials(false)
110+
.inMemoryAuthentication()
111+
.withUser("user").password("password").roles("USER")
112+
}
113+
}
92114
}

0 commit comments

Comments
 (0)