I’m unable to use hasRole
method in @PreAuthorize
annotation. Also request.isUserInRole(“ADMIN”)
gives false
. What am I missing?
Although .hasAuthority(“ADMIN”)
works fine.
I am assigning authorities to the users from a database.
I’m unable to use hasRole
method in @PreAuthorize
annotation. Also request.isUserInRole(“ADMIN”)
gives false
. What am I missing?
Although .hasAuthority(“ADMIN”)
works fine.
I am assigning authorities to the users from a database.
You have to name your authority with prefix
ROLE_
to useisUserInRole
, see Spring Security Reference:Same for
hasRole
(alsohasAnyRole
), see Spring Security Reference: