Class PosixAcl

java.lang.Object
com.norconex.crawler.fs.fetch.acl.PosixAcl

public final class PosixAcl extends Object

The permissions of one file or folder of a POSIX-style source (a Unix file system, SFTP, ADLS Gen2, HDFS): its owner, group and mode bits, and any extended entries (named users and groups, and the mask), turned into the standard AclLevel for one right.

POSIX checks the classes in order and stops at the first that matches: the owner, then named users, then the groups (any group the person is in that grants the right), then everyone else. The standard has no order, only "a deny wins", so a class without the right is written as a deny whenever a later class could otherwise let the same person in: an owner who may not read is denied when a group or everyone may. The translation never lets in anyone POSIX keeps out. It can keep out a person POSIX lets in, in one rare case: an owner (or named user) with the right who is also in a group that is denied.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    An entry beside the mode bits that allows or denies rights directly, the way macOS ACL entries do (they are checked before the mode bits).
    static final record 
    A user or group, by the most stable id the source gives, and a readable name when the source gives one besides.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The execute right (x), which on a folder is the right to go in.
    static final int
    The read right (r).
    static final int
    The write right (w).
  • Constructor Summary

    Constructors
    Constructor
    Description
    PosixAcl(String dir, PosixAcl.Principal owner, PosixAcl.Principal group, int mode)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Whether a level lets everybody in: it allows everyone and denies nobody.
    Adds an entry that allows or denies rights directly (macOS).
    group(PosixAcl.Principal grp, int perms)
    Adds a named group entry of an extended ACL.
    groupPerms(int perms)
    Sets the owning group's rights, as given by an extended ACL's own group:: entry (when a file has an extended ACL, the group bits of its mode hold the mask instead).
    boolean
     
    level(String levelName, int right)
    Who has one right, as a level.
    mask(int perms)
    Sets the mask, which limits the rights of named users, named groups and the owning group.
    static int
    The mode bits of a set of Java POSIX permissions.
    The source's own entries, in the getfacl way of writing them when none were kept as given.
    Keeps one of the source's own entries, as it gave it, for the native part of the ACL.
    otherPerms(int perms)
    Sets everyone else's rights, as given by an extended ACL's other:: entry.
    ownerPerms(int perms)
    Sets the owner's rights, as given by an extended ACL's own user:: entry.
     
    static int
    Reads a mode written in octal (755, 1777), or the rwxr-x--- way.
    static int
    Reads rights written the rwx way (r-x, for example), any other letter than r, w and x ignored.
    user(PosixAcl.Principal user, int perms)
    Adds a named user entry of an extended ACL.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • READ

      public static final int READ
      The read right (r).
      See Also:
    • WRITE

      public static final int WRITE
      The write right (w).
      See Also:
    • EXECUTE

      public static final int EXECUTE
      The execute right (x), which on a folder is the right to go in.
      See Also:
  • Constructor Details

    • PosixAcl

      public PosixAcl(String dir, PosixAcl.Principal owner, PosixAcl.Principal group, int mode)
      Parameters:
      dir - the directory users and groups belong to, as <system>:<name> (for example unix:host.example.com)
      owner - the owning user, or null if unknown
      group - the owning group, or null if unknown
      mode - the mode bits (0640, for example); only the lowest nine are used
  • Method Details

    • ownerPerms

      public PosixAcl ownerPerms(int perms)
      Sets the owner's rights, as given by an extended ACL's own user:: entry.
      Parameters:
      perms - the rights, as READ, WRITE and EXECUTE bits
      Returns:
      this
    • groupPerms

      public PosixAcl groupPerms(int perms)
      Sets the owning group's rights, as given by an extended ACL's own group:: entry (when a file has an extended ACL, the group bits of its mode hold the mask instead).
      Parameters:
      perms - the rights
      Returns:
      this
    • otherPerms

      public PosixAcl otherPerms(int perms)
      Sets everyone else's rights, as given by an extended ACL's other:: entry.
      Parameters:
      perms - the rights
      Returns:
      this
    • mask

      public PosixAcl mask(int perms)
      Sets the mask, which limits the rights of named users, named groups and the owning group.
      Parameters:
      perms - the rights the mask lets through
      Returns:
      this
    • user

      public PosixAcl user(PosixAcl.Principal user, int perms)
      Adds a named user entry of an extended ACL.
      Parameters:
      user - the user
      perms - the rights, before the mask
      Returns:
      this
    • group

      public PosixAcl group(PosixAcl.Principal grp, int perms)
      Adds a named group entry of an extended ACL.
      Parameters:
      grp - the group
      perms - the rights, before the mask
      Returns:
      this
    • direct

      public PosixAcl direct(PosixAcl.Direct direct)
      Adds an entry that allows or denies rights directly (macOS).
      Parameters:
      direct - the entry
      Returns:
      this
    • nativeEntry

      public PosixAcl nativeEntry(String entry)
      Keeps one of the source's own entries, as it gave it, for the native part of the ACL.
      Parameters:
      entry - the entry, as text
      Returns:
      this
    • hasExtendedEntries

      public boolean hasExtendedEntries()
      Returns:
      whether named users or groups were added
    • level

      public AclLevel level(String levelName, int right)
      Who has one right, as a level.
      Parameters:
      levelName - the level's name
      right - READ or EXECUTE, typically
      Returns:
      the level
    • owners

      public List<AclEntry> owners()
      Returns:
      the owner, as the ACL's owners
    • nativeData

      public Map<String,Object> nativeData()
      The source's own entries, in the getfacl way of writing them when none were kept as given.
      Returns:
      the native part of the ACL
    • admitsEverybody

      public static boolean admitsEverybody(AclLevel level)
      Whether a level lets everybody in: it allows everyone and denies nobody. Such a level can be left out, as it changes nothing.
      Parameters:
      level - the level
      Returns:
      true if it lets everybody in
    • parsePerms

      public static int parsePerms(String text)
      Reads rights written the rwx way (r-x, for example), any other letter than r, w and x ignored.
      Parameters:
      text - the rights as text
      Returns:
      the rights, as READ, WRITE and EXECUTE bits
    • parseMode

      public static int parseMode(String text)
      Reads a mode written in octal (755, 1777), or the rwxr-x--- way.
      Parameters:
      text - the mode
      Returns:
      the mode bits
      Throws:
      IllegalArgumentException - if the mode is not readable
    • mode

      public static int mode(Set<PosixFilePermission> perms)
      The mode bits of a set of Java POSIX permissions.
      Parameters:
      perms - the permissions
      Returns:
      the mode bits