Class HytalePermissionsProvider

java.lang.Object
com.hypixel.hytale.server.core.util.io.BlockingDiskFile
com.hypixel.hytale.server.core.permissions.provider.HytalePermissionsProvider
All Implemented Interfaces:
PermissionProvider

public final class HytalePermissionsProvider extends BlockingDiskFile implements PermissionProvider
The basic vanilla handling of permissions using permissions.json.

This is never exposed anywhere - it's withheld and internal.

  • Field Details

  • Constructor Details

    • HytalePermissionsProvider

      public HytalePermissionsProvider()
      Default Constructor for a HytalePermissionsProvider instance.
    • HytalePermissionsProvider

      public HytalePermissionsProvider(@Nonnull Path path)
  • Method Details

    • resolveGroupName

      @Nonnull public static String resolveGroupName(@Nonnull String group)
      Resolves a group name, mapping legacy names to the new namespaced equivalents.
    • getName

      @Nonnull public String getName()
      Specified by:
      getName in interface PermissionProvider
      Returns:
      the name of the permission provider.
    • syncLoad

      public void syncLoad()
      Reads the file, and writes it back when the read brought it up to FILE_VERSION.

      A failed write leaves the server running on what it read. The upgrade gives the same result each time it runs, so the next start does it again, and the next change writes it.

      Overrides:
      syncLoad in class BlockingDiskFile
    • addUserPermissions

      public void addUserPermissions(@Nonnull UUID uuid, @Nonnull Set<String> permissions)
      Description copied from interface: PermissionProvider
      Called to add a set of permissions to a user.
      Specified by:
      addUserPermissions in interface PermissionProvider
      Parameters:
      uuid - The UUID of the user.
      permissions - The set of permissions to add.
    • removeUserPermissions

      public void removeUserPermissions(@Nonnull UUID uuid, @Nonnull Set<String> permissions)
      Description copied from interface: PermissionProvider
      Called to remove a set of permissions from a user.
      Specified by:
      removeUserPermissions in interface PermissionProvider
      Parameters:
      uuid - The UUID of the user.
      permissions - The set of permissions to remove.
    • getUserPermissions

      @Nonnull public Set<String> getUserPermissions(@Nonnull UUID uuid)
      Description copied from interface: PermissionProvider
      Called to get the set of permissions for a user.
      Specified by:
      getUserPermissions in interface PermissionProvider
      Parameters:
      uuid - The UUID of the user.
      Returns:
      the set of permissions for the user.
    • getUsersWithPermission

      @Nonnull public Set<UUID> getUsersWithPermission(@Nonnull String permission)
      Description copied from interface: PermissionProvider
      Finds the users that hold the permission as a grant of their own. A user who holds it through a group is not one of them, and neither is a user who holds it through a wildcard.

      This carries no default, because a provider that answers "nobody" when it means "I cannot tell" makes PermissionProvider.removeUserPermissionFromAll(String) report that it revoked a permission that the user still holds.

      Specified by:
      getUsersWithPermission in interface PermissionProvider
      Parameters:
      permission - The permission node.
      Returns:
      the users that were granted the permission.
    • addUserPermissions

      @Nonnull public Set<UUID> addUserPermissions(@Nonnull Collection<UUID> uuids, @Nonnull Set<String> permissions)
      Description copied from interface: PermissionProvider
      Adds the permissions to every user named. Override this to store the change once rather than once for each user. The default adds them one user at a time, so a failure part way through leaves the users before it changed and reports none of them.
      Specified by:
      addUserPermissions in interface PermissionProvider
      Parameters:
      uuids - The UUID of each user.
      permissions - The set of permissions to add.
      Returns:
      the users the permissions were added to, which leaves out the users that held them.
    • removeUserPermissionFromAll

      @Nonnull public Set<UUID> removeUserPermissionFromAll(@Nonnull String permission)
      Description copied from interface: PermissionProvider
      Takes the permission back from every user that holds it as a grant of their own, as one change. A user who holds it through a group keeps it.
      Specified by:
      removeUserPermissionFromAll in interface PermissionProvider
      Parameters:
      permission - The permission node.
      Returns:
      the users the permission was taken from.
    • getUsersInGroup

      @Nonnull public Set<UUID> getUsersInGroup(@Nonnull String group)
      Description copied from interface: PermissionProvider
      Finds the users that were added to the group. A user who is in the group only because it is the default group is not one of them.

      This carries no default, because a provider that answers "nobody" when it means "I cannot tell" makes PermissionProvider.removeAllUsersFromGroup(String) report that it emptied a group that still has members.

      Specified by:
      getUsersInGroup in interface PermissionProvider
      Parameters:
      group - The name of the group.
      Returns:
      the users that were added to the group.
    • removeAllUsersFromGroup

      @Nonnull public Set<UUID> removeAllUsersFromGroup(@Nonnull String group)
      Description copied from interface: PermissionProvider
      Removes every user that was added to the group, as one change. Override this to store the change once rather than once for each user.
      Specified by:
      removeAllUsersFromGroup in interface PermissionProvider
      Parameters:
      group - The name of the group.
      Returns:
      the users that were removed from the group.
    • addGroupPermissions

      public void addGroupPermissions(@Nonnull String group, @Nonnull Set<String> permissions)
      Description copied from interface: PermissionProvider
      Called to add a set of permissions to a group.
      Specified by:
      addGroupPermissions in interface PermissionProvider
      Parameters:
      group - The name of the group.
      permissions - The set of permissions to add.
    • removeGroupPermissions

      public void removeGroupPermissions(@Nonnull String group, @Nonnull Set<String> permissions)
      Description copied from interface: PermissionProvider
      Called to remove a set of permissions from a group.
      Specified by:
      removeGroupPermissions in interface PermissionProvider
      Parameters:
      group - The name of the group.
      permissions - The set of permissions to remove.
    • getGroupPermissions

      @Nonnull public Set<String> getGroupPermissions(@Nonnull String group)
      Description copied from interface: PermissionProvider
      Called to get the direct (non-inherited) set of permissions for a group.
      Specified by:
      getGroupPermissions in interface PermissionProvider
      Parameters:
      group - The name of the group.
      Returns:
      the set of permissions for the group.
    • getGroupParent

      @Nullable public String getGroupParent(@Nonnull String group)
      Specified by:
      getGroupParent in interface PermissionProvider
      Parameters:
      group - The name of the group.
      Returns:
      the parent group name, or null if this group has no parent.
    • getAllRegisteredGroups

      @Nonnull public Set<String> getAllRegisteredGroups()
      Specified by:
      getAllRegisteredGroups in interface PermissionProvider
      Returns:
      all group names known to this provider.
    • getEffectiveGroupPermissions

      @Nonnull public Set<String> getEffectiveGroupPermissions(@Nonnull String group)
      Description copied from interface: PermissionProvider
      Resolves the full set of permissions for a group, including inherited permissions from the parent chain. Implementations must protect against cycles.
      Specified by:
      getEffectiveGroupPermissions in interface PermissionProvider
      Parameters:
      group - The name of the group.
      Returns:
      the effective permission set (direct + inherited).
    • addUserToGroup

      public void addUserToGroup(@Nonnull UUID uuid, @Nonnull String group)
      Description copied from interface: PermissionProvider
      Called to add a user to a group.
      Specified by:
      addUserToGroup in interface PermissionProvider
      Parameters:
      uuid - The UUID of the user.
      group - The name of the group.
    • removeUserFromGroup

      public void removeUserFromGroup(@Nonnull UUID uuid, @Nonnull String group)
      Description copied from interface: PermissionProvider
      Called to remove a user from a group.
      Specified by:
      removeUserFromGroup in interface PermissionProvider
      Parameters:
      uuid - The UUID of the user.
      group - The name of the group.
    • getGroupsForUser

      @Nonnull public Set<String> getGroupsForUser(@Nonnull UUID uuid)
      Description copied from interface: PermissionProvider
      Called to get the set of groups a user is in.
      Specified by:
      getGroupsForUser in interface PermissionProvider
      Parameters:
      uuid - The UUID of the user.
      Returns:
      the set of groups the user is in.
    • setUserGroup

      public void setUserGroup(@Nonnull UUID uuid, @Nonnull String group)
      Description copied from interface: PermissionProvider
      Atomically replaces all groups for a user with the given single group.
      Specified by:
      setUserGroup in interface PermissionProvider
      Parameters:
      uuid - The UUID of the user.
      group - The group to set as the user's sole group.