Class PermissionUser
java.lang.Object
eu.cloudnetservice.driver.permission.AbstractPermissible
eu.cloudnetservice.driver.permission.PermissionUser
- All Implemented Interfaces:
eu.cloudnetservice.common.document.property.DefaultedDocPropertyHolder<eu.cloudnetservice.common.document.gson.JsonDocument,,Permissible> eu.cloudnetservice.common.document.property.DocPropertyHolder<eu.cloudnetservice.common.document.gson.JsonDocument,,Permissible> eu.cloudnetservice.common.Nameable,Permissible,Comparable<Permissible>
The permission user extends the permissible in that way that it has its own personal permissions. A permission user
can belong to several permission groups and inherits the permissions of those groups.
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for permission users. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Set<PermissionUserGroupInfo>private final Stringprivate final UUIDFields inherited from class eu.cloudnetservice.driver.permission.AbstractPermissible
createdTime, groupPermissions, name, permissions, potency, properties -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPermissionUser(@NonNull UUID uniqueId, @Nullable String hashedPassword, @NonNull Set<PermissionUserGroupInfo> groups, @NonNull String name, int potency, long createdTime, @NonNull Set<Permission> permissions, @NonNull Map<String, Set<Permission>> groupPermissions, @NonNull eu.cloudnetservice.common.document.gson.JsonDocument properties) Constructs a new permission group. -
Method Summary
Modifier and TypeMethodDescriptionaddGroup(@NonNull PermissionUserGroupInfo groupInfo) Adds the given group user info to this permission user.Adds the given group without any time-out to this permission user.Adds the given group with the given time-out to this permission user.static @NonNull PermissionUser.Builderbuilder()Creates a new permission user builder instance with all default values.static @NonNull PermissionUser.Builderbuilder(@NonNull PermissionUser user) Creates a new permission user builder instance and copies all values from the given permission user.booleancheckPassword(@Nullable String password) Checks if the given password matches the stored password.findAssignedGroup(@NonNull String group) Searches for any of the users groups with the given name.Gets the name of all groups the user is in.groups()Gets all groups that the user belongs to.Gets the password of the user hashed with sha 256.booleanChecks if the user is in a permission group that has the given name.booleanremoveGroup(@NonNull String group) Removes every group that has the given name.uniqueId()Gets the unique id of the permission user.Methods inherited from class eu.cloudnetservice.driver.permission.AbstractPermissible
addPermission, addPermission, creationTime, groupPermissions, name, permissions, potency, propertyHolder, removePermission, removePermissionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.common.document.property.DefaultedDocPropertyHolder
propertyAbsent, propertyPresent, readProperty, readPropertyOrDefault, readPropertyOrGet, readPropertyOrThrow, readPropertyOrThrow, removeProperty, writeProperty, writePropertyIfAbsent, writePropertyIfAbsent, writePropertyIfPresent, writePropertyIfPresentMethods inherited from interface eu.cloudnetservice.driver.permission.Permissible
addPermission, addPermission, compareTo, findMatchingPermission, hasPermission, hasPermission, hasPermission, hasPermission, isPermissionSet, permission, permissionNames
-
Field Details
-
uniqueId
-
hashedPassword
-
groups
-
-
Constructor Details
-
PermissionUser
protected PermissionUser(@NonNull @NonNull UUID uniqueId, @Nullable @Nullable String hashedPassword, @NonNull @NonNull Set<PermissionUserGroupInfo> groups, @NonNull @NonNull String name, int potency, long createdTime, @NonNull @NonNull Set<Permission> permissions, @NonNull @NonNull Map<String, Set<Permission>> groupPermissions, @NonNull @NonNull eu.cloudnetservice.common.document.gson.JsonDocument properties) Constructs a new permission group. The group is not saved or updated in any way beforePermissionManagement.addPermissionUser(PermissionUser)is called.- Parameters:
uniqueId- the unique id of the user.hashedPassword- the hashed password of the user.groups- all groups the user is in.name- the name of the user.potency- the potency of the user.createdTime- the creation timestamp.permissions- all permissions of the user.groupPermissions- all group specific permissions of the user.properties- extra properties for the permission user.- Throws:
NullPointerException- if any of the given parameters except the hashed password is null.
-
-
Method Details
-
builder
Creates a new permission user builder instance with all default values.- Returns:
- the new builder instance.
-
builder
@NonNull public static @NonNull PermissionUser.Builder builder(@NonNull @NonNull PermissionUser user) Creates a new permission user builder instance and copies all values from the given permission user.- Parameters:
user- the group to copy from.- Returns:
- the new builder instance.
- Throws:
NullPointerException- if the given user is null.
-
checkPassword
Checks if the given password matches the stored password. The input is hashed using sha 256 and encoded using base64 and then compared to the stored value.- Parameters:
password- the password to compare.- Returns:
- true if the password matches, false otherwise.
-
uniqueId
Gets the unique id of the permission user.- Returns:
- the unique id of the user.
-
groups
Gets all groups that the user belongs to.- Returns:
- all groups of the user.
-
hashedPassword
Gets the password of the user hashed with sha 256. If no password is set null is returned.- Returns:
- the hashed password.
-
groupNames
Gets the name of all groups the user is in.- Returns:
- the name of all groups of the user.
-
findAssignedGroup
@Nullable public @Nullable PermissionUserGroupInfo findAssignedGroup(@NonNull @NonNull String group) Searches for any of the users groups with the given name.- Parameters:
group- the group to search for.- Returns:
- the information about the assigned group, null if not assigned to this user.
- Throws:
NullPointerException- if the given group is null.
-
addGroup
Adds the given group without any time-out to this permission user.Note: No update is done until the user is manually updated using
PermissionManagement.updateUser(PermissionUser).- Parameters:
group- the group to add to the user.- Returns:
- the same user instance for chaining.
- Throws:
NullPointerException- if the given group is null.
-
addGroup
@NonNull public @NonNull PermissionUser addGroup(@NonNull @NonNull String group, long timeOutMillis) Adds the given group with the given time-out to this permission user. The given time-out should be a unix timestamp in the future or any negative int if the group should not expire.Note: No update is done until the user is manually updated using
PermissionManagement.updateUser(PermissionUser).- Parameters:
group- the group to add to the user.timeOutMillis- the timestamp for the group expiry.- Returns:
- the same usr instance for chaining.
- Throws:
NullPointerException- if the given group is null.
-
addGroup
@NonNull public @NonNull PermissionUser addGroup(@NonNull @NonNull PermissionUserGroupInfo groupInfo) Adds the given group user info to this permission user. Other groups with the same name are replaced by the given group info.Note: No update is done until the user is manually updated using
PermissionManagement.updateUser(PermissionUser).- Parameters:
groupInfo- the group info of the new group for the user.- Returns:
- the same user instance for chaining.
- Throws:
NullPointerException- if the given group is null.
-
removeGroup
Removes every group that has the given name.Note: No update is done until the user is manually updated using
PermissionManagement.updateUser(PermissionUser).- Parameters:
group- the group to remove.- Returns:
- true if any group was removed, false otherwise.
- Throws:
NullPointerException- if the given group is null.
-
inGroup
Checks if the user is in a permission group that has the given name.- Parameters:
group- the group to check if the user is in.- Returns:
- true if the user is in any group with the given name, false otherwise.
- Throws:
NullPointerException- if the given group is null.
-