作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在设置一个不使用 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/
我是一名优秀的程序员,十分优秀!