从xml到java的authentication-manager。春天的安全

时间:2014-04-10 21:32:22

标签: java spring spring-security

如何将下面的xml配置(spring security)迁移到java配置。

<!-- Configure Authentication mechanism -->
<authentication-manager alias="authenticationManager">
    <!-- SHA-256 values can be produced using 'echo n your_desired_password | sha256sum' (using normal *nix environments) -->
    <authentication-provider user-service-ref="securityUserService" >
        <password-encoder hash="sha-256"/>
    </authentication-provider>    
</authentication-manager>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您应该使用registerAuthentication()方法,例如:

 @Override
 protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
     auth
        .userDetailsService(userDetailsServiceImpl)
        .passwordEncoder(passwordEncoder());
 }

@Bean public ShaPasswordEncoder passwordEncoder() throws Exception {  
    return new ShaPasswordEncoder(256);  
}  

来源:http://automateddeveloper.blogspot.co.uk/2014/02/spring-4-xml-to-annotation-configuration.html