use of java.nio.file.attribute.AclEntryFlag in project java-chassis by ServiceComb.
the class FortifyUtils method getDefaultFileAttributes.
public static FileAttribute<?> getDefaultFileAttributes(String filePath) {
Path file = new File(filePath).toPath();
if (isPosix()) {
return PosixFilePermissions.asFileAttribute(FilePerm.getDefaultPosixPerm());
} else {
// for not posix must support ACL, or failed.
String userName = System.getProperty("user.name");
UserPrincipal user = null;
try {
user = file.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName(userName);
} catch (IOException e) {
throw new RuntimeException("Unknown user error.");
}
final AclEntry entry = AclEntry.newBuilder().setType(AclEntryType.ALLOW).setPrincipal(user).setPermissions(FilePerm.getDefaultAclPerm()).setFlags(new AclEntryFlag[] { AclEntryFlag.FILE_INHERIT, AclEntryFlag.DIRECTORY_INHERIT }).build();
return new FileAttribute<List<AclEntry>>() {
public String name() {
return "acl:acl";
}
/* Windows ACL */
//public Object value() { ArrayList l = new ArrayList(); l.add(entry); return l; }
public List<AclEntry> value() {
ArrayList<AclEntry> l = new ArrayList<AclEntry>();
l.add(entry);
return l;
}
};
}
}
use of java.nio.file.attribute.AclEntryFlag in project j2objc by google.
the class AclEntryTest method testGetters.
@Test
public void testGetters() throws Exception {
UserPrincipal user = Files.getOwner(Paths.get("."));
AclEntry aclEntry = AclEntry.newBuilder().setType(AclEntryType.ALLOW).setPrincipal(user).setFlags(AclEntryFlag.INHERIT_ONLY).setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.READ_ATTRIBUTES).build();
assertEquals(AclEntryType.ALLOW, aclEntry.type());
assertEquals(user, aclEntry.principal());
Set<AclEntryPermission> permissions = aclEntry.permissions();
assertEquals(2, permissions.size());
assertTrue(permissions.contains(AclEntryPermission.READ_DATA));
assertTrue(permissions.contains(AclEntryPermission.READ_ATTRIBUTES));
Set<AclEntryFlag> flags = aclEntry.flags();
assertEquals(1, flags.size());
assertTrue(flags.contains(AclEntryFlag.INHERIT_ONLY));
}
Aggregations