Skip to content

Instantly share code, notes, and snippets.

@john-evangelist
Last active August 29, 2015 14:03
Show Gist options
  • Save john-evangelist/ade8794c7506dc4574d4 to your computer and use it in GitHub Desktop.
Save john-evangelist/ade8794c7506dc4574d4 to your computer and use it in GitHub Desktop.
Static role imlementation of Spring Security role management
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