List of usage examples for org.apache.hadoop.fs.permission AclEntry getPermission
public FsAction getPermission()
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;//from ww w . j a v a2 s . c o m Path filePath = new Path(path); boolean isDir = hdfs.isDirectory(filePath); try { 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:org.apache.sentry.hdfs.SentryAuthorizationProvider.java
License:Apache License
private void addToACLMap(Map<String, AclEntry> map, Collection<AclEntry> entries) { for (AclEntry ent : entries) { String key = (ent.getName() == null ? "" : ent.getName()) + ent.getScope() + ent.getType(); AclEntry aclEntry = map.get(key); if (aclEntry == null) { map.put(key, ent);/*from www. j a v a2s .co m*/ } else { map.put(key, new AclEntry.Builder().setName(ent.getName()).setScope(ent.getScope()) .setType(ent.getType()) .setPermission(ent.getPermission().or(aclEntry.getPermission())).build()); } } }
From source file:org.apache.sentry.hdfs.SentryINodeAttributesProvider.java
License:Apache License
private static void addToACLMap(Map<String, AclEntry> map, Collection<AclEntry> entries) { for (AclEntry ent : entries) { String key = (ent.getName() == null ? "" : ent.getName()) + ent.getScope() + ent.getType(); AclEntry aclEntry = map.get(key); if (aclEntry == null) { map.put(key, ent);//from w ww.j a v a 2 s . c o m } else { map.put(key, new AclEntry.Builder().setName(ent.getName()).setScope(ent.getScope()) .setType(ent.getType()) .setPermission(ent.getPermission().or(aclEntry.getPermission())).build()); } } }
From source file:org.apache.sentry.tests.e2e.hdfs.TestHDFSIntegration.java
License:Apache License
private Map<String, FsAction> getAcls(Path path) throws Exception { AclStatus aclStatus = miniDFS.getFileSystem().getAclStatus(path); Map<String, FsAction> acls = new HashMap<String, FsAction>(); for (AclEntry ent : aclStatus.getEntries()) { if (ent.getType().equals(AclEntryType.GROUP)) { // In case of duplicate acl exist, exception should be thrown. if (acls.containsKey(ent.getName())) { throw new SentryAlreadyExistsException("The acl " + ent.getName()); } else { acls.put(ent.getName(), ent.getPermission()); }/* ww w . ja v a 2 s . co m*/ } } return acls; }
From source file:org.apache.sentry.tests.e2e.hdfs.TestHDFSIntegrationBase.java
License:Apache License
protected Map<String, FsAction> getAcls(AclEntryType type, Path path) throws Exception { AclStatus aclStatus = miniDFS.getFileSystem().getAclStatus(path); Map<String, FsAction> acls = new HashMap<String, FsAction>(); for (AclEntry ent : aclStatus.getEntries()) { if (ent.getType().equals(type)) { // In case of duplicate acl exist, exception should be thrown. if (acls.containsKey(ent.getName())) { throw new SentryAlreadyExistsException("The acl " + ent.getName() + " already exists.\n"); } else { acls.put(ent.getName(), ent.getPermission()); }//www.j a v a 2 s .co m } } return acls; }