Last active
August 29, 2015 14:03
-
-
Save john-evangelist/ade8794c7506dc4574d4 to your computer and use it in GitHub Desktop.
Static role imlementation of Spring Security role management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Collection<? extends GrantedAuthority> getAuthorities(Integer role) { | |
List<GrantedAuthority> authList = getGrantedAuthorities(getRoles(role)); | |
return authList; | |
} | |
public List<String> getRoles(Integer role) { | |
List<String> roles = new ArrayList<String>(); | |
if (role.intValue() == 1) { | |
roles.add("MODERATOR"); | |
roles.add("ADMIN"); | |
} else if (role.intValue() == 2) { | |
roles.add("MODERATOR"); | |
}else if (role.intValue()== 3 { | |
roles.add("USER"); | |
return roles; | |
} | |
public static List<GrantedAuthority> getGrantedAuthorities(List<String> roles) { | |
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); | |
for (String role : roles) { | |
authorities.add(new SimpleGrantedAuthority(role)); | |
} | |
return authorities; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment