Spring Boot 2,如何在ProviderManager中设置eraseCredentialsAfterAuthentication false

Smi*_*ise 3 java spring-security spring-boot

我使用 spring boot 2 + Spring Security 5。我不想在身份验证后删除凭据,所以我想eraseCredentialsAfterAuthentication = falseProviderManger. 但我不知道如何在Spring Boot中配置它而不需要XML配置。

Smi*_*ise 8

好吧,我知道了。只需在WebSecurityConfigurerAdapter.

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.eraseCredentials(false);
    }

}
Run Code Online (Sandbox Code Playgroud)