java.lang.Object
com.michelin.cio.hudson.plugins.rolestrategy.Role
All Implemented Interfaces:
Comparable

public final class Role extends Object implements Comparable
Class representing a role, which holds a set of Permissions.
Author:
Thomas Maurel
  • Field Details

  • Constructor Details

    • Role

      @DataBoundConstructor public Role(@NonNull String name, @CheckForNull String pattern, @CheckForNull Set<String> permissionIds, @CheckForNull String description, String templateName)
    • Role

      public Role(@NonNull String name, @CheckForNull String pattern, @CheckForNull Set<String> permissionIds, @CheckForNull String description)
    • Role

      public Role(String name, Pattern pattern, Set<Permission> permissions, @CheckForNull String description)
      Create a Role.
      Parameters:
      name - The role name
      pattern - The pattern matching AccessControlled objects names
      permissions - The Permissions associated to the role. null permissions 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 name
      pattern - The pattern matching AccessControlled objects names
      permissions - The Permissions associated to the role. null permissions will be ignored.
      description - A description for the role
      templateName - 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 name
      folders - Full names of the items the role applies to; must contain at least one non-blank entry
      permissions - The Permissions associated to the role. null permissions will be ignored.
      description - A description for the role
      templateName - Name of the permission template the role takes its permissions from, if any
      Returns:
      the new role
      Throws:
      IllegalArgumentException - if folders has no usable entry
    • setTemplateName

      public void setTemplateName(@CheckForNull String templateName)
    • getTemplateName

      public String getTemplateName()
    • getName

      public String getName()
      Getter for the role name.
      Returns:
      The role name
    • getPattern

      public Pattern 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 null when the role matches by getPattern()
    • isFolderScoped

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean isFolderScoped()
      Whether this role is scoped to folders rather than to a pattern.
      Returns:
      true for a folder-scoped role
    • matches

      public boolean matches(@NonNull String name)
      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:
      true if 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

      public Set<Permission> getPermissions()
      Getter for the Permissions set.
      Returns:
      Permissions set
    • refreshPermissionsFromTemplate

      @Deprecated public void refreshPermissionsFromTemplate(Collection<PermissionTemplate> permissionTemplates)
      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

      @CheckForNull public String getDescription()
      Gets the role description.
      Returns:
      Role description. null if not set
    • hasPermission

      public Boolean hasPermission(Permission permission)
      Checks if the role holds the given Permission.
      Parameters:
      permission - The permission you want to check
      Returns:
      True if the role holds this permission
    • hasAnyPermission

      public Boolean hasAnyPermission(Set<Permission> permissions)
      Checks if the role holds any of the given Permission.
      Parameters:
      permissions - A Permissions set
      Returns:
      True if the role holds any of the given Permissions
    • compareTo

      public int compareTo(@NonNull Object o)
      Compare role names. Used to sort the sets. We presume that any role name is being used once and only once.
      Specified by:
      compareTo in interface Comparable
      Parameters:
      o - The object you want to compare this instance to
      Returns:
      Comparison of role names
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object