Example usage for org.apache.hadoop.fs.permission AclEntry getName

List of usage examples for org.apache.hadoop.fs.permission AclEntry getName

Introduction

In this page you can find the example usage for org.apache.hadoop.fs.permission AclEntry getName.

Prototype

public String getName() 

Source Link

Document

Returns the optional ACL entry name.

Usage

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;/* w  ww .j  a va 2s  . co  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:alluxio.underfs.hdfs.acl.SupportedHdfsAclProvider.java

License:Apache License

/**
 * @param entry an hdfs acl entry//from   www  .j av  a2s .  c  om
 * @return alluxio acl entry type
 */
private alluxio.security.authorization.AclEntryType getAclEntryType(AclEntry entry) throws IOException {
    switch (entry.getType()) {
    case USER:
        return entry.getName() == null || entry.getName().isEmpty()
                ? alluxio.security.authorization.AclEntryType.OWNING_USER
                : alluxio.security.authorization.AclEntryType.NAMED_USER;
    case GROUP:
        return entry.getName() == null || entry.getName().isEmpty()
                ? alluxio.security.authorization.AclEntryType.OWNING_GROUP
                : alluxio.security.authorization.AclEntryType.NAMED_GROUP;
    case MASK:
        return alluxio.security.authorization.AclEntryType.MASK;
    case OTHER:
        return alluxio.security.authorization.AclEntryType.OTHER;
    default:
        throw new IOException("Unknown HDFS ACL entry type: " + entry.getType());
    }
}

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);//  w w  w .j  ava2s . 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.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   ww w  . ja  v  a  2 s. 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.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());
            }/*from  w  w w. ja  va2s  .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());
            }/*from  w  ww . j  a  v a 2 s . com*/
        }
    }
    return acls;
}