Class DefaultPermissionManagement
java.lang.Object
eu.cloudnetservice.driver.permission.DefaultPermissionManagement
- All Implemented Interfaces:
PermissionManagement
- Direct Known Subclasses:
DefaultCachedPermissionManagement
This abstract default permission management represents the implementation for the permission management. Methods
doing the calculation for permissions and their result are already implemented and there is no need to implement
those yourself.
- Since:
- 4.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallGroupPermissions(@NonNull Permissible permissible, String group) Gets all permission of the specified permissible on the given group.allPermissions(@NonNull Permissible permissible) Gets all permission of the specified permissible.Gets the child permission management.protected voidcollectAllGroupPermissionsInto(@NonNull Collection<Permission> target, @NonNull Collection<PermissionGroup> groups, @Nullable String[] taskGroups, @NonNull Collection<String> travelledGroups) Collects all permissions into the given target collection by travelling recursively through every of the given group and the parents of the groups.protected @NonNull Collection<Permission>collectAllPermissions(@NonNull Permissible permissible, @Nullable String[] groups) protected @NonNull Collection<Permission>collectAllPermissionsTo(@NonNull Collection<Permission> target, @NonNull Permissible permissible, @Nullable String[] groups) Collects all permissions for the given permissible into the given target collection.protected voidcollectPermissionsInto(@NonNull Collection<Permission> permissions, @NonNull Permissible permissible, @Nullable String[] groups) Collects all permissions of the given permissible into the given permission collection.findHighestPermission(@NonNull Collection<Permission> permissions, @NonNull Permission permission) Finds the highest permission (sorted by the potency) in the given permission collection using the given permission potency as the starting point.groupPermissionResult(@NonNull Permissible permissible, @NonNull String group, @NonNull Permission permission) Checks if the given permissible has the given permission for the given group.groupsOf(@Nullable Permissible permissible) Gets all groups that are associated with the given permissible.groupsPermissionResult(@NonNull Permissible permissible, @NonNull String[] groups, @NonNull Permission permission) Checks if the given permissible has the given permission for the given groups.highestPermissionGroup(@NonNull PermissionUser permissionUser) Gets the highest permission group for the given user.modifyGroup(@NonNull String name, @NonNull BiConsumer<PermissionGroup, PermissionGroup.Builder> modifier) Gets the permission group with the given name by usingPermissionManagement.group(String)and, if not null, puts it into the consumer, after that, the group will be updated by usingPermissionManagement.updateGroup(PermissionGroup).modifyUser(@NonNull UUID uniqueId, @NonNull BiConsumer<PermissionUser, PermissionUser.Builder> modifier) Gets the permission user with the given unique id usingPermissionManagement.user(UUID)and, if not null, puts them into the consumer, after that, the user will be updated by usingPermissionManagement.updateUser(PermissionUser).modifyUsers(@NonNull String name, @NonNull BiConsumer<PermissionUser, PermissionUser.Builder> modifier) Gets every user matching the given name usingPermissionManagement.usersByName(String)and puts them into the consumer, after that, every user will be updated by usingPermissionManagement.updateUser(PermissionUser).permissionResult(@NonNull Permissible permissible, @NonNull Permission permission) Checks if the given permissible or any group that is associated with the permissible has the permission, and it is not overriden by another permission with a negative potency.booleantestPermissible(@Nullable Permissible permissible) Removes the timed-out permissions of the given permissible.booleantestPermissionUser(@Nullable PermissionUser permissionUser) Removes all timed-out permissions and groups of the given permission user.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.permission.PermissionManagement
addGroupAsync, addPermissionGroup, addPermissionGroup, addPermissionGroupAsync, addPermissionUser, addPermissionUser, addPermissionUserAsync, addUserAsync, close, containsGroup, containsGroupAsync, containsOneUser, containsOneUserAsync, containsUser, containsUserAsync, defaultPermissionGroup, defaultPermissionGroupAsync, deleteGroup, deleteGroupAsync, deletePermissionGroup, deletePermissionGroupAsync, deletePermissionUser, deletePermissionUserAsync, deleteUser, deleteUserAsync, firstUser, firstUserAsync, getOrCreateUser, getOrCreateUserAsync, group, groupAsync, groups, groups, groupsAsync, groupsAsync, groupsOfAsync, hasGroupPermission, hasPermission, init, modifyGroupAsync, modifyUserAsync, modifyUsersAsync, reload, sendCommandLine, sendCommandLineAsync, updateGroup, updateGroupAsync, updateUser, updateUserAsync, user, userAsync, users, usersAsync, usersByGroup, usersByGroupAsync, usersByName, usersByNameAsync
-
Constructor Details
-
DefaultPermissionManagement
public DefaultPermissionManagement()
-
-
Method Details
-
childPermissionManagement
Gets the child permission management. The default implementation does not allow a child permission management, therefore it's always null.- Specified by:
childPermissionManagementin interfacePermissionManagement- Returns:
- the child management, by default null.
-
highestPermissionGroup
Gets the highest permission group for the given user. The highest permission group is determined by the potency of the group. A higher potency results in the highest group.- Specified by:
highestPermissionGroupin interfacePermissionManagement- Parameters:
permissionUser- the user to get the group for.- Returns:
- the highest permission group, null if the user is not in any group and there is no default group.
-
testPermissionUser
Removes all timed-out permissions and groups of the given permission user.- Specified by:
testPermissionUserin interfacePermissionManagement- Parameters:
permissionUser- the permission user to check.- Returns:
- true if at least one permission was removed, false otherwise.
-
testPermissible
Removes the timed-out permissions of the given permissible.- Specified by:
testPermissiblein interfacePermissionManagement- Parameters:
permissible- the permissible to check.- Returns:
- true if at least one permission was removed, false otherwise.
-
groupsOf
@NonNull public @NonNull Collection<PermissionGroup> groupsOf(@Nullable @Nullable Permissible permissible) Gets all groups that are associated with the given permissible.- Specified by:
groupsOfin interfacePermissionManagement- Parameters:
permissible- the permissible to retrieve the groups for.- Returns:
- all found groups.
-
permissionResult
@NonNull public @NonNull PermissionCheckResult permissionResult(@NonNull @NonNull Permissible permissible, @NonNull @NonNull Permission permission) Checks if the given permissible or any group that is associated with the permissible has the permission, and it is not overriden by another permission with a negative potency.- Specified by:
permissionResultin interfacePermissionManagement- Parameters:
permissible- the permissible to check if the permission is set.permission- the permission to check.- Returns:
- the result of the permission check.
-
groupPermissionResult
@NonNull public @NonNull PermissionCheckResult groupPermissionResult(@NonNull @NonNull Permissible permissible, @NonNull @NonNull String group, @NonNull @NonNull Permission permission) Checks if the given permissible has the given permission for the given group.- Specified by:
groupPermissionResultin interfacePermissionManagement- Parameters:
permissible- the permissible to check if the permission is set.group- the group to get the permissions on.permission- the permission to check.- Returns:
- the result of the permission check.
-
groupsPermissionResult
@NonNull public @NonNull PermissionCheckResult groupsPermissionResult(@NonNull @NonNull Permissible permissible, @NonNull @NonNull String[] groups, @NonNull @NonNull Permission permission) Checks if the given permissible has the given permission for the given groups.- Specified by:
groupsPermissionResultin interfacePermissionManagement- Parameters:
permissible- the permissible to check if the permission is set.groups- the groups to get the permissions on.permission- the permission to check.- Returns:
- the result of the permission check.
-
findHighestPermission
@Nullable public @Nullable Permission findHighestPermission(@NonNull @NonNull Collection<Permission> permissions, @NonNull @NonNull Permission permission) Finds the highest permission (sorted by the potency) in the given permission collection using the given permission potency as the starting point.- Specified by:
findHighestPermissionin interfacePermissionManagement- Parameters:
permissions- the permissions to check through.permission- the starting point for the check to run.- Returns:
- the highest permission in the given permission or null if there is no permission with a higher potency in the given collection.
-
collectAllPermissions
@NonNull protected @NonNull Collection<Permission> collectAllPermissions(@NonNull @NonNull Permissible permissible, @Nullable @Nullable String[] groups) -
collectAllPermissionsTo
@NonNull protected @NonNull Collection<Permission> collectAllPermissionsTo(@NonNull @NonNull Collection<Permission> target, @NonNull @NonNull Permissible permissible, @Nullable @Nullable String[] groups) Collects all permissions for the given permissible into the given target collection. If the groups array is not null group specific permissions are included in the collection.- Parameters:
target- the target to collect to.permissible- the permissible to collect for.groups- the groups to collect group permissions for.- Returns:
- all collected permissions.
- Throws:
NullPointerException- if the given target or permissible is null.
-
collectAllGroupPermissionsInto
protected void collectAllGroupPermissionsInto(@NonNull @NonNull Collection<Permission> target, @NonNull @NonNull Collection<PermissionGroup> groups, @Nullable @Nullable String[] taskGroups, @NonNull @NonNull Collection<String> travelledGroups) Collects all permissions into the given target collection by travelling recursively through every of the given group and the parents of the groups. If task groups are given the group permissions are included too. The travelled group collection is used to prevent infinite recursion, the collection is passed down while travelling to the next group.- Parameters:
target- the collection to collect into.groups- the groups to collect the permissions for.taskGroups- the groups to collect group permissions for.travelledGroups- all already visited groups.- Throws:
NullPointerException- if the given target, group or travelled group collection is null.
-
collectPermissionsInto
protected void collectPermissionsInto(@NonNull @NonNull Collection<Permission> permissions, @NonNull @NonNull Permissible permissible, @Nullable @Nullable String[] groups) Collects all permissions of the given permissible into the given permission collection. If the groups array is not null group permissions are included too.- Parameters:
permissions- the collection to collect into.permissible- the permissible to collect for.groups- optional target groups to collect for.- Throws:
NullPointerException- if the given permissions or permissible is null.
-
allPermissions
@NonNull public @NonNull Collection<Permission> allPermissions(@NonNull @NonNull Permissible permissible) Gets all permission of the specified permissible.- Specified by:
allPermissionsin interfacePermissionManagement- Parameters:
permissible- the permissible to get the permission of.- Returns:
- all permissions of the permissible.
-
allGroupPermissions
@NonNull public @NonNull Collection<Permission> allGroupPermissions(@NonNull @NonNull Permissible permissible, String group) Gets all permission of the specified permissible on the given group.- Specified by:
allGroupPermissionsin interfacePermissionManagement- Parameters:
permissible- the permissible to get the permission of.group- the group to get the permission on or null if no specific group should be used.- Returns:
- all permissions of the permissible on the specified group if provided.
-
modifyGroup
@Nullable public @Nullable PermissionGroup modifyGroup(@NonNull @NonNull String name, @NonNull @NonNull BiConsumer<PermissionGroup, PermissionGroup.Builder> modifier) Gets the permission group with the given name by usingPermissionManagement.group(String)and, if not null, puts it into the consumer, after that, the group will be updated by usingPermissionManagement.updateGroup(PermissionGroup).- Specified by:
modifyGroupin interfacePermissionManagement- Parameters:
name- the name of the group.modifier- the consumer to modify the user.- Returns:
- the modified group, null if no group was found with the given name.
-
modifyUser
@Nullable public @Nullable PermissionUser modifyUser(@NonNull @NonNull UUID uniqueId, @NonNull @NonNull BiConsumer<PermissionUser, PermissionUser.Builder> modifier) Gets the permission user with the given unique id usingPermissionManagement.user(UUID)and, if not null, puts them into the consumer, after that, the user will be updated by usingPermissionManagement.updateUser(PermissionUser).- Specified by:
modifyUserin interfacePermissionManagement- Parameters:
uniqueId- the unique id of the usermodifier- the consumer to modify the user- Returns:
- the modified user, null if no user was found with the given unique id.
-
modifyUsers
@NonNull public @NonNull List<PermissionUser> modifyUsers(@NonNull @NonNull String name, @NonNull @NonNull BiConsumer<PermissionUser, PermissionUser.Builder> modifier) Gets every user matching the given name usingPermissionManagement.usersByName(String)and puts them into the consumer, after that, every user will be updated by usingPermissionManagement.updateUser(PermissionUser).- Specified by:
modifyUsersin interfacePermissionManagement- Parameters:
name- the name of the users.modifier- the consumer to modify the available users.- Returns:
- a list containing all modified users.
-