Package com.jgcomptech.tools.authc
Class UserRole
- java.lang.Object
-
- com.jgcomptech.tools.authc.UserRole
-
public class UserRole extends java.lang.ObjectAn 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 classUserRole.BuilderA 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 booleanaddImplicitPermission(java.lang.String name)Implicitly adds the specified permission to the user role even if it is already inherited.booleanaddImplicitPermissions(java.lang.String... names)Implicitly adds the specified permissions to the user role even if they are already inherited.booleanaddPermission(java.lang.String name)Adds the specified permission to the user role.booleanaddPermissions(java.lang.String... names)Adds the specified permissions to the user role.voiddisable()Attempts to disable the user role.voidenable()Enables the user role.booleanequals(java.lang.Object o)java.lang.StringgetName()Returns the name of the user role.java.util.Set<java.lang.String>getPermissions()Returns a list of permissions assigned to the user role.inthashCode()booleanhasPermission(java.lang.String name)Checks if the user role has the specified permission.booleanhasPermissions(java.lang.String... names)Checks if the user role has the specified permissions.booleanisEnabled()Checks if the user role is enabled.UserRole.Buildermodify()Creates a new instance of the UserRole modification builder.booleanremovePermission(java.lang.String name)Removes the specified permission from the user role.booleanremovePermissions(java.lang.String... names)Removes the specified permissions from the user role.java.lang.StringtoString()
-
-
-
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:
toStringin 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-