spring security redirect user by ROLE -


i want redirect user page based on role don't know how it. serched on doesn't work me. it's taking redirect role_master if user has role_user or other. tried in different ways can see in commented code none of them worked correctly.

the code is:

    @configuration     @enablewebsecurity     public class springsecurityconfig extends websecurityconfigureradapter {      @autowired     usersdetailsserviceimpl usersdetailsservice;      @autowired     public void configureglobal(authenticationmanagerbuilder auth) throws exception {         auth.inmemoryauthentication().withuser("stefan").password("1234").roles("admin");         auth.userdetailsservice(usersdetailsservice);     }      @override     public void configure(websecurity web) throws exception {         web.ignoring().antmatchers("/res/**");     }      //.csrf() optional, enabled default, if using websecurityconfigureradapter constructor     @override     protected void configure(httpsecurity http) throws exception {          http    .authorizerequests()                 .antmatchers("/master/**").access("hasrole('role_master')")                 .antmatchers("/admin/**").access("hasrole('role_admin')")                 .antmatchers("/user/**").access("hasrole('role_user')")                 .antmatchers("/viewer/**").access("hasrole('role_viewer')")                 .and()                 .formlogin().loginpage("/").failureurl("/?error")                 .usernameparameter("username").passwordparameter("password").defaultsuccessurl("/master")                 .and()                 .logout().logouturl("/logout").logoutsuccessurl("/?logout")                 .and()                 .csrf();  //                .and() //                .authorizerequests() //                .antmatchers("/admin/**").access("hasrole('role_admin')") //                .and() //                .formlogin().loginpage("/").failureurl("/?error") //                .usernameparameter("username").passwordparameter("password").defaultsuccessurl("/admin") //                .and() //                .logout().logouturl("/logout").logoutsuccessurl("/?logout") //                .and() //                .csrf() // //                .and() //                .authorizerequests() //                .antmatchers("/user/**").access("hasrole('role_user')") //                .and() //                .formlogin().loginpage("/").failureurl("/?error") //                .usernameparameter("username").passwordparameter("password").defaultsuccessurl("/user") //                .and() //                .logout().logouturl("/logout").logoutsuccessurl("/?logout") //                .and() //                .csrf() // //                .and() //                .authorizerequests() //                .antmatchers("/viewer/**").access("hasrole('role_viewer')") //                .and() //                .formlogin().loginpage("/").failureurl("/?error") //                .usernameparameter("username").passwordparameter("password").defaultsuccessurl("/viewer") //                .and() //                .logout().logouturl("/logout").logoutsuccessurl("/?logout") //                .and() //                .csrf();   //        http.authorizerequests() //                .antmatchers("/admin/**").access("hasrole('role_admin')") //                .and() //                .formlogin().loginpage("/").failureurl("/?error") //                .usernameparameter("username").passwordparameter("password").defaultsuccessurl("/admin") //                .and() //                .logout().logouturl("/logout").logoutsuccessurl("/?logout") //                .and() //                .csrf();  //        http.authorizerequests() //                .antmatchers("/user/**").access("hasrole('role_user')") //                .and() //                .formlogin().loginpage("/").failureurl("/?error") //                .usernameparameter("username").passwordparameter("password").defaultsuccessurl("/user") //                .and() //                .logout().logouturl("/logout").logoutsuccessurl("/?logout") //                .and() //                .csrf();  //        http.authorizerequests() //                .antmatchers("/viewer/**").access("hasrole('role_viewer')") //                .and() //                .formlogin().loginpage("/").failureurl("/?error") //                .usernameparameter("username").passwordparameter("password").defaultsuccessurl("/viewer") //                .and() //                .logout().logouturl("/logout").logoutsuccessurl("/?logout") //                .and() //                .csrf();         //  http.formlogin().loginpage("/admin/login").failureurl("/admin/login?error").defaultsuccessurl("/main",true).usernameparameter("username").passwordparameter("password");      }  } 

any ideea how can ?

implement own authenticationsuccesshandler check user role authentication object , send redirect suitable url

<bean id="authenticationsuccesshandler" class="..." /> <form-login authentication-success-handler-ref="authenticationsuccesshandler" ... /> 

full example roles


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -