上代码:
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(Locale locale, Model model, SecurityContextHolderAwareRequestWrapper request) {
if( request.isUserInRole("ROLE_USER") || request.isUserInRole("ROLE_ADMIN"))
{
return new ModelAndView(new RedirectView(""));
}
return new ModelAndView("login");
}
参考:
http://stackoverflow.com/questions/3021200/how-to-check-hasrole-in-java-code-with-spring-security
有很多解决方法,我选了最后一种,比较简明,目前使用看没问题。