Class Role
java.lang.Object
com.michelin.cio.hudson.plugins.rolestrategy.Role
- All Implemented Interfaces:
Comparable
Class representing a role, which holds a set of
Permissions.- Author:
- Thomas Maurel
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompare role names.booleanstatic RoleforFolders(String name, Collection<String> folders, Set<Permission> permissions, String description, String templateName) Create a role scoped to folders instead of a pattern.Gets the role description.Full names of the items a folder-scoped role applies to.getName()Getter for the role name.Getter for the regexp pattern.Getter for thePermissions set.Human readable description of what this role applies to, for messages shown to users.hasAnyPermission(Set<Permission> permissions) Checks if the role holds any of the givenPermission.inthashCode()hasPermission(Permission permission) Checks if the role holds the givenPermission.booleanWhether this role is scoped to folders rather than to a pattern.booleanChecks whether this role applies to the item or agent with the given name.normalizeFolders(Collection<String> folders) Normalizes folder names entered by users or read from configuration: trims whitespace, drops leading and trailing slashes and empty entries.voidrefreshPermissionsFromTemplate(PermissionTemplate permissionTemplate) Updates the permissions from the given template.voidrefreshPermissionsFromTemplate(Collection<PermissionTemplate> permissionTemplates) Deprecated.voidsetTemplateName(String templateName)
-
Field Details
-
GLOBAL_ROLE_PATTERN
- See Also:
-
-
Constructor Details
-
Role
-
Role
-
Role
public Role(String name, Pattern pattern, Set<Permission> permissions, @CheckForNull String description) Create a Role.- Parameters:
name- The role namepattern- The pattern matchingAccessControlledobjects namespermissions- ThePermissions associated to the role.nullpermissions will be ignored.description- A description for the role
-
Role
public Role(String name, Pattern pattern, Set<Permission> permissions, @CheckForNull String description, String templateName) Create a Role.- Parameters:
name- The role namepattern- The pattern matchingAccessControlledobjects namespermissions- ThePermissions associated to the role.nullpermissions will be ignored.description- A description for the roletemplateName- True to mark this role as generated
-
-
Method Details
-
forFolders
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @NonNull public static Role forFolders(String name, @NonNull Collection<String> folders, Set<Permission> permissions, @CheckForNull String description, @CheckForNull String templateName) Create a role scoped to folders instead of a pattern.The role applies to each listed item and to everything nested below it. Entries are full item names such as
Team/Special; leading and trailing slashes and surrounding whitespace are ignored.- Parameters:
name- The role namefolders- Full names of the items the role applies to; must contain at least one non-blank entrypermissions- ThePermissions associated to the role.nullpermissions will be ignored.description- A description for the roletemplateName- Name of the permission template the role takes its permissions from, if any- Returns:
- the new role
- Throws:
IllegalArgumentException- iffoldershas no usable entry
-
setTemplateName
-
getTemplateName
-
getName
Getter for the role name.- Returns:
- The role name
-
getPattern
Getter for the regexp pattern.For a folder-scoped role this is an equivalent pattern derived from its folders; use
matches(String)to check whether the role applies to a name.- Returns:
- The pattern associated to the role
-
getFolders
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @CheckForNull public SortedSet<String> getFolders()Full names of the items a folder-scoped role applies to.- Returns:
- the folders, or
nullwhen the role matches bygetPattern()
-
isFolderScoped
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean isFolderScoped()Whether this role is scoped to folders rather than to a pattern.- Returns:
truefor a folder-scoped role
-
matches
Checks whether this role applies to the item or agent with the given name.- Parameters:
name- the full name of an item, or the name of an agent- Returns:
trueif the role applies to it
-
getScopeDescription
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @NonNull public String getScopeDescription()Human readable description of what this role applies to, for messages shown to users.- Returns:
- the folder list for a folder-scoped role, otherwise the pattern
-
normalizeFolders
@NonNull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static SortedSet<String> normalizeFolders(@CheckForNull Collection<String> folders) Normalizes folder names entered by users or read from configuration: trims whitespace, drops leading and trailing slashes and empty entries.- Parameters:
folders- the raw folder names- Returns:
- the normalized, sorted, de-duplicated folder names
-
getPermissions
Getter for thePermissions set.- Returns:
Permissions set
-
refreshPermissionsFromTemplate
@Deprecated public void refreshPermissionsFromTemplate(Collection<PermissionTemplate> permissionTemplates) Deprecated.Updates the permissions from the template matching the name.- Parameters:
permissionTemplates- List of templates to look for
-
refreshPermissionsFromTemplate
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void refreshPermissionsFromTemplate(@CheckForNull PermissionTemplate permissionTemplate) Updates the permissions from the given template. The name of the given template must match the configured template name in the role.- Parameters:
permissionTemplate- PermissionTemplate
-
getDescription
Gets the role description.- Returns:
- Role description.
nullif not set
-
hasPermission
Checks if the role holds the givenPermission.- Parameters:
permission- The permission you want to check- Returns:
- True if the role holds this permission
-
hasAnyPermission
Checks if the role holds any of the givenPermission.- Parameters:
permissions- APermissions set- Returns:
- True if the role holds any of the given
Permissions
-
compareTo
Compare role names. Used to sort the sets. We presume that any role name is being used once and only once.- Specified by:
compareToin interfaceComparable- Parameters:
o- The object you want to compare this instance to- Returns:
- Comparison of role names
-
hashCode
public int hashCode() -
equals
-
refreshPermissionsFromTemplate(PermissionTemplate)