@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"); }
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; }
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; } }
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; }  }
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); }
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);  }