Class Role

  • All Implemented Interfaces:
    java.security.Principal

    public class Role
    extends java.lang.Object
    implements java.security.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Role ALL
      Deprecated.
      To be removed as it is ambiguous, roles being specific to a given application.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      static Role get​(Application application, java.lang.String name)
      Finds an existing role or creates a new one if needed.
      static Role get​(Application application, java.lang.String name, java.lang.String description)
      Finds an existing role or creates a new one if needed.
      Application getApplication()
      Returns the parent application.
      java.util.List<Role> getChildRoles()
      Returns the modifiable list of child roles.
      java.lang.String getDescription()
      Returns the description.
      java.lang.String getName()
      Returns the name.
      int hashCode()  
      void setApplication​(Application application)
      Sets the parent application.
      void setChildRoles​(java.util.List<Role> childRoles)
      Sets the modifiable list of child roles.
      void setDescription​(java.lang.String description)
      Sets the description.
      void setName​(java.lang.String name)
      Sets the name.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.security.Principal

        implies
    • Field Detail

      • ALL

        @Deprecated
        public static final Role ALL
        Deprecated.
        To be removed as it is ambiguous, roles being specific to a given application.
        Unmodifiable role that covers all existing roles. Its name is "*" by convention.
    • Constructor Detail

      • 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,
                    java.lang.String name)
        Constructor.
        Parameters:
        application - The parent application or null.
        name - The name.
      • Role

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

        @Deprecated
        public Role​(java.lang.String name,
                    java.lang.String description)
        Deprecated.
        Constructor. Note that the parent application is retrieved using the Application.getCurrent() method.
        Parameters:
        name - The name.
        description - The description.
    • Method Detail

      • get

        public static Role get​(Application application,
                               java.lang.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,
                               java.lang.String name,
                               java.lang.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​(java.lang.Object o)
        Specified by:
        equals in interface java.security.Principal
        Overrides:
        equals in class java.lang.Object
      • getApplication

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

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

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

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

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

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

        public void setChildRoles​(java.util.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​(java.lang.String description)
        Sets the description.
        Parameters:
        description - The description.
      • setName

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

        public java.lang.String toString()
        Specified by:
        toString in interface java.security.Principal
        Overrides:
        toString in class java.lang.Object