Package com.jgcomptech.tools.authc
Class UserRole
- java.lang.Object
-
- com.jgcomptech.tools.authc.UserRole
-
public class UserRole extends java.lang.Object
An object representing a user account role.- Since:
- 1.4.0, 1.5.0 Updated permission integration
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
UserRole.Builder
A builder class to be used to modify UserRoles.
-
Constructor Summary
Constructors Constructor Description UserRole(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addImplicitPermission(java.lang.String name)
Implicitly adds the specified permission to the user role even if it is already inherited.boolean
addImplicitPermissions(java.lang.String... names)
Implicitly adds the specified permissions to the user role even if they are already inherited.boolean
addPermission(java.lang.String name)
Adds the specified permission to the user role.boolean
addPermissions(java.lang.String... names)
Adds the specified permissions to the user role.void
disable()
Attempts to disable the user role.void
enable()
Enables the user role.boolean
equals(java.lang.Object o)
java.lang.String
getName()
Returns the name of the user role.java.util.Set<java.lang.String>
getPermissions()
Returns a list of permissions assigned to the user role.int
hashCode()
boolean
hasPermission(java.lang.String name)
Checks if the user role has the specified permission.boolean
hasPermissions(java.lang.String... names)
Checks if the user role has the specified permissions.boolean
isEnabled()
Checks if the user role is enabled.UserRole.Builder
modify()
Creates a new instance of the UserRole modification builder.boolean
removePermission(java.lang.String name)
Removes the specified permission from the user role.boolean
removePermissions(java.lang.String... names)
Removes the specified permissions from the user role.java.lang.String
toString()
-
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the name of the user role.- Returns:
- the name of the user role
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isEnabled
public boolean isEnabled()
Checks if the user role is enabled.- Returns:
- true if the user role is enabled
-
enable
public void enable()
Enables the user role.
-
disable
public void disable()
Attempts to disable the user role.- Throws:
java.lang.IllegalStateException
- if the user role is a system role because system roles cannot be disabled
-
getPermissions
public java.util.Set<java.lang.String> getPermissions()
Returns a list of permissions assigned to the user role.- Returns:
- a list of permissions assigned to the user role
-
hasPermission
public boolean hasPermission(java.lang.String name)
Checks if the user role has the specified permission.- Parameters:
name
- the name of the permission to check- Returns:
- true if the user role has the specified permission
- Since:
- 1.5.0
-
hasPermissions
public boolean hasPermissions(java.lang.String... names)
Checks if the user role has the specified permissions.- Parameters:
names
- the names of the permissions to check- Returns:
- true if the user role has the specified permissions
- Since:
- 1.5.0
-
addPermission
public boolean addPermission(java.lang.String name)
Adds the specified permission to the user role.- Parameters:
name
- the name of the permission to add- Returns:
- true if permission is added successfully
- Throws:
java.lang.IllegalArgumentException
- if attempting to add to the NONE system role
-
addPermissions
public boolean addPermissions(java.lang.String... names)
Adds the specified permissions to the user role.- Parameters:
names
- the names of the permissions to add- Returns:
- true if permission is added successfully
- Throws:
java.lang.IllegalArgumentException
- if attempting to add to the NONE system role
-
addImplicitPermission
public boolean addImplicitPermission(java.lang.String name)
Implicitly adds the specified permission to the user role even if it is already inherited.- Parameters:
name
- the name of the permission to add- Returns:
- true if permission is added successfully
- Throws:
java.lang.IllegalArgumentException
- if attempting to add to the NONE system role- Since:
- 1.5.0
-
addImplicitPermissions
public boolean addImplicitPermissions(java.lang.String... names)
Implicitly adds the specified permissions to the user role even if they are already inherited.- Parameters:
names
- the name of the permissions to add- Returns:
- true if permissions are added successfully
- Throws:
java.lang.IllegalArgumentException
- if attempting to add to the NONE system role- Since:
- 1.5.0
-
removePermission
public boolean removePermission(java.lang.String name)
Removes the specified permission from the user role. Inherited permissions are not removed.- Parameters:
name
- the name of the permission to remove- Returns:
- true if permission is removed successfully
-
removePermissions
public boolean removePermissions(java.lang.String... names)
Removes the specified permissions from the user role. Inherited permissions are not removed.- Parameters:
names
- the names of the permissions to remove- Returns:
- true if permissions are removed successfully
-
modify
public UserRole.Builder modify()
Creates a new instance of the UserRole modification builder.- Returns:
- a new instance of the UserRole modification builder
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-