Class Permissions

  • All Implemented Interfaces:
    java.io.Serializable

    public class Permissions
    extends java.lang.Object
    implements java.io.Serializable
    class responsible for storing all Right/Role-based information for entities as well as various flags for the containing Details instance. It is strongly encouraged to not base any code on the implementation of the rights, roles, and flag but rather to rely on the public methods.

    In the future, further roles, rights, and flags may be added to this class. This will change the representation in the database, but the simple grant/revoke/isSet logic will remain the same.

    See Also:
    ticket:180, Serialized Form
    • Constructor Detail

      • Permissions

        public Permissions()
        simple constructor. Will turn on all rights for all roles
    • Method Detail

      • bit

        public static int bit​(Permissions.Flag flag)
        returns the order of the bit representing the given Permissions.Flag. This is dependent on the internal representation of Permissions and should only be used when necessary.
      • parseString

        public static Permissions parseString​(java.lang.String rwrwrw)
      • isDisallow

        public static boolean isDisallow​(boolean[] restrictions,
                                         int restriction)
      • isDisallowAnnotate

        public boolean isDisallowAnnotate()
      • isDisallowChgrp

        public boolean isDisallowChgrp()
      • isDisallowChown

        public boolean isDisallowChown()
      • isDisallowDelete

        public boolean isDisallowDelete()
      • isDisallowEdit

        public boolean isDisallowEdit()
      • isDisallowLink

        public boolean isDisallowLink()
      • addExtendedRestrictions

        public void addExtendedRestrictions​(java.util.Set<java.lang.String> extendedRestrictions)
      • getRestrictions

        public boolean[] getRestrictions()
      • copyRestrictions

        @Deprecated
        public boolean[] copyRestrictions()
        Deprecated.
        Produce a copy of restrictions for use elsewhere.
      • copyExtendedRestrictions

        public java.lang.String[] copyExtendedRestrictions()
        Produce a copy of restrictions for use elsewhere.
      • copyRestrictions

        public void copyRestrictions​(java.lang.String[] extendedRestrictions)
        Safely copy the source array.
      • copyRestrictions

        @Deprecated
        public void copyRestrictions​(boolean[] source,
                                     java.lang.String[] extendedRestrictions)
        Deprecated.
        Safely copy the source array. If it is null or contains no "true" values, then the restrictions field will remain null.
      • copyRestrictions

        public void copyRestrictions​(int allow,
                                     java.util.Set<java.lang.String> extendedRestrictions)
        Copy restrictions based on the integer returned by BasicACLVoter.
      • grant

        public Permissions grant​(Permissions.Role role,
                                 Permissions.Right... rights)
        turns on the rights for the given role. Null or empty rights are simply ignored. For example, somePermissions().grant(USER,READ,WRITE,USE); will guarantee that the current user has all rights on this entity.
      • revoke

        public Permissions revoke​(Permissions.Role role,
                                  Permissions.Right... rights)
        turns off the rights for the given role. Null or empty rights are simply ignored. For example, new Permissions().revoke(WORLD,WRITE,USE); will return a Permissions instance which cannot be altered or linked to by members of WORLD.
      • grantAll

        public Permissions grantAll​(Permissions mask)
        takes a permissions instance and ORs it with the current instance. This means that any privileges which have been granted to the argument will also be granted to the current instance. For example, Permissions mask = new Permissions().grant(WORLD,READ); someEntity.getDetails().getPermissions().grantAllk(mask); will allow READ access (and possibly more) to someEntity for members of WORLD.
      • revokeAll

        public Permissions revokeAll​(Permissions mask)
        takes a permissions instance and ANDs it with the current instance. This means that any privileges which have been revoked from the argument will also be revoked from the current instance. For example, Permissions mask = new Permissions().revoke(WORLD,READ,WRITE,USE); someEntity.getDetails().getPermissions().applyMask(mask); will disallow all access to someEntity for members of WORLD. This also implies that applyMask can be used to make copies of Permissions. For example, new Permissions().applyMask( somePermissions ); will produce a copy of somePermissions. Note: the logic here is different from Unix UMASKS.
      • setDisallow

        @Deprecated
        public static void setDisallow​(boolean[] restrictions,
                                       int restriction,
                                       boolean disallow)
        Deprecated.
      • setDisallow

        public void setDisallow​(int restriction,
                                boolean disallow)
      • setDisallowAnnotate

        public Permissions setDisallowAnnotate​(boolean disallowAnnotate)
      • setDisallowChgrp

        public Permissions setDisallowChgrp​(boolean disallowChgrp)
      • setDisallowChown

        public Permissions setDisallowChown​(boolean disallowChown)
      • setDisallowDelete

        public Permissions setDisallowDelete​(boolean disallowDelete)
      • setDisallowEdit

        public Permissions setDisallowEdit​(boolean disallowEdit)
      • setDisallowLink

        public Permissions setDisallowLink​(boolean disallowLink)
      • toString

        public java.lang.String toString()
        produces a String representation of the Permissions similar to those on a Unix filesystem. Unset bits are represented by a dash, while other bits are represented by a symbolic value in the correct bit position. For example, a Permissions with all rights granted to all but WORLD roles would look like: rwrw--
        Overrides:
        toString in class java.lang.Object
      • identical

        public boolean identical​(Permissions p)
        two Permissions instances are identical if they have the same bit representation.
        See Also:
        ticket:291
      • getPerm1

        protected long getPerm1()
      • setPerm1

        protected void setPerm1​(long value)
      • singleBitOut

        protected static final long singleBitOut​(Permissions.Role role,
                                                 Permissions.Right right)
        returns a long with only a single 0 defined by role/right
      • singleBitOn

        protected static final long singleBitOn​(Permissions.Role role,
                                                Permissions.Right right)
        returns a long with only a single 1 defined by role/right