# AclFileAttributeView

public interface **AclFileAttributeView** implements [FileOwnerAttributeView](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html) A file attribute view that supports reading or updating a file's Access
Control Lists (ACL) or file owner attributes.

ACLs are used to specify access rights to file system objects. An ACL is
an ordered list of `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html`, each specifying a
`https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipal.html` and the level of access for that user principal. This
file attribute view defines the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclFileAttributeView.html#getAcl()`, and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclFileAttributeView.html#setAcl(java.util.List<java.nio.file.attribute.AclEntry>)` methods to read and write ACLs based on the ACL
model specified in [*RFC 3530: Network File System (NFS) version 4 Protocol*](http://www.ietf.org/rfc/rfc3530.txt). This file attribute view
is intended for file system implementations that support the NFSv4 ACL model
or have a *well-defined* mapping between the NFSv4 ACL model and the ACL
model used by the file system. The details of such mapping are implementation
dependent and are therefore unspecified.

This class also extends `FileOwnerAttributeView` so as to define
methods to get and set the file owner.

When a file system provides access to a set of `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/FileStore.html` that are not homogeneous then only some of the file systems may
support ACLs. The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/FileStore.html#supportsFileAttributeView(java.lang.Class<?%20extends%20java.nio.file.attribute.FileAttributeView>)` method can be used to test if a file system
supports ACLs.

## Interoperability

RFC 3530 allows for special user identities to be used on platforms that support the POSIX defined access permissions. The special user identities are "`OWNER@`", "`GROUP@`", and "`EVERYONE@`". When both the `AclFileAttributeView` and the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html` are supported then these special user identities may be included in ACL `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html` that are read or written. The file system's `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipalLookupService.html` may be used to obtain a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipal.html` to represent these special identities by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipalLookupService.html#lookupPrincipalByName(java.lang.String)` method.

**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);
 
```

## Dynamic Access

Where dynamic access to file attributes is required, the attributes
supported by this attribute view are as follows:
>
> | Name | Type |
> |---|---|
> | "acl" | `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html`\<`https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html`\> |
> | "owner" | `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipal.html` |

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#getAttribute(java.nio.file.Path,%20java.lang.String,%20java.nio.file.LinkOption...)` method may be used to read
the ACL or owner attributes as if by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclFileAttributeView.html#getAcl()` or
`https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#getOwner()` methods.

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#setAttribute(java.nio.file.Path,%20java.lang.String,%20java.lang.Object,%20java.nio.file.LinkOption...)` method may be used to
update the ACL or owner attributes as if by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclFileAttributeView.html#setAcl(java.util.List<java.nio.file.attribute.AclEntry>)`
or `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#setOwner(java.nio.file.attribute.UserPrincipal)` methods.

## Setting the ACL when creating a file

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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#createFile(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>...)` or `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#createDirectory(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>...)` as an `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileAttribute.html` with `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileAttribute.html#name()` `"acl:acl"` and a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileAttribute.html#value()` that is the list of `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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html`)
any attempt to create a file that would be less secure as a result of the
translation.

### Public Method Summary

|---|---|
| abstract [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[AclEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html)\> | [getAcl](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclFileAttributeView.html#getAcl())() Reads the access control list. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [name](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclFileAttributeView.html#name())() Returns the name of the attribute view. |
| abstract void | [setAcl](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclFileAttributeView.html#setAcl(java.util.List<java.nio.file.attribute.AclEntry>))([List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[AclEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html)\> acl) Updates (replace) the access control list. |

### Inherited Method Summary

From interface [java.nio.file.attribute.FileOwnerAttributeView](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html)

|---|---|
| abstract [UserPrincipal](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipal.html) | [getOwner](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#getOwner())() Read the file owner. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [name](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#name())() Returns the name of the attribute view. |
| abstract void | [setOwner](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#setOwner(java.nio.file.attribute.UserPrincipal))([UserPrincipal](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipal.html) owner) Updates the file owner. |

From interface [java.nio.file.attribute.AttributeView](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AttributeView.html)

|---|---|
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [name](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AttributeView.html#name())() Returns the name of the attribute view. |

## Public Methods

#### public abstract [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[AclEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html)\>
**getAcl**
()

Reads the access control list.

When the file system uses an ACL model that differs from the NFSv4
defined ACL model, then this method returns an ACL that is the translation
of the ACL to the NFSv4 ACL model.

The returned list is modifiable so as to facilitate changes to the
existing ACL. The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclFileAttributeView.html#setAcl(java.util.List<java.nio.file.attribute.AclEntry>)` method is used to update
the file's ACL attribute.

##### Returns

- an ordered list of `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html` representing the ACL

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | In the case of the default provider, a security manager is installed, and it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/RuntimePermission.html`("accessUserInformation") or its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkRead(java.lang.String)` method denies read access to the file. |
|---|---|

#### public abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**name**
()

Returns the name of the attribute view. Attribute views of this type
have the name `"acl"`.

##### Returns

- the name of the attribute view

#### public abstract void
**setAcl**
([List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[AclEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html)\> acl)

Updates (replace) the access control list.

Where the file system supports Access Control Lists, and it uses an
ACL model that differs from the NFSv4 defined ACL model, then this method
must translate the ACL to the model supported by the file system. This
method should reject (by throwing `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html`) any
attempt to write an ACL that would appear to make the file more secure
than would be the case if the ACL were updated. Where an implementation
does not support a mapping of `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntryType.html#AUDIT` or `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntryType.html#ALARM` entries, then this method ignores these entries when
writing the ACL.

If an ACL entry contains a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AclEntry.html#principal()`
that is not associated with the same provider as this attribute view then
`https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/ProviderMismatchException.html` is thrown. Additional validation, if
any, is implementation dependent.

If the file system supports other security related file attributes
(such as a file `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributes.html#permissions()` for example), the updating the access control list
may also cause these security related attributes to be updated.

##### Parameters

| acl | the new access control list |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs or the ACL is invalid |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | In the case of the default provider, a security manager is installed, it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/RuntimePermission.html`("accessUserInformation") or its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkWrite(java.lang.String)` method denies write access to the file. |
|---|---|