gpt4 book ai didi

spring - 如何在 Java Config 中注册 SaltSource(无 xml)

转载 作者:IT老高 更新时间:2023-10-28 13:49:07 26 4
gpt4 key购买 nike

我正在设置一个不使用 xml(没有 web.xml 和 spring.xml)的新 Web 应用程序。除了不知道如何注册 SaltSource 之外,我几乎可以完成所有工作。我需要将以下内容替换为 Java 等效项。

<authentication-manager>
<authentication-provider user-service-ref="authService" >
<password-encoder hash="sha" ref="myPasswordEncoder">
<salt-source user-property="salt"/>
</password-encoder>
</authentication-provider>
</authentication-manager>

到目前为止,我在 Java 中有这个。

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
ReflectionSaltSource rss = new ReflectionSaltSource();
rss.setUserPropertyToUse("salt");

auth.userDetailsService(authService).passwordEncoder(new MyPasswordEncoder());
// How do I set the saltSource down in DaoAuthenticationProvider
}

那么我如何注册 SaltSource 以便它在 DaoAuthenticationProvider 中结束(就像 xml 过去所做的那样)?

最佳答案

我通过以下方式开始工作:

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
ReflectionSaltSource rss = new ReflectionSaltSource();
rss.setUserPropertyToUse("salt");
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setSaltSource(rss);
provider.setUserDetailsService(authService);
provider.setPasswordEncoder(new MyPasswordEncoder());
auth.authenticationProvider(provider);
}

关于spring - 如何在 Java Config 中注册 SaltSource(无 xml),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22994851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com