如何在Java Config中注册SaltSource(无xml) [英] How to Register SaltSource in Java Config (no xml)

查看:89
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆