Reputation: 824
How i can check if currently authenticated user has a specific role?
I found some older solution for older version of spring security, but in current version in spring it's not working, so I'm looking for a solution like this but in spring-boot-starter-security
version 1.5.2
.
Upvotes: 0
Views: 1279
Reputation: 2413
verify if authorities lenght is >0 :
Collection<SimpleGrantedAuthority> authorities = (Collection<SimpleGrantedAuthority>) SecurityContextHolder.getContext().getAuthentication().getAuthorities()
;
and after compare with your role if he has roles
Upvotes: 1