user3488241
user3488241

Reputation: 1121

authentication-manager from xml to java. Spring security

How can I migrate the xml configuration below (spring security) to java configuration.

<!-- 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>

Thanks for your help.

Upvotes: 1

Views: 860

Answers (1)

rhinds
rhinds

Reputation: 10043

You should use the registerAuthentication() method, something like:

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

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

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

Upvotes: 1

Related Questions