Answers for "get role assigned to a user inside spring controller"

0

get role assigned to a user inside spring controller

private boolean hasRole(String role) {
  Collection<GrantedAuthority> authorities = (Collection<GrantedAuthority>)
  SecurityContextHolder.getContext().getAuthentication().getAuthorities();
  boolean hasRole = false;
  for (GrantedAuthority authority : authorities) {
     hasRole = authority.getAuthority().equals(role);
     if (hasRole) {
      break;
     }
  }
  return hasRole;
}
Posted by: Guest on May-11-2021

Code answers related to "get role assigned to a user inside spring controller"

Browse Popular Code Answers by Language