如何在 Java Config 中注册 SaltSource(无 xml) [英] How to Register SaltSource in Java Config (no xml)
本文介绍了如何在 Java Config 中注册 SaltSource(无 xml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在设置一个不使用 xml(没有 web.xml 和 spring.xml)的新 Web 应用程序.除了我不知道如何注册 SaltSource 之外,我几乎可以完成所有工作.我需要用 Java 等效项替换以下内容.
I am setting up a new web app that uses no xml (no web.xml and no spring.xml). I have almost everything work except I can't figure out how to register the SaltSource. I need to replace the following with the Java equivalent.
<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 中有这个.
So far I have this in 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 所做的那样)?
So how do I register the SaltSource so that it ends up in DaoAuthenticationProvider (like the xml has done in the past)?
推荐答案
我开始做以下工作:
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);
}
这篇关于如何在 Java Config 中注册 SaltSource(无 xml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文