### Question:
FilePermissionSample { static Acl mapPosixFilePermissionToCloudSearchAcl(Path pathToFile) throws IOException { String identitySourceId = "abcdef12345"; PosixFileAttributeView attributeView = Files.getFileAttributeView( pathToFile, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (attributeView == null) { return new Acl.Builder().build(); } PosixFileAttributes attrs = attributeView.readAttributes(); List<Principal> owners = Collections.singletonList( Acl.getUserPrincipal(attrs.owner().getName(), identitySourceId) ); List<Principal> readers = new ArrayList<>(); Set<PosixFilePermission> permissions = attrs.permissions(); if (permissions.contains(PosixFilePermission.OWNER_READ)) { readers.add(Acl.getUserPrincipal(attrs.owner().getName(), identitySourceId)); } if (permissions.contains(PosixFilePermission.GROUP_READ)) { String externalGroupName = attrs.group().getName(); Principal group = Acl.getGroupPrincipal(externalGroupName, identitySourceId); readers.add(group); } if (permissions.contains(PosixFilePermission.OTHERS_READ)) { Principal everyone = Acl.getCustomerPrincipal(); readers.add(everyone); } Acl acl = new Acl.Builder() .setReaders(readers) .setOwners(owners) .build(); return acl; }  static void main(String[] args);  }### Answer:
@Test public void testPosixOwnerOnly() throws IOException { Path path = createTestFileWithPosixPermissions( user("100"), group("200"), PosixFilePermission.OWNER_READ); Acl acl = FilePermissionSample.mapPosixFilePermissionToCloudSearchAcl(path); assertThat(acl.getReaders()).hasSize(1); List<String> userPrincipalNames = acl.getReaders().stream() .map(principal -> principal.getUserResourceName()) .collect(Collectors.toList()); assertThat(userPrincipalNames).contains("identitysources/abcdef12345/users/100"); }
@Test public void testPosixWithGroup() throws IOException { Path path = createTestFileWithPosixPermissions( user("100"), group("200"), PosixFilePermission.OWNER_READ, PosixFilePermission.GROUP_READ); Acl acl = FilePermissionSample.mapPosixFilePermissionToCloudSearchAcl(path); assertThat(acl.getReaders()).hasSize(2); List<String> groupPrincipalNames = acl.getReaders().stream() .filter(principal -> principal.getGroupResourceName() != null) .map(principal -> principal.getGroupResourceName()) .collect(Collectors.toList()); assertThat(groupPrincipalNames).contains("identitysources/abcdef12345/groups/200"); }
@Test public void testPosixWithGroupAndOther() throws IOException { Path path = createTestFileWithPosixPermissions( user("100"), group("200"), PosixFilePermission.OWNER_READ, PosixFilePermission.OTHERS_READ, PosixFilePermission.GROUP_READ); Acl acl = FilePermissionSample.mapPosixFilePermissionToCloudSearchAcl(path); assertThat(acl.getReaders()).hasSize(3); assertThat(acl.getReaders().stream() .filter(principal -> principal.getGsuitePrincipal() != null && principal.getGsuitePrincipal().getGsuiteDomain()) .count()).isEqualTo(1); }