The service that encapsulates authorities granted to users. This service will refuse to create any user authorities. These should be managed using the AuthenticationService and PersonService. Methods that try to change alter users will throw an exception. A string key is used to identify the authority. These follow the contract defined in AuthorityType. If there are entities linked to these authorities this key should be used to find them, as userName is used to link user and person.
Authority is a general term to describe a group, user, or role. The AuthorityService provides an API to:
- Add and delete authorities.
- Get authorities.
- Retrieve authority details such as short name.
/** * Search the root groups, those without a parent group. * * @param paging Paging object with max number to return, and items to skip * @param sortBy What to sort on (authorityName, shortName or displayName) * @return The root groups (empty if there are no root groups) */ public ScriptGroup[] searchRootGroupsInZone( String displayNamePattern, String zone, ScriptPagingDetails paging, String sortBy) { Set<String> authorities; try { authorities = serviceRegistry.getAuthorityService().findAuthorities(AuthorityType.GROUP, null, true, displayNamePattern, zone); } catch (UnknownAuthorityException e) { authorities = Collections.emptySet(); } return makeScriptGroups(authorities, paging, sortBy, serviceRegistry, this.getScope()); }
Add an authority:
String knightGroup = serviceRegistry.getAuthorityService().createAuthority(AuthorityType.GROUP, "KNIGHTS"); serviceRegistry.getAuthorityService().addAuthority(knightGroup, ADMIN_USER_NAME);
See also