Package com.jgcomptech.tools.authz
Class PermissionManager
- java.lang.Object
-
- com.jgcomptech.tools.events.EventTarget<PermissionEvent>
-
- com.jgcomptech.tools.authz.PermissionManager
-
public final class PermissionManager extends EventTarget<PermissionEvent>
Manages permissions to be used to enable or disable parts of your application.- Since:
- 1.4.0, 1.5.0 Changed implementation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPermissionManager.SystemPermissionsA list of the implemented permission types.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddAndEnableCustomPermission(java.lang.String name, java.lang.String parentName)Adds new permission with the specified name and parent name, enabled by default.booleanaddCustomPermission(java.lang.String name, java.lang.String parentName)Adds new permission with the specified name and parent name, disabled by default.java.lang.Objectclone()voiddisableDebugLogging()Disables basic event handlers with System.Out logging for all events.booleandisablePermission(java.lang.String name)Disables the specified permission and all its children.booleandoesPermissionExist(java.lang.String name)Checks if the specified permission exists.voidenableDebugLogging()Enables basic event handlers with System.Out logging for all events.booleanenablePermission(java.lang.String name)Enables the specified permission and all its children.PermissiongetAdminPermission()Returns the Admin permission.PermissiongetCreatePermission()Returns the Create permission.PermissiongetEditPermission()Returns the Edit permission.static PermissionManagergetInstance()Returns the instance of the PermissionManager, if one doesn't exist it is created.PermissiongetPermission(java.lang.String name)Returns the specified permission.java.util.Set<java.lang.String>getPermissionChildren(java.lang.String name)Returns a list of child permissions of the specified permission.java.util.Map<java.lang.String,Permission>getPermissions()Returns a HashMap of all existing permission objects.java.util.Set<java.lang.String>getPermissionsNames()Returns a list of names of existing permissions.PermissiongetReadPermission()Returns the Read permission.booleanisAdminPermissionEnabled()Returns true if Admin permission is enabled.booleanisCreatePermissionEnabled()Returns true if Create permission is enabled.booleanisEditPermissionEnabled()Returns true if Edit permission is enabled.booleanisPermissionDisabled(java.lang.String name)Checks if the specified permission is enabled.booleanisPermissionEnabled(java.lang.String name)Checks if the specified permission is enabled.booleanisReadPermissionEnabled()Returns true if Read permission is enabled.voidloadPermissions(boolean enableAll)Sets all permissions, if enableAll is true, all are enabled and false all are disabled.voidloadPermissions(UserRole userRole)Sets the correct permissions according to the specified user role.voidloadPermissions(UserRoleManager.SystemUserRoles userRole)Sets the correct permissions according to the specified user role.booleanremovePermission(java.lang.String name)Removes the specified permission.voidsetAdminPermission(boolean value)Manually sets the status of the Admin permission.voidsetCreatePermission(boolean value)Manually sets the status of the Create permission.voidsetEditPermission(boolean value)Manually sets the status of the Edit permission.voidsetOnAllPermissionsDisabled(EventHandler<PermissionEvent> e)Sets the event handler that will fire when multiple permissions loaded.voidsetOnAllPermissionsEnabled(EventHandler<PermissionEvent> e)Sets the event handler that will fire when multiple permissions loaded.voidsetOnPermissionsApplied(EventHandler<PermissionEvent> e)Sets the event handler that will fire when multiple permissions loaded.booleansetPermissionOnDisabled(java.lang.String name, EventHandler<PermissionEvent> e)Sets the EventHandler for the OnDisabled event for the specified permission.booleansetPermissionOnEnabled(java.lang.String name, EventHandler<PermissionEvent> e)Sets the EventHandler for the OnEnabled event for the specified permission.voidsetReadPermission(boolean value)Manually sets the status of the Read permission.-
Methods inherited from class com.jgcomptech.tools.events.EventTarget
addEventHandler, equals, fire, getEventHandler, hashCode, removeEventHandler, toString
-
-
-
-
Method Detail
-
getInstance
public static PermissionManager getInstance()
Returns the instance of the PermissionManager, if one doesn't exist it is created.- Returns:
- the instance of the PermissionManager
-
enableDebugLogging
public void enableDebugLogging()
Enables basic event handlers with System.Out logging for all events.- Since:
- 1.5.0
-
disableDebugLogging
public void disableDebugLogging()
Disables basic event handlers with System.Out logging for all events.- Since:
- 1.5.0
-
isAdminPermissionEnabled
public boolean isAdminPermissionEnabled()
Returns true if Admin permission is enabled.- Returns:
- true if Admin permission is enabled
-
isEditPermissionEnabled
public boolean isEditPermissionEnabled()
Returns true if Edit permission is enabled.- Returns:
- true if Edit permission is enabled
-
isCreatePermissionEnabled
public boolean isCreatePermissionEnabled()
Returns true if Create permission is enabled.- Returns:
- true if Create permission is enabled
-
isReadPermissionEnabled
public boolean isReadPermissionEnabled()
Returns true if Read permission is enabled.- Returns:
- true if Read permission is enabled
-
setAdminPermission
public void setAdminPermission(boolean value)
Manually sets the status of the Admin permission.- Parameters:
value- the value to set
-
setEditPermission
public void setEditPermission(boolean value)
Manually sets the status of the Edit permission.- Parameters:
value- the value to set
-
setCreatePermission
public void setCreatePermission(boolean value)
Manually sets the status of the Create permission.- Parameters:
value- the value to set
-
setReadPermission
public void setReadPermission(boolean value)
Manually sets the status of the Read permission.- Parameters:
value- the value to set
-
getAdminPermission
public Permission getAdminPermission()
Returns the Admin permission.- Returns:
- the permission object
-
getEditPermission
public Permission getEditPermission()
Returns the Edit permission.- Returns:
- the permission object
-
getCreatePermission
public Permission getCreatePermission()
Returns the Create permission.- Returns:
- the permission object
-
getReadPermission
public Permission getReadPermission()
Returns the Read permission.- Returns:
- the permission object
-
getPermissions
public java.util.Map<java.lang.String,Permission> getPermissions()
Returns a HashMap of all existing permission objects.- Returns:
- a HashMap of all existing permission objects
-
getPermissionsNames
public java.util.Set<java.lang.String> getPermissionsNames()
Returns a list of names of existing permissions.- Returns:
- a list of names of existing permissions
-
getPermission
public Permission getPermission(java.lang.String name)
Returns the specified permission.- Parameters:
name- the name of the permission to lookup- Returns:
- the specified permission
-
doesPermissionExist
public boolean doesPermissionExist(java.lang.String name)
Checks if the specified permission exists.- Parameters:
name- the name of the permission to check- Returns:
- true if the specified permission exists
- Since:
- 1.5.0
-
removePermission
public boolean removePermission(java.lang.String name)
Removes the specified permission.- Parameters:
name- the name of the permission to remove- Returns:
- false if the permission does not exist or is a system permission
- Since:
- 1.5.0 now uses a parallel stream allowing a large list of permissions
-
enablePermission
public boolean enablePermission(java.lang.String name)
Enables the specified permission and all its children.- Parameters:
name- the name of the permission to enable- Returns:
- false if the permission does not exist
-
disablePermission
public boolean disablePermission(java.lang.String name)
Disables the specified permission and all its children.- Parameters:
name- the name of the permission to disable- Returns:
- false if the permission does not exist
-
isPermissionEnabled
public boolean isPermissionEnabled(java.lang.String name)
Checks if the specified permission is enabled.- Parameters:
name- the name of the permission to check- Returns:
- false if the permission is disabled or if the permission does not exist
-
isPermissionDisabled
public boolean isPermissionDisabled(java.lang.String name)
Checks if the specified permission is enabled.- Parameters:
name- the name of the permission to check- Returns:
- true if the permission is disabled or if the permission does not exist
-
getPermissionChildren
public java.util.Set<java.lang.String> getPermissionChildren(java.lang.String name)
Returns a list of child permissions of the specified permission.- Parameters:
name- the name of the permission- Returns:
- a list of child permissions of the specified permission. Returns null if the permission does not exist.
-
addCustomPermission
public boolean addCustomPermission(java.lang.String name, java.lang.String parentName)Adds new permission with the specified name and parent name, disabled by default.- Parameters:
name- the name of the new permissionparentName- the name of the parent permission, null or empty string if none- Returns:
- false if permission already exists
-
addAndEnableCustomPermission
public boolean addAndEnableCustomPermission(java.lang.String name, java.lang.String parentName)Adds new permission with the specified name and parent name, enabled by default.- Parameters:
name- the name of the new permissionparentName- the name of the parent permission, null or empty string if none- Returns:
- false if permission already exists
-
setPermissionOnEnabled
public boolean setPermissionOnEnabled(java.lang.String name, EventHandler<PermissionEvent> e)Sets the EventHandler for the OnEnabled event for the specified permission.- Parameters:
name- the name of the permission to add EventHandler toe- the EventHandler to set- Returns:
- false if the permission does not exist
-
setPermissionOnDisabled
public boolean setPermissionOnDisabled(java.lang.String name, EventHandler<PermissionEvent> e)Sets the EventHandler for the OnDisabled event for the specified permission.- Parameters:
name- the name of the permission to add EventHandler toe- the EventHandler to set- Returns:
- false if the permission does not exist
-
setOnPermissionsApplied
public void setOnPermissionsApplied(EventHandler<PermissionEvent> e)
Sets the event handler that will fire when multiple permissions loaded.- Parameters:
e- the event handler
-
setOnAllPermissionsEnabled
public void setOnAllPermissionsEnabled(EventHandler<PermissionEvent> e)
Sets the event handler that will fire when multiple permissions loaded.- Parameters:
e- the event handler
-
setOnAllPermissionsDisabled
public void setOnAllPermissionsDisabled(EventHandler<PermissionEvent> e)
Sets the event handler that will fire when multiple permissions loaded.- Parameters:
e- the event handler
-
loadPermissions
public void loadPermissions(boolean enableAll)
Sets all permissions, if enableAll is true, all are enabled and false all are disabled.- Parameters:
enableAll- if true all are enabled and if false all are disabled- Since:
- 1.5.0 now uses a parallel stream allowing a large list of permissions
-
loadPermissions
public void loadPermissions(UserRoleManager.SystemUserRoles userRole)
Sets the correct permissions according to the specified user role.- Parameters:
userRole- the user role to use to set permissions
-
loadPermissions
public void loadPermissions(UserRole userRole)
Sets the correct permissions according to the specified user role.- Parameters:
userRole- the user role to use to set permissions- Since:
- 1.5.0 now uses a parallel stream allowing a large list of permissions
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException
-
-