Search in sources :

Example 6 with HiveRoleGrant

use of org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant in project hive by apache.

the class DDLTask method writeRolesGrantedInfo.

static String writeRolesGrantedInfo(List<HiveRoleGrant> roles, boolean testMode) {
    if (roles == null || roles.isEmpty()) {
        return "";
    }
    StringBuilder builder = new StringBuilder();
    //sort the list to get sorted (deterministic) output (for ease of testing)
    Collections.sort(roles);
    for (HiveRoleGrant role : roles) {
        appendNonNull(builder, role.getRoleName(), true);
        appendNonNull(builder, role.isGrantOption());
        appendNonNull(builder, testMode ? -1 : role.getGrantTime() * 1000L);
        appendNonNull(builder, role.getGrantor());
    }
    return builder.toString();
}
Also used : HiveRoleGrant(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant)

Example 7 with HiveRoleGrant

use of org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant in project hive by apache.

the class DDLTask method roleDDL.

private int roleDDL(Hive db, RoleDDLDesc roleDDLDesc) throws Exception {
    HiveAuthorizer authorizer = getSessionAuthorizer(db);
    RoleDDLDesc.RoleOperation operation = roleDDLDesc.getOperation();
    //call the appropriate hive authorizer function
    switch(operation) {
        case CREATE_ROLE:
            authorizer.createRole(roleDDLDesc.getName(), null);
            break;
        case DROP_ROLE:
            authorizer.dropRole(roleDDLDesc.getName());
            break;
        case SHOW_ROLE_GRANT:
            boolean testMode = conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST);
            List<HiveRoleGrant> roles = authorizer.getRoleGrantInfoForPrincipal(AuthorizationUtils.getHivePrincipal(roleDDLDesc.getName(), roleDDLDesc.getPrincipalType()));
            writeToFile(writeRolesGrantedInfo(roles, testMode), roleDDLDesc.getResFile());
            break;
        case SHOW_ROLES:
            List<String> allRoles = authorizer.getAllRoles();
            writeListToFileAfterSort(allRoles, roleDDLDesc.getResFile());
            break;
        case SHOW_CURRENT_ROLE:
            List<String> roleNames = authorizer.getCurrentRoleNames();
            writeListToFileAfterSort(roleNames, roleDDLDesc.getResFile());
            break;
        case SET_ROLE:
            authorizer.setCurrentRole(roleDDLDesc.getName());
            break;
        case SHOW_ROLE_PRINCIPALS:
            testMode = conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST);
            List<HiveRoleGrant> roleGrants = authorizer.getPrincipalGrantInfoForRole(roleDDLDesc.getName());
            writeToFile(writeHiveRoleGrantInfo(roleGrants, testMode), roleDDLDesc.getResFile());
            break;
        default:
            throw new HiveException("Unkown role operation " + operation.getOperationName());
    }
    return 0;
}
Also used : HiveAuthorizer(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizer) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) HiveRoleGrant(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant) RoleDDLDesc(org.apache.hadoop.hive.ql.plan.RoleDDLDesc)

Example 8 with HiveRoleGrant

use of org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant in project hive by apache.

the class SQLStdHiveAccessController method doesUserHasAdminOption.

private boolean doesUserHasAdminOption(List<String> roleNames) throws HiveAuthzPluginException {
    List<HiveRoleGrant> currentRoles;
    currentRoles = getCurrentRoles();
    for (String roleName : roleNames) {
        boolean roleFound = false;
        for (HiveRoleGrant currentRole : currentRoles) {
            if (roleName.equalsIgnoreCase(currentRole.getRoleName())) {
                roleFound = true;
                if (!currentRole.isGrantOption()) {
                    return false;
                } else {
                    break;
                }
            }
        }
        if (!roleFound) {
            return false;
        }
    }
    return true;
}
Also used : HiveRoleGrant(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant)

Example 9 with HiveRoleGrant

use of org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant in project hive by apache.

the class SQLStdHiveAccessController method getRolesFromMS.

private List<HiveRoleGrant> getRolesFromMS() throws HiveAuthzPluginException {
    try {
        List<RolePrincipalGrant> roles = getRoleGrants(currentUserName, PrincipalType.USER);
        Map<String, HiveRoleGrant> name2Rolesmap = new HashMap<String, HiveRoleGrant>();
        getAllRoleAncestors(name2Rolesmap, roles);
        List<HiveRoleGrant> currentRoles = new ArrayList<HiveRoleGrant>(roles.size());
        for (HiveRoleGrant role : name2Rolesmap.values()) {
            if (!HiveMetaStore.ADMIN.equalsIgnoreCase(role.getRoleName())) {
                currentRoles.add(role);
            } else {
                this.adminRole = role;
            }
        }
        return currentRoles;
    } catch (Exception e) {
        throw SQLAuthorizationUtils.getPluginException("Failed to retrieve roles for " + currentUserName, e);
    }
}
Also used : RolePrincipalGrant(org.apache.hadoop.hive.metastore.api.RolePrincipalGrant) HashMap(java.util.HashMap) HiveRoleGrant(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant) ArrayList(java.util.ArrayList) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveAccessControlException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException) HiveAuthzPluginException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException) TException(org.apache.thrift.TException)

Example 10 with HiveRoleGrant

use of org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant in project hive by apache.

the class SQLStdHiveAccessController method isUserAdmin.

/**
   * @return true only if current role of user is Admin
   * @throws HiveAuthzPluginException
   */
boolean isUserAdmin() throws HiveAuthzPluginException {
    List<HiveRoleGrant> roles;
    roles = getCurrentRoles();
    for (HiveRoleGrant role : roles) {
        if (role.getRoleName().equalsIgnoreCase(HiveMetaStore.ADMIN)) {
            return true;
        }
    }
    return false;
}
Also used : HiveRoleGrant(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant)

Aggregations

HiveRoleGrant (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveRoleGrant)10 RolePrincipalGrant (org.apache.hadoop.hive.metastore.api.RolePrincipalGrant)4 ArrayList (java.util.ArrayList)3 HiveAccessControlException (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 HiveAuthzPluginException (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException)2 TException (org.apache.thrift.TException)2 HashMap (java.util.HashMap)1 GetPrincipalsInRoleRequest (org.apache.hadoop.hive.metastore.api.GetPrincipalsInRoleRequest)1 GetPrincipalsInRoleResponse (org.apache.hadoop.hive.metastore.api.GetPrincipalsInRoleResponse)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 RoleDDLDesc (org.apache.hadoop.hive.ql.plan.RoleDDLDesc)1 HiveAuthorizer (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizer)1