List of usage examples for org.apache.hadoop.fs.permission AclStatus getOwner
public String getOwner()
From source file:alluxio.underfs.hdfs.acl.SupportedHdfsAclProvider.java
License:Apache License
@Override public Pair<AccessControlList, DefaultAccessControlList> getAcl(FileSystem hdfs, String path) throws IOException { AclStatus hdfsAcl; Path filePath = new Path(path); boolean isDir = hdfs.isDirectory(filePath); try {/*from ww w. j a v a 2 s . c o m*/ hdfsAcl = hdfs.getAclStatus(filePath); } catch (AclException e) { // When dfs.namenode.acls.enabled is false, getAclStatus throws AclException. return new Pair<>(null, null); } AccessControlList acl = new AccessControlList(); DefaultAccessControlList defaultAcl = new DefaultAccessControlList(); acl.setOwningUser(hdfsAcl.getOwner()); acl.setOwningGroup(hdfsAcl.getGroup()); defaultAcl.setOwningUser(hdfsAcl.getOwner()); defaultAcl.setOwningGroup(hdfsAcl.getGroup()); for (AclEntry entry : hdfsAcl.getEntries()) { alluxio.security.authorization.AclEntry.Builder builder = new alluxio.security.authorization.AclEntry.Builder(); builder.setType(getAclEntryType(entry)); builder.setSubject(entry.getName() == null ? "" : entry.getName()); FsAction permission = entry.getPermission(); if (permission.implies(FsAction.READ)) { builder.addAction(AclAction.READ); } else if (permission.implies(FsAction.WRITE)) { builder.addAction(AclAction.WRITE); } else if (permission.implies(FsAction.EXECUTE)) { builder.addAction(AclAction.EXECUTE); } if (entry.getScope().equals(AclEntryScope.ACCESS)) { acl.setEntry(builder.build()); } else { // default ACL, must be a directory defaultAcl.setEntry(builder.build()); } } if (isDir) { return new Pair<>(acl, defaultAcl); } else { // a null defaultACL indicates this is a file return new Pair<>(acl, null); } }
From source file:com.bigstep.datalake.JsonUtil.java
License:Apache License
/** Convert a AclStatus object to a Json string. */ public static String toJsonString(final AclStatus status) { if (status == null) { return null; }/*from ww w . jav a 2 s.c om*/ final Map<String, Object> m = new TreeMap<String, Object>(); m.put("owner", status.getOwner()); m.put("group", status.getGroup()); m.put("stickyBit", status.isStickyBit()); final List<String> stringEntries = new ArrayList<>(); for (AclEntry entry : status.getEntries()) { stringEntries.add(entry.toString()); } m.put("entries", stringEntries); FsPermission perm = status.getPermission(); if (perm != null) { m.put("permission", toString(perm)); if (perm.getAclBit()) { m.put("aclBit", true); } if (perm.getEncryptedBit()) { m.put("encBit", true); } } final Map<String, Map<String, Object>> finalMap = new TreeMap<String, Map<String, Object>>(); finalMap.put(AclStatus.class.getSimpleName(), m); Gson gson = new Gson(); return gson.toJson(finalMap); }
From source file:org.trustedanalytics.auth.gateway.hdfs.integration.HdfsGatewayIntegrationTest.java
License:Apache License
private void checkIfDirectoryExistsWithACL(Path path, String owner, String[] privilegedUsers, String[] privilegedGroups) throws IOException { AclStatus s = fileSystem.getAclStatus(path); assertThat(fileSystem.exists(path), equalTo(true)); assertThat(s.getOwner(), equalTo(owner)); List<String> usersWithAcl = s.getEntries().stream() .filter(entry -> entry.getType().equals(AclEntryType.USER)) .filter(entry -> entry.getScope().equals(AclEntryScope.ACCESS)).map(AclEntry::getName) .collect(toList());//from w w w .j a va 2 s. co m List<String> groupsWithAcl = s.getEntries().stream() .filter(entry -> entry.getType().equals(AclEntryType.GROUP)) .filter(entry -> entry.getScope().equals(AclEntryScope.ACCESS)).map(AclEntry::getName) .collect(toList()); List<String> usersWithDefaultAcl = s.getEntries().stream() .filter(entry -> entry.getType().equals(AclEntryType.USER)) .filter(entry -> entry.getScope().equals(AclEntryScope.ACCESS)).map(AclEntry::getName) .collect(toList()); List<String> groupsWithDefaultAcl = s.getEntries().stream() .filter(entry -> entry.getType().equals(AclEntryType.GROUP)) .filter(entry -> entry.getScope().equals(AclEntryScope.ACCESS)).map(AclEntry::getName) .collect(toList()); assertThat(usersWithAcl.size(), equalTo(privilegedUsers.length)); assertThat(usersWithAcl, containsInAnyOrder(privilegedUsers)); assertThat(groupsWithAcl.size(), equalTo(privilegedGroups.length)); assertThat(groupsWithAcl, containsInAnyOrder(privilegedGroups)); assertThat(usersWithDefaultAcl.size(), equalTo(privilegedUsers.length)); assertThat(usersWithDefaultAcl, containsInAnyOrder(privilegedUsers)); assertThat(groupsWithDefaultAcl.size(), equalTo(privilegedGroups.length)); assertThat(groupsWithDefaultAcl, containsInAnyOrder(privilegedGroups)); }