Class Role

java.lang.Object
org.restlet.security.Role
All Implemented Interfaces:
Principal

public class Role extends Object implements Principal
Application specific role. Common examples are "administrator", "user", "anonymous", "supervisor". Note that for reusability purpose, it is recommended that those role don't reflect an actual organization, but more the functional requirements of your application. Two roles are considered equals if they belong to the same parent application and have the same name and child roles. The description isn't used for equality assessment. Since version 2.2, they don't need to be the same Java objects anymore. In order to prevent the multiplication of equivalent Role instances, you should try to call Application.getRole(String) method.
Author:
Jerome Louvel, Tim Peierls
  • Constructor Details

    • Role

      public Role()
      Default constructor. Note that the parent application is retrieved using the Application.getCurrent() method if available or is null.
    • Role

      public Role(Application application, String name)
      Constructor.
      Parameters:
      application - The parent application or null.
      name - The name.
    • Role

      public Role(Application application, String name, String description)
      Constructor.
      Parameters:
      application - The parent application or null.
      name - The name.
      description - The description.
  • Method Details

    • get

      public static Role get(Application application, String name)
      Finds an existing role or creates a new one if needed. Note that a null description will be set if the role has to be created.
      Parameters:
      application - The parent application.
      name - The role name to find or create.
      Returns:
      The role found or created.
    • get

      public static Role get(Application application, String name, String description)
      Finds an existing role or creates a new one if needed.
      Parameters:
      application - The parent application.
      name - The role name to find or create.
      description - The role description if one needs to be created.
      Returns:
      The role found or created.
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Principal
      Overrides:
      equals in class Object
    • getApplication

      public Application getApplication()
      Returns the parent application.
      Returns:
      The parent application.
    • getChildRoles

      public List<Role> getChildRoles()
      Returns the modifiable list of child roles.
      Returns:
      The modifiable list of child roles.
    • getDescription

      public String getDescription()
      Returns the description.
      Returns:
      The description.
    • getName

      public String getName()
      Returns the name.
      Specified by:
      getName in interface Principal
      Returns:
      The name.
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Principal
      Overrides:
      hashCode in class Object
    • setApplication

      public void setApplication(Application application)
      Sets the parent application.
      Parameters:
      application - The parent application.
    • setChildRoles

      public void setChildRoles(List<Role> childRoles)
      Sets the modifiable list of child roles. This method clears the current list and adds all entries in the parameter list.
      Parameters:
      childRoles - A list of child roles.
    • setDescription

      public void setDescription(String description)
      Sets the description.
      Parameters:
      description - The description.
    • setName

      public void setName(String name)
      Sets the name.
      Parameters:
      name - The name.
    • toString

      public String toString()
      Specified by:
      toString in interface Principal
      Overrides:
      toString in class Object