samedi 7 mars 2015

AuthenticationSuccessHandler in spring mvc java based configuration

I have three roles, and i want to redirect user to different pages after login according to their roles. I know this can be done by AuthenticationSuccessHandler, but i am having trouble in declaring it in java based configuration. So far i have done this.



protected void configure(HttpSecurity http) throws Exception {

http
.authorizeRequests()
.antMatchers("/resources/**", "/login").permitAll()
.antMatchers("/admin/**").hasRole("USER")
.and()

.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/")
.successHandler(successHandler) //----- to handle user role
.failureUrl("/loginfailed")
.permitAll()
.and()

.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.deleteCookies("JSESSIONID")
.invalidateHttpSession( true )
.and();
}


My question is where to declare successHandler and how to autowire it in this class, or how to declare successHandler method in this class and use it.


Aucun commentaire:

Enregistrer un commentaire