Example usage for java.nio.file.attribute AclFileAttributeView getAcl

List of usage examples for java.nio.file.attribute AclFileAttributeView getAcl

Introduction

In this page you can find the example usage for java.nio.file.attribute AclFileAttributeView getAcl.

Prototype

List<AclEntry> getAcl() throws IOException;

Source Link

Document

Reads the access control list.

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("C:/home/docs/users.txt");
    AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class);
    List<AclEntry> aclEntryList = view.getAcl();
    displayAclEntries(aclEntryList);/*from   w w  w . j a va  2s .  c  o m*/
}

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("C:/home/docs/users.txt");
    AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class);
    List<AclEntry> aclEntryList = view.getAcl();
    for (AclEntry entry : aclEntryList) {
        System.out.println("User Principal Name: " + entry.principal().getName());
        System.out.println("ACL Entry Type: " + entry.type());
        displayEntryFlags(entry.flags());
        displayPermissions(entry.permissions());
        System.out.println();//  ww w  . ja va 2  s.c o  m
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("C:\\Java_Dev\\test1.txt");
    AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class);
    if (aclView == null) {
        System.out.format("ACL view  is not  supported.%n");
        return;/*from  ww  w  .j av a 2  s .c om*/
    }
    List<AclEntry> aclEntries = aclView.getAcl();
    for (AclEntry entry : aclEntries) {
        System.out.format("Principal: %s%n", entry.principal());
        System.out.format("Type: %s%n", entry.type());
        System.out.format("Permissions are:%n");

        Set<AclEntryPermission> permissions = entry.permissions();
        for (AclEntryPermission p : permissions) {
            System.out.format("%s %n", p);
        }

    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("C:\\Java_Dev\\test1.txt");

    AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class);
    if (aclView == null) {
        System.out.format("ACL view  is not  supported.%n");
        return;//from  ww  w. j  av  a  2s . co  m
    }
    UserPrincipal bRiceUser = FileSystems.getDefault().getUserPrincipalLookupService()
            .lookupPrincipalByName("brice");

    Set<AclEntryPermission> permissions = EnumSet.of(AclEntryPermission.READ_DATA,
            AclEntryPermission.WRITE_DATA);

    AclEntry.Builder builder = AclEntry.newBuilder();
    builder.setPrincipal(bRiceUser);
    builder.setType(AclEntryType.ALLOW);
    builder.setPermissions(permissions);
    AclEntry newEntry = builder.build();

    List<AclEntry> aclEntries = aclView.getAcl();

    aclEntries.add(newEntry);

    aclView.setAcl(aclEntries);
}