SEC-2533: Global AuthenticationManagerBuilder disables clearing child credentials
This commit is contained in:
parent
cb0549a609
commit
c411014c24
|
@ -78,6 +78,9 @@ public class AuthenticationManagerBuilder extends AbstractConfiguredSecurityBuil
|
||||||
*/
|
*/
|
||||||
public AuthenticationManagerBuilder parentAuthenticationManager(
|
public AuthenticationManagerBuilder parentAuthenticationManager(
|
||||||
AuthenticationManager authenticationManager) {
|
AuthenticationManager authenticationManager) {
|
||||||
|
if(authenticationManager instanceof ProviderManager) {
|
||||||
|
eraseCredentials(((ProviderManager) authenticationManager).isEraseCredentialsAfterAuthentication());
|
||||||
|
}
|
||||||
this.parentAuthenticationManager = authenticationManager;
|
this.parentAuthenticationManager = authenticationManager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.security.config.annotation.authentication
|
package org.springframework.security.config.annotation.authentication
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.security.authentication.AuthenticationManager
|
import org.springframework.security.authentication.AuthenticationManager
|
||||||
|
@ -89,4 +90,25 @@ class NamespaceAuthenticationManagerTests extends BaseSpringSpec {
|
||||||
return super.authenticationManagerBean();
|
return super.authenticationManagerBean();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "SEC-2533: global authentication-manager@erase-credentials=false"() {
|
||||||
|
when:
|
||||||
|
loadConfig(GlobalEraseCredentialsFalseConfig)
|
||||||
|
Authentication auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("user","password"))
|
||||||
|
then:
|
||||||
|
auth.credentials == "password"
|
||||||
|
auth.principal.password == "password"
|
||||||
|
}
|
||||||
|
|
||||||
|
@EnableWebSecurity
|
||||||
|
@Configuration
|
||||||
|
static class GlobalEraseCredentialsFalseConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
@Autowired
|
||||||
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
|
auth
|
||||||
|
.eraseCredentials(false)
|
||||||
|
.inMemoryAuthentication()
|
||||||
|
.withUser("user").password("password").roles("USER")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue