I have a situation where i need to pass the path variable as a argument to the preauthorize
@RequestMapping(value="/page/{cmd}", method = RequestMethod.GET)
@PreAuthorize("hasRole(#cmd)")
public void method(@PathVariable String cmd, HttpServletRequest request, HttpServletResponse response){
// my stuff
}
It is not working.can anyone suggest me how to use the path variable in pre authorize please.
Spring Security's
@PreAuthorizeis used for authorizing access to methods. It doesn't know really much about Spring MVC, in particular about its@RequestMappingannotation.Names like
#cmdwill refer to method parameters, and yourcmdparameter is null. Change it to:This way,
cmdpath variable will be bound tocmdmethod parameter, which will then be bound by#cmdin@PreAuthorize.