Spring 如何在Java配置中注册SaltSource(无xml)

Spring 如何在Java配置中注册SaltSource(无xml),spring,spring-security,Spring,Spring Security,我正在设置一个不使用xml(不使用web.xml和spring.xml)的新web应用程序。除了我不知道如何注册SaltSource之外,我几乎所有的工作都在进行中。我需要用Java等价物替换以下内容 <authentication-manager> <authentication-provider user-service-ref="authService" > <password-encoder hash="sha" ref="myPasswordEn

我正在设置一个不使用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>

那么,如何注册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);
}

我通过以下操作实现了它:受保护的void配置(AuthenticationManagerBuilder auth)抛出异常{ReflectionSaltSource rss=new ReflectionSaltSource();rss.setUserPropertyToUse(“salt”);DAOAAuthenticationProvider provider=new DAOAAuthenticationProvider();provider.SetAltSource(rss);provider.setUserDetailsService(authService);provider.setPasswordEncoder(new MyPasswordEncoder());auth.authenticationProvider(provider);}如果您有自定义Spring安全性的消息,请不要忘记调用
provider.setMessageSource()
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);
}