Class AbstractPermissible

java.lang.Object
eu.cloudnetservice.driver.permission.AbstractPermissible
All Implemented Interfaces:
eu.cloudnetservice.common.Named, DefaultedDocPropertyHolder, DocPropertyHolder, Permissible, Comparable<Permissible>
Direct Known Subclasses:
PermissionGroup, PermissionUser

public abstract class AbstractPermissible extends Object implements DefaultedDocPropertyHolder, Permissible
An abstract implementation of a permissible for shared usage.
Since:
4.0
  • Field Details

    • name

      protected final String name
    • potency

      protected final int potency
    • createdTime

      protected final long createdTime
    • permissions

      protected final Set<Permission> permissions
    • groupPermissions

      protected final Map<String,Set<Permission>> groupPermissions
    • properties

      protected final Document properties
  • Constructor Details

    • AbstractPermissible

      public AbstractPermissible(@NonNull @NonNull String name, int potency, long createdTime, @NonNull @NonNull Set<Permission> permissions, @NonNull @NonNull Map<String,Set<Permission>> groupPermissions, @NonNull @NonNull Document properties)
      Constructs a new abstract permissible instance.
      Parameters:
      name - the name of the permissible.
      potency - the potency of the permissible.
      createdTime - the creation time as unix timestamp.
      permissions - all permissions of the permissible.
      groupPermissions - all permissions of the permissible that are per (service) group.
      properties - extra properties for the permissible.
      Throws:
      NullPointerException - if the given name, permissions, groupPermissions or properties is null.
  • Method Details

    • addPermission

      private void addPermission(@NonNull @NonNull Set<Permission> permissions, @NonNull @NonNull Permission permission)
      Adds the given permission into the set of permissions. If the collection contains a permission with the same name it is removed before adding the new permission.
      Parameters:
      permissions - the set of permissions to add the given permission to.
      permission - the permission to add to the other permissions.
      Throws:
      NullPointerException - if the given permissions or the permission is null.
    • addPermission

      public void addPermission(@NonNull @NonNull Permission permission)
      Adds the given permission to this permissible. If a permission with the same name already exists the permission is replaced with the given one.

      After adding the permission an update is required.

      Specified by:
      addPermission in interface Permissible
      Parameters:
      permission - the permission to add.
    • addPermission

      public void addPermission(@NonNull @NonNull String group, @NonNull @NonNull Permission permission)
      Adds the given permission to this permissible for the specified target group. If a permission with the same name already exists the permission is replaced with the given one.

      After adding the permission an update is required.

      Specified by:
      addPermission in interface Permissible
      Parameters:
      group - the group to add the permission for.
      permission - the permission to add.
    • removePermission

      public boolean removePermission(@NonNull @NonNull String permission)
      Removes the given permission from this permissible. This only removes global permissions, not group specific ones.

      After removing the permission an update is required.

      Specified by:
      removePermission in interface Permissible
      Parameters:
      permission - the permission to remove.
      Returns:
      true if any permission was removed, false otherwise.
    • removePermission

      public boolean removePermission(@NonNull @NonNull String permission, @NonNull @NonNull String group)
      Removes the given permission from this permissible and the given target group. This only removes group specific permissions, not global ones.

      After removing the permission an update is required.

      Specified by:
      removePermission in interface Permissible
      Parameters:
      permission - the permission to remove.
      group - the target group to remove the permission from.
      Returns:
      true if any permission was removed, false otherwise.
    • creationTime

      public long creationTime()
      Gets the creation time as unix timestamp of this permissible.
      Specified by:
      creationTime in interface Permissible
      Returns:
      the creation time of this permissible.
    • name

      @NonNull public @NonNull String name()
      Specified by:
      name in interface eu.cloudnetservice.common.Named
    • potency

      public int potency()
      Gets the potency of this permissible. The potency is used for comparison of permissibles. A higher potency results in higher significance.
      Specified by:
      potency in interface Permissible
      Returns:
      the potency of this permissible.
      See Also:
    • permissions

      @NonNull public @NonNull Collection<Permission> permissions()
      Gets all global permissions of this permissible. Specific group permissions are not included.
      Specified by:
      permissions in interface Permissible
      Returns:
      all global permissions.
    • groupPermissions

      @NonNull public @NonNull Map<String,Set<Permission>> groupPermissions()
      Gets all group specific permissions. Global permissions are not included.
      Specified by:
      groupPermissions in interface Permissible
      Returns:
      all group specific permissions.
    • propertyHolder

      @NonNull public @NonNull Document propertyHolder()
      Get the underlying document that all read and write operations are delegated to.
      Specified by:
      propertyHolder in interface DocPropertyHolder
      Returns:
      the underlying document.