Skip to content

Instantly share code, notes, and snippets.

@romartin
Created January 13, 2016 18:58
Show Gist options
  • Select an option

  • Save romartin/5cbf1a062c96061c6ea3 to your computer and use it in GitHub Desktop.

Select an option

Save romartin/5cbf1a062c96061c6ea3 to your computer and use it in GitHub Desktop.
// Check that roles registered in the framework are created as realm groups as well, if not they cannot be used, as it couldn't be assigned.
protected Set<Role> getRegisteredRoles() {
final Set<Role> result = new LinkedHashSet<Role>();
final Set<Role> registeredRoles = SecurityManagementUtils.getRegisteredRoles();
if ( null != registeredRoles && !registeredRoles.isEmpty() ) {
GroupManager groupManager = userSystemManager.groups();
for (final Role registeredRole : registeredRoles) {
try {
// If the groupManager does not found the role name, it will throw an exception,
// so the role will be not added into the resulting list.
groupManager.get(registeredRole.getName());
result.add(registeredRole);
} catch (GroupNotFoundException e) {
// Registered role not found as realm group.
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment