Search in sources :

Example 16 with PrincipalType

use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.

the class DDLTask method descDatabase.

private int descDatabase(Hive db, DescDatabaseDesc descDatabase) throws HiveException {
    DataOutputStream outStream = getOutputStream(descDatabase.getResFile());
    try {
        Database database = db.getDatabase(descDatabase.getDatabaseName());
        if (database == null) {
            throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, descDatabase.getDatabaseName());
        }
        Map<String, String> params = null;
        if (descDatabase.isExt()) {
            params = database.getParameters();
        }
        // key. This is to get consistent param ordering between Java7 and Java8.
        if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST) && params != null) {
            params = new TreeMap<String, String>(params);
        }
        String location = database.getLocationUri();
        if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST)) {
            location = "location/in/test";
        }
        PrincipalType ownerType = database.getOwnerType();
        formatter.showDatabaseDescription(outStream, database.getName(), database.getDescription(), location, database.getOwnerName(), (null == ownerType) ? null : ownerType.name(), params);
    } catch (Exception e) {
        throw new HiveException(e, ErrorMsg.GENERIC_ERROR);
    } finally {
        IOUtils.closeStream(outStream);
    }
    return 0;
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) DataOutputStream(java.io.DataOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Database(org.apache.hadoop.hive.metastore.api.Database) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) URISyntaxException(java.net.URISyntaxException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) HiveAuthzPluginException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException) InvalidTableException(org.apache.hadoop.hive.ql.metadata.InvalidTableException)

Example 17 with PrincipalType

use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.

the class HiveAuthorizationTaskFactoryImpl method createShowRoleGrantTask.

@Override
public Task<? extends Serializable> createShowRoleGrantTask(ASTNode ast, Path resultFile, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) {
    ASTNode child = (ASTNode) ast.getChild(0);
    PrincipalType principalType = PrincipalType.USER;
    switch(child.getType()) {
        case HiveParser.TOK_USER:
            principalType = PrincipalType.USER;
            break;
        case HiveParser.TOK_GROUP:
            principalType = PrincipalType.GROUP;
            break;
        case HiveParser.TOK_ROLE:
            principalType = PrincipalType.ROLE;
            break;
    }
    String principalName = BaseSemanticAnalyzer.unescapeIdentifier(child.getChild(0).getText());
    RoleDDLDesc roleDesc = new RoleDDLDesc(principalName, principalType, RoleDDLDesc.RoleOperation.SHOW_ROLE_GRANT, null);
    roleDesc.setResFile(resultFile.toString());
    return TaskFactory.get(new DDLWork(inputs, outputs, roleDesc));
}
Also used : DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) RoleDDLDesc(org.apache.hadoop.hive.ql.plan.RoleDDLDesc) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Example 18 with PrincipalType

use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.

the class HiveV1Authorizer method getRoleGrantInfoForPrincipal.

@Override
public List<HiveRoleGrant> getRoleGrantInfoForPrincipal(HivePrincipal principal) throws HiveAuthzPluginException, HiveAccessControlException {
    PrincipalType type = AuthorizationUtils.getThriftPrincipalType(principal.getType());
    try {
        List<HiveRoleGrant> grants = new ArrayList<HiveRoleGrant>();
        Hive hive = Hive.getWithFastCheck(this.conf);
        for (RolePrincipalGrant grant : hive.getRoleGrantInfoForPrincipal(principal.getName(), type)) {
            grants.add(new HiveRoleGrant(grant));
        }
        return grants;
    } catch (HiveException e) {
        throw new HiveAuthzPluginException(e);
    }
}
Also used : Hive(org.apache.hadoop.hive.ql.metadata.Hive) RolePrincipalGrant(org.apache.hadoop.hive.metastore.api.RolePrincipalGrant) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ArrayList(java.util.ArrayList) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Example 19 with PrincipalType

use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.

the class HiveV1Authorizer method showPrivileges.

@Override
public List<HivePrivilegeInfo> showPrivileges(HivePrincipal principal, HivePrivilegeObject privObj) throws HiveAuthzPluginException, HiveAccessControlException {
    String name = principal == null ? null : principal.getName();
    PrincipalType type = AuthorizationUtils.getThriftPrincipalType(principal == null ? null : principal.getType());
    List<HiveObjectPrivilege> privs = new ArrayList<HiveObjectPrivilege>();
    try {
        Hive hive = Hive.getWithFastCheck(this.conf);
        if (privObj == null) {
            // show user level privileges
            privs.addAll(hive.showPrivilegeGrant(HiveObjectType.GLOBAL, name, type, null, null, null, null));
        } else if (privObj.getDbname() == null) {
            // show all privileges
            privs.addAll(hive.showPrivilegeGrant(null, name, type, null, null, null, null));
        } else {
            Database dbObj = hive.getDatabase(privObj.getDbname());
            ;
            if (dbObj == null) {
                throw new HiveException("Database " + privObj.getDbname() + " does not exists");
            }
            Table tableObj = null;
            if (privObj.getObjectName() != null) {
                tableObj = hive.getTable(dbObj.getName(), privObj.getObjectName());
            }
            List<String> partValues = privObj.getPartKeys();
            if (tableObj == null) {
                // show database level privileges
                privs.addAll(hive.showPrivilegeGrant(HiveObjectType.DATABASE, name, type, dbObj.getName(), null, null, null));
            } else {
                List<String> columns = privObj.getColumns();
                if (columns != null && !columns.isEmpty()) {
                    // show column level privileges
                    for (String columnName : columns) {
                        privs.addAll(hive.showPrivilegeGrant(HiveObjectType.COLUMN, name, type, dbObj.getName(), tableObj.getTableName(), partValues, columnName));
                    }
                } else if (partValues == null) {
                    // show table level privileges
                    privs.addAll(hive.showPrivilegeGrant(HiveObjectType.TABLE, name, type, dbObj.getName(), tableObj.getTableName(), null, null));
                } else {
                    // show partition level privileges
                    privs.addAll(hive.showPrivilegeGrant(HiveObjectType.PARTITION, name, type, dbObj.getName(), tableObj.getTableName(), partValues, null));
                }
            }
        }
        return AuthorizationUtils.getPrivilegeInfos(privs);
    } catch (Exception ex) {
        throw new HiveAuthzPluginException(ex);
    }
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Hive(org.apache.hadoop.hive.ql.metadata.Hive) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) Table(org.apache.hadoop.hive.ql.metadata.Table) ArrayList(java.util.ArrayList) Database(org.apache.hadoop.hive.metastore.api.Database) ArrayList(java.util.ArrayList) List(java.util.List) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Example 20 with PrincipalType

use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.

the class HiveV1Authorizer method grantOrRevokeRole.

private void grantOrRevokeRole(List<HivePrincipal> principals, List<String> roles, boolean grantOption, HivePrincipal grantor, boolean isGrant) throws HiveException {
    PrincipalType grantorType = AuthorizationUtils.getThriftPrincipalType(grantor.getType());
    Hive hive = Hive.getWithFastCheck(this.conf);
    for (HivePrincipal principal : principals) {
        PrincipalType principalType = AuthorizationUtils.getThriftPrincipalType(principal.getType());
        String userName = principal.getName();
        for (String roleName : roles) {
            if (isGrant) {
                hive.grantRole(roleName, userName, principalType, grantor.getName(), grantorType, grantOption);
            } else {
                hive.revokeRole(roleName, userName, principalType, grantOption);
            }
        }
    }
}
Also used : Hive(org.apache.hadoop.hive.ql.metadata.Hive) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Aggregations

PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)29 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)15 ArrayList (java.util.ArrayList)14 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)13 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)11 MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)8 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)6 MTable (org.apache.hadoop.hive.metastore.model.MTable)6 Hive (org.apache.hadoop.hive.ql.metadata.Hive)6 Database (org.apache.hadoop.hive.metastore.api.Database)5 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)5 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)5 MDataConnector (org.apache.hadoop.hive.metastore.model.MDataConnector)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 List (java.util.List)3 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)3 MDBPrivilege (org.apache.hadoop.hive.metastore.model.MDBPrivilege)3 MDCPrivilege (org.apache.hadoop.hive.metastore.model.MDCPrivilege)3