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

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

Introduction

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

Prototype

public AclEntryType getType() 

Source Link

Document

Returns the ACL entry type.

Usage

From source file:alluxio.underfs.hdfs.acl.SupportedHdfsAclProvider.java

License:Apache License

private AclEntry getHdfsAclEntry(alluxio.security.authorization.AclEntry entry) throws IOException {
    AclEntry.Builder builder = new AclEntry.Builder();
    // Do not set name for unnamed entries
    if (entry.getType() != alluxio.security.authorization.AclEntryType.OWNING_USER
            && entry.getType() != alluxio.security.authorization.AclEntryType.OWNING_GROUP) {
        builder.setName(entry.getSubject());
    }//from   w  ww  .  j a v a 2s . c om

    builder.setScope(entry.isDefault() ? AclEntryScope.DEFAULT : AclEntryScope.ACCESS);
    builder.setType(getHdfsAclEntryType(entry));
    FsAction permission = FsAction.getFsAction(entry.getActions().toCliString());
    builder.setPermission(permission);
    return builder.build();
}

From source file:alluxio.underfs.hdfs.acl.SupportedHdfsAclProvider.java

License:Apache License

/**
 * @param aclEntry an alluxio acl entry/* ww  w.  j  a  v a2  s . c  o  m*/
 * @return hdfs acl entry type
 */
private AclEntryType getHdfsAclEntryType(alluxio.security.authorization.AclEntry aclEntry) throws IOException {
    switch (aclEntry.getType()) {
    case OWNING_USER:
    case NAMED_USER:
        return AclEntryType.USER;
    case OWNING_GROUP:
    case NAMED_GROUP:
        return AclEntryType.GROUP;
    case MASK:
        return AclEntryType.MASK;
    case OTHER:
        return AclEntryType.OTHER;
    default:
        throw new IOException("Unknown Alluxio ACL entry type: " + aclEntry.getType());
    }
}

From source file:alluxio.underfs.hdfs.acl.SupportedHdfsAclProvider.java

License:Apache License

/**
 * @param entry an hdfs acl entry/* w  w  w  .  j  a v  a2s  . com*/
 * @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);/*from  www. j  av 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 va2 s. com*/
        } 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.TestSentryPermissions.java

License:Apache License

/**
 * Adds user and group permissions and role info and check is the ACL are properly generated.
 *///w w  w  .ja  v  a2  s .c  o m
@Test
public void testSentryPermissions() {
    String authorizable = "db1.tb1";
    FsAction fsAction = FsAction.ALL;
    SentryPermissions perms = new SentryPermissions();
    SentryPermissions.RoleInfo roleInfo = new SentryPermissions.RoleInfo("role1");
    roleInfo.addGroup("group1");
    roleInfo.addGroup("group2");
    TPrivilegePrincipal roleEntity = new TPrivilegePrincipal(TPrivilegePrincipalType.ROLE, "role1");
    TPrivilegePrincipal userEntity = new TPrivilegePrincipal(TPrivilegePrincipalType.USER, "user1");

    perms.addRoleInfo(roleInfo);

    SentryPermissions.PrivilegeInfo pInfo = new SentryPermissions.PrivilegeInfo(authorizable);
    pInfo.setPermission(roleEntity, fsAction);
    pInfo.setPermission(userEntity, fsAction);

    perms.addPrivilegeInfo(pInfo);

    List<AclEntry> acls = perms.getAcls(authorizable);
    Assert.assertEquals("Unexpected number of ACL entries received", 3, acls.size());
    Assert.assertEquals("Unexpected permission", fsAction, acls.get(0).getPermission());

    int userAclCount = 0;
    int groupAclCount = 0;

    for (AclEntry entry : acls) {
        if (entry.getType() == AclEntryType.GROUP) {
            groupAclCount++;
        } else if (entry.getType() == AclEntryType.USER) {
            userAclCount++;
        }
    }
    Assert.assertEquals("Unexpected number of User ACL", 1, userAclCount);
    Assert.assertEquals("Unexpected number of Group ACL", 2, groupAclCount);
}

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  ww .  j a va 2s .c om*/
        }
    }
    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  ww w .  j  a v  a 2  s . com
        }
    }
    return acls;
}