This class also extends {@code FileOwnerAttributeView} so as to definemethods to get and set the file owner.
When a file system provides access to a set of {@link FileStore file-systems} that are not homogeneous then only some of the file systems maysupport ACLs. The {@link FileStore#supportsFileAttributeView supportsFileAttributeView} method can be used to test if a file systemsupports ACLs.
Usage Example: Suppose we wish to add an entry to an existing ACL to grant "joe" access:
// lookup "joe" UserPrincipal joe = file.getFileSystem().getUserPrincipalLookupService() .lookupPrincipalByName("joe"); // get view AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class); // create ACE to give "joe" read access AclEntry entry = AclEntry.newBuilder() .setType(AclEntryType.ALLOW) .setPrincipal(joe) .setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.READ_ATTRIBUTES) .build(); // read ACL, insert ACE, re-write ACL List<AclEntry> acl = view.getAcl(); acl.add(0, entry); // insert before any DENY entries view.setAcl(acl);
Where dynamic access to file attributes is required, the attributes supported by this attribute view are as follows:
Name Type "acl" {@link List}< {@link AclEntry}> "owner" {@link UserPrincipal}
The {@link Files#getAttribute getAttribute} method may be used to readthe ACL or owner attributes as if by invoking the {@link #getAcl getAcl} or{@link #getOwner getOwner} methods.
The {@link Files#setAttribute setAttribute} method may be used toupdate the ACL or owner attributes as if by invoking the {@link #setAcl setAcl}or {@link #setOwner setOwner} methods.
Implementations supporting this attribute view may also support setting the initial ACL when creating a file or directory. The initial ACL may be provided to methods such as {@link Files#createFile createFile} or {@link Files#createDirectory createDirectory} as an {@link FileAttribute} with {@link FileAttribute#name name} {@code "acl:acl"} and a {@link FileAttribute#value value} that is the list of {@code AclEntry} objects.
Where an implementation supports an ACL model that differs from the NFSv4 defined ACL model then setting the initial ACL when creating the file must translate the ACL to the model supported by the file system. Methods that create a file should reject (by throwing {@link IOException IOException}) any attempt to create a file that would be less secure as a result of the translation. @since 1.7
|
|
|
|
|
|