Package org.restlet.security
Class Role
- java.lang.Object
-
- org.restlet.security.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 equivalentRole
instances, you should try to callApplication.getRole(String)
method.- Author:
- Jerome Louvel, Tim Peierls
-
-
Constructor Summary
Constructors Constructor Description Role()
Default constructor.Role(java.lang.String name)
Deprecated.UseRole(Application, String)
instead.Role(java.lang.String name, java.lang.String description)
Deprecated.UseRole(Application, String, String)
instead.Role(Application application, java.lang.String name)
Constructor.Role(Application application, java.lang.String name, java.lang.String description)
Constructor.
-
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()
-
-
-
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 theApplication.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)
Deprecated.UseRole(Application, String)
instead.Constructor. Note that the parent application is retrieved using theApplication.getCurrent()
method.- Parameters:
name
- The name.
-
Role
@Deprecated public Role(java.lang.String name, java.lang.String description)
Deprecated.UseRole(Application, String, String)
instead.Constructor. Note that the parent application is retrieved using theApplication.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 interfacejava.security.Principal
- Overrides:
equals
in classjava.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 interfacejava.security.Principal
- Returns:
- The name.
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.security.Principal
- Overrides:
hashCode
in classjava.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 interfacejava.security.Principal
- Overrides:
toString
in classjava.lang.Object
-
-