@Test public void testAcl() throws IOException { Path path = createTestFileWithAcl( user("100"), allow(user("100")), allow(user("200")), deny(group("300"))); Acl acl = FilePermissionSample.mapNfsAclToCloudSearchAcl(path); assertThat(acl.getReaders()).hasSize(2); assertThat(acl.getDeniedReaders()).hasSize(1); List<String> userPrincipalNames = acl.getReaders().stream() .filter(principal -> principal.getUserResourceName() != null) .map(principal -> principal.getUserResourceName()) .collect(Collectors.toList()); assertThat(userPrincipalNames) .containsAllOf("identitysources/abcdef12345/users/100", "identitysources/abcdef12345/users/200"); List<String> groupPrincipalNames = acl.getDeniedReaders().stream() .map(principal -> principal.getGroupResourceName()) .collect(Collectors.toList()); assertThat(groupPrincipalNames).contains("identitysources/abcdef12345/groups/300"); }
static Acl mapNfsAclToCloudSearchAcl(Path pathToFile) throws IOException { String identitySourceId = "abcdef12345"; AclFileAttributeView aclView = Files.getFileAttributeView( pathToFile, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (aclView == null) { return new Acl.Builder().build(); } List<Principal> owners = Collections.singletonList( Acl.getUserPrincipal(aclView.getOwner().getName(), identitySourceId) ); List<Principal> allowedReaders = new ArrayList<>(); List<Principal> deniedReaders = new ArrayList<>(); for(AclEntry entry: aclView.getAcl()) { UserPrincipal fsPrincipal = entry.principal(); Principal cloudSearchPrincipal = fsPrincipal instanceof GroupPrincipal ? Acl.getGroupPrincipal(fsPrincipal.getName(), identitySourceId) : Acl.getUserPrincipal(fsPrincipal.getName(), identitySourceId); if (entry.type() == AclEntryType.ALLOW) { allowedReaders.add(cloudSearchPrincipal); } else if (entry.type() == AclEntryType.DENY) { deniedReaders.add(cloudSearchPrincipal); } } return new Acl.Builder() .setReaders(allowedReaders) .setDeniedReaders(deniedReaders) .setOwners(owners) .build(); }
FilePermissionSample { static Acl mapNfsAclToCloudSearchAcl(Path pathToFile) throws IOException { String identitySourceId = "abcdef12345"; AclFileAttributeView aclView = Files.getFileAttributeView( pathToFile, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (aclView == null) { return new Acl.Builder().build(); } List<Principal> owners = Collections.singletonList( Acl.getUserPrincipal(aclView.getOwner().getName(), identitySourceId) ); List<Principal> allowedReaders = new ArrayList<>(); List<Principal> deniedReaders = new ArrayList<>(); for(AclEntry entry: aclView.getAcl()) { UserPrincipal fsPrincipal = entry.principal(); Principal cloudSearchPrincipal = fsPrincipal instanceof GroupPrincipal ? Acl.getGroupPrincipal(fsPrincipal.getName(), identitySourceId) : Acl.getUserPrincipal(fsPrincipal.getName(), identitySourceId); if (entry.type() == AclEntryType.ALLOW) { allowedReaders.add(cloudSearchPrincipal); } else if (entry.type() == AclEntryType.DENY) { deniedReaders.add(cloudSearchPrincipal); } } return new Acl.Builder() .setReaders(allowedReaders) .setDeniedReaders(deniedReaders) .setOwners(owners) .build(); } }
FilePermissionSample { static Acl mapNfsAclToCloudSearchAcl(Path pathToFile) throws IOException { String identitySourceId = "abcdef12345"; AclFileAttributeView aclView = Files.getFileAttributeView( pathToFile, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (aclView == null) { return new Acl.Builder().build(); } List<Principal> owners = Collections.singletonList( Acl.getUserPrincipal(aclView.getOwner().getName(), identitySourceId) ); List<Principal> allowedReaders = new ArrayList<>(); List<Principal> deniedReaders = new ArrayList<>(); for(AclEntry entry: aclView.getAcl()) { UserPrincipal fsPrincipal = entry.principal(); Principal cloudSearchPrincipal = fsPrincipal instanceof GroupPrincipal ? Acl.getGroupPrincipal(fsPrincipal.getName(), identitySourceId) : Acl.getUserPrincipal(fsPrincipal.getName(), identitySourceId); if (entry.type() == AclEntryType.ALLOW) { allowedReaders.add(cloudSearchPrincipal); } else if (entry.type() == AclEntryType.DENY) { deniedReaders.add(cloudSearchPrincipal); } } return new Acl.Builder() .setReaders(allowedReaders) .setDeniedReaders(deniedReaders) .setOwners(owners) .build(); }  }
FilePermissionSample { static Acl mapNfsAclToCloudSearchAcl(Path pathToFile) throws IOException { String identitySourceId = "abcdef12345"; AclFileAttributeView aclView = Files.getFileAttributeView( pathToFile, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (aclView == null) { return new Acl.Builder().build(); } List<Principal> owners = Collections.singletonList( Acl.getUserPrincipal(aclView.getOwner().getName(), identitySourceId) ); List<Principal> allowedReaders = new ArrayList<>(); List<Principal> deniedReaders = new ArrayList<>(); for(AclEntry entry: aclView.getAcl()) { UserPrincipal fsPrincipal = entry.principal(); Principal cloudSearchPrincipal = fsPrincipal instanceof GroupPrincipal ? Acl.getGroupPrincipal(fsPrincipal.getName(), identitySourceId) : Acl.getUserPrincipal(fsPrincipal.getName(), identitySourceId); if (entry.type() == AclEntryType.ALLOW) { allowedReaders.add(cloudSearchPrincipal); } else if (entry.type() == AclEntryType.DENY) { deniedReaders.add(cloudSearchPrincipal); } } return new Acl.Builder() .setReaders(allowedReaders) .setDeniedReaders(deniedReaders) .setOwners(owners) .build(); }  static void main(String[] args); }
FilePermissionSample { static Acl mapNfsAclToCloudSearchAcl(Path pathToFile) throws IOException { String identitySourceId = "abcdef12345"; AclFileAttributeView aclView = Files.getFileAttributeView( pathToFile, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (aclView == null) { return new Acl.Builder().build(); } List<Principal> owners = Collections.singletonList( Acl.getUserPrincipal(aclView.getOwner().getName(), identitySourceId) ); List<Principal> allowedReaders = new ArrayList<>(); List<Principal> deniedReaders = new ArrayList<>(); for(AclEntry entry: aclView.getAcl()) { UserPrincipal fsPrincipal = entry.principal(); Principal cloudSearchPrincipal = fsPrincipal instanceof GroupPrincipal ? Acl.getGroupPrincipal(fsPrincipal.getName(), identitySourceId) : Acl.getUserPrincipal(fsPrincipal.getName(), identitySourceId); if (entry.type() == AclEntryType.ALLOW) { allowedReaders.add(cloudSearchPrincipal); } else if (entry.type() == AclEntryType.DENY) { deniedReaders.add(cloudSearchPrincipal); } } return new Acl.Builder() .setReaders(allowedReaders) .setDeniedReaders(deniedReaders) .setOwners(owners) .build(); }  static void main(String[] args);  }