How to convert spring security xml configuration to java configuration? -


i'm trying convert below xml java configuration, confused alias argument in sec:authentication-manager tag. have worked on partial part of java configuration , appreciate if can me rest of configuration.

xml configuration

<beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xmlns:sec="http://www.springframework.org/schema/security"         xsi:schemalocation="http://www.springframework.org/schema/beans                       http://www.springframework.org/schema/beans/spring-beans.xsd                       http://www.springframework.org/schema/security                       http://www.springframework.org/schema/security/spring-security.xsd">      <bean id="passwordencoder" class="org.springframework.security.crypto.password.standardpasswordencoder"/>      <sec:authentication-manager alias="userauthenticationmanager">         <sec:authentication-provider user-service-ref="userservice">             <sec:password-encoder ref="passwordencoder"/>         </sec:authentication-provider>     </sec:authentication-manager>      <sec:authentication-manager id="clientauthenticationmanager" xmlns="http://www.springframework.org/schema/security">         <sec:authentication-provider user-service-ref="client-details-user-service"/>     </sec:authentication-manager>       <bean id="client-details-user-service" class="org.springframework.security.oauth2.provider.client.clientdetailsuserdetailsservice">         <constructor-arg ref="client-details-service" />     </bean>  </beans> 

converted partial

@configuration @enablewebsecurity public class securityconfig extends websecurityconfigureradapter{      @autowired     private clientdetailsservice clientdetailsservice;      @autowired     private userrepository userrepository;      @autowired     private validator validator;      @autowired     private passwordencoder passwordencoder;      @override     protected authenticationmanager authenticationmanager() throws exception {         // todo auto-generated method stub         return super.authenticationmanager();     }     @override     protected void configure(authenticationmanagerbuilder auth)             throws exception {         auth.userdetailsservice(userdetailsservice());     }          @bean         public userdetailsservice userdetailsservice() {             return new userserviceimpl(userrepository, validator, passwordencoder);         }     } 

the alias tag identify specific authentication-manager. if doesn't need in java-config, can try following:

@autowired private standardpasswordencoder standardpasswordencoder;  @override public void init(authenticationmanagerbuilder auth) throws exception {     auth.userdetailsservice(principalservice).passwordencoder(standardpasswordencoder);     auth.authenticationprovider(preauthenticatedauthenticationprovider()); }  @autowired public void configureglobal(authenticationmanagerbuilder auth) throws exception {    auth.userdetailsservice(principalservice).passwordencoder(passwordencoder);    auth.authenticationprovider(preauthenticatedauthenticationprovider()); }  @bean public preauthenticatedauthenticationprovider preauthenticatedauthenticationprovider(){     preauthenticatedauthenticationprovider preauthenticatedauthenticationprovider = new preauthenticatedauthenticationprovider();     preauthenticatedauthenticationprovider.setpreauthenticateduserdetailsservice(preauthenticationuserdetailservice);     return preauthenticatedauthenticationprovider; } 

edit

if want multiply authentication manager check answer: https://stackoverflow.com/a/26308661/1809221


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -