Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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;
}  
Comment

PREVIOUS NEXT
Code Example
Java :: how to convert errorBody to pojo in retrofit 
Java :: Fix arabic javafx 
Java :: call function after specific time java android 
Java :: java continue keyword 
Java :: jdbc dependency 
Java :: Using multiple delimiters with String Tokenizer 
Java :: change text size java 
Java :: how to get orientation lock to portrait android stackoverflow 
Java :: how to change resource color to int color in android 
Java :: array reverse in java 
Java :: What is the function of an IntentFilter? 
Java :: overload and override in java 
Java :: how to use enumUtils in java 
Java :: linked list vs vector 
Java :: setimageuri crash 
Java :: springbootservletinitializer maven dependency 
Java :: model mapper to list stream 
Java :: object type in java 
Java :: Explain JDK, JRE and JVM? 
Java :: array.swap java 
Java :: remove selected text from string value android java 
Java :: enable cors on apache tomcat 
Java :: java noverify 
Java :: transparent border of jtextfield in java 
Java :: what is object in java 
Java :: difference between synchronized block and synchronized method example 
Java :: android studio space 
Java :: 1 elemenet array java 
Java :: linear serach in java 
Java :: call by value and call by reference in java 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =