The following Code sets "Read" Permissions on the folder "\\myShare\Folder1\" for the Group G-Test:
String gName="G-Test";
AclEntryPermission[] aeps=new AclEntryPermission[]{
AclEntryPermission.READ_DATA,
AclEntryPermission.READ_ATTRIBUTES,
AclEntryPermission.READ_NAMED_ATTRS,
AclEntryPermission.READ_ACL,
AclEntryPermission.SYNCHRONIZE
};
Path p = FileSystems.getDefault().getPath(new File("\\\\myShare\\Folder1\\").getPath());
AclFileAttributeView view = Files.getFileAttributeView(p, AclFileAttributeView.class);
Set<AclEntryPermission> set = EnumSet.noneOf(AclEntryPermission.class);
for (AclEntryPermission acp: aeps) set.add(acp);
AclEntry.Builder b= AclEntry.newBuilder();
b.setType(AclEntryType.ALLOW);
b.setPermissions(set);
b.setPrincipal(FileSystems.getDefault().getUserPrincipalLookupService().lookupPrincipalByName(gName));
b.setFlags(new AclEntryFlag[]{AclEntryFlag.FILE_INHERIT,AclEntryFlag.DIRECTORY_INHERIT});
List<AclEntry> acl = view.getAcl();
acl.add(b.build());
view.setAcl(acl);
This works for folder1 as expected. But on Folder2 (subfolder: \\myShare\Folder1\Folder2) the ACL is not inherited. When looking with the Windows GUI the inherited ACL is missing in Folder2.
When changing the ACL with Windows for another Group/Permission in Folder1, i could see the previous missing permission on folder2. Or on creating an new Subfolder the ACL is correct inherited.
Is something wrong with the code above? I want to set Read-Permissions on folder1 wich were inherited to all subfolders and files.
The code runs on a Windows 8.1 PC and the share is a Windows 2008 R2 File - Cluster