我正在使用@preauthorize来提高方法级安全性。对于我的method1,两个角色中的一个只能满足。但是在这个方法中,我需要知道它在这个时候遇到了哪个角色,并且基于我需要为功能需求设置后续行程。我的问题如下 -
@PreAuthorize("hasAnyRole('Role_1') or hasAnyRole('Role_2')")
@RequestMapping(value = URL_MAPPING, method = {RequestMethod.GET, RequestMethod.POST })
public ModelAndView methodName(HttpSession session,
ModelAndView modelAndView) {
//here i need to know which role it has passed to execute the method.
if (role1 executed) {
sessionInformation.updateJourneyInfo(updateforrole1);
}else{
sessionInformation.updateJourneyInfo(updateforrole2);
}
任何人都可以帮忙解决这个问题。谢谢。
答案 0 :(得分:0)
将HttpServletRequest
请求添加到方法的参数列表中,然后使用
request.isInRole("ROLE_Role_1")