Spring Security hasRole() not working
You are missing a concept:
- If you use
hasRole('ADMIN')
, in yourADMIN Enum
must beROLE_ADMIN
instead ofADMIN
. - If you use
hasAuthority('ADMIN')
, yourADMIN Enum
must beADMIN
.
In spring security, hasRole()
is the same as hasAuthority()
, but hasRole()
function map with Authority
without ROLE_
prefix.
You can find the accepted answer in this post: Difference between Role and GrantedAuthority in Spring Security
Try use hasAuthority
instead hasRole
inside HTML-tag.
sec:authorize="hasAuthority('ADMIN')"