Hello All brother I am a new spring Thymleaf code please help me to solve this code
@Controller public class DefaultController {
@RequestMapping("/default")
public String defaultAfterLogin(HttpServletRequest request) {
if (request.isUserInRole("ROLE_ADMIN")) {
System.out.println("ROLE_ADMIN");
return "redirect:/";
}else if(request.isUserInRole("ROLE_USER")) {
System.out.println("ROLE_USER");
return "redirect:/user";
}else if(request.isUserInRole("ROLE_SH")) {
System.out.println("ROLE_SE");
return "redirect:/sectionHead";
}
return "redirect:/access-denied";
}
}
-------------------------This is my config------------------------------------------
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.csrf().disable();
http.headers().frameOptions().sameOrigin().and().authorizeRequests()
.antMatchers(("/user"),"/user/**").hasAnyRole("ADMIN","USER")
.antMatchers(("/sectionHead"),"/reqSectionHead/**").hasRole("SH")
.anyRequest().authenticated().and().formLogin()
.defaultSuccessUrl("/default")
.loginProcessingUrl("/sso/login")
.and()
.exceptionHandling().accessDeniedHandler(accessDeniedHandler())
.and().logout()
.invalidateHttpSession(true).clearAuthentication(true)
.logoutRequestMatcher(new AntPathRequestMatcher("/sso/logout")).logoutSuccessUrl("/sso/login").permitAll();
}