Syngularity
Syngularity

Reputation: 824

Spring security web check if currently authenticated user has role

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

Answers (1)

Azzabi Haythem
Azzabi Haythem

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

Related Questions