Search in sources :

Example 1 with ShowGrantDesc

use of org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc in project hive by apache.

the class TestHiveAuthorizationTaskFactory method testShowGrantRoleOnTable.

/**
 * SHOW GRANT ROLE ... ON TABLE ...
 */
@Test
public void testShowGrantRoleOnTable() throws Exception {
    DDLWork work = analyze("SHOW GRANT ROLE " + ROLE + " ON TABLE " + TABLE);
    ShowGrantDesc grantDesc = (ShowGrantDesc) work.getDDLDesc();
    Assert.assertNotNull("Show grant should not be null", grantDesc);
    Assert.assertEquals(PrincipalType.ROLE, grantDesc.getPrincipalDesc().getType());
    Assert.assertEquals(ROLE, grantDesc.getPrincipalDesc().getName());
    Assert.assertTrue("Expected table", grantDesc.getHiveObj().getTable());
    Assert.assertEquals(TABLE_QNAME, grantDesc.getHiveObj().getObject());
    Assert.assertTrue("Expected table", grantDesc.getHiveObj().getTable());
}
Also used : DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) ShowGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc) Test(org.junit.Test)

Example 2 with ShowGrantDesc

use of org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc in project hive by apache.

the class TestHiveAuthorizationTaskFactory method testShowGrantUserOnTable.

/**
 * SHOW GRANT USER ... ON TABLE ...
 */
@Test
public void testShowGrantUserOnTable() throws Exception {
    DDLWork work = analyze("SHOW GRANT USER " + USER + " ON TABLE " + TABLE);
    ShowGrantDesc grantDesc = (ShowGrantDesc) work.getDDLDesc();
    Assert.assertNotNull("Show grant should not be null", grantDesc);
    Assert.assertEquals(PrincipalType.USER, grantDesc.getPrincipalDesc().getType());
    Assert.assertEquals(USER, grantDesc.getPrincipalDesc().getName());
    Assert.assertTrue("Expected table", grantDesc.getHiveObj().getTable());
    Assert.assertEquals(TABLE_QNAME, grantDesc.getHiveObj().getObject());
    Assert.assertTrue("Expected table", grantDesc.getHiveObj().getTable());
}
Also used : DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) ShowGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc) Test(org.junit.Test)

Example 3 with ShowGrantDesc

use of org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc in project hive by apache.

the class TestHiveAuthorizationTaskFactory method testShowGrantGroupOnTable.

/**
 * SHOW GRANT GROUP ... ON TABLE ...
 */
@Test
public void testShowGrantGroupOnTable() throws Exception {
    DDLWork work = analyze("SHOW GRANT GROUP " + GROUP + " ON TABLE " + TABLE);
    ShowGrantDesc grantDesc = (ShowGrantDesc) work.getDDLDesc();
    Assert.assertNotNull("Show grant should not be null", grantDesc);
    Assert.assertEquals(PrincipalType.GROUP, grantDesc.getPrincipalDesc().getType());
    Assert.assertEquals(GROUP, grantDesc.getPrincipalDesc().getName());
    Assert.assertTrue("Expected table", grantDesc.getHiveObj().getTable());
    Assert.assertEquals(TABLE_QNAME, grantDesc.getHiveObj().getObject());
    Assert.assertTrue("Expected table", grantDesc.getHiveObj().getTable());
}
Also used : DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) ShowGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc) Test(org.junit.Test)

Example 4 with ShowGrantDesc

use of org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc in project hive by apache.

the class HiveAuthorizationTaskFactoryImpl method createShowGrantTask.

@Override
public Task<?> createShowGrantTask(ASTNode ast, Path resultFile, Set<ReadEntity> inputs, Set<WriteEntity> outputs) throws SemanticException {
    PrincipalDesc principalDesc = null;
    PrivilegeObjectDesc privHiveObj = null;
    ASTNode param = null;
    if (ast.getChildCount() > 0) {
        param = (ASTNode) ast.getChild(0);
        principalDesc = AuthorizationParseUtils.getPrincipalDesc(param);
        if (principalDesc != null) {
            // shift one
            param = (ASTNode) ast.getChild(1);
        }
    }
    if (param != null) {
        if (param.getType() == HiveParser.TOK_RESOURCE_ALL) {
            privHiveObj = new PrivilegeObjectDesc(true, null, null, null);
        } else if (param.getType() == HiveParser.TOK_PRIV_OBJECT_COL) {
            privHiveObj = parsePrivObject(param);
        }
    }
    ShowGrantDesc showGrant = new ShowGrantDesc(resultFile.toString(), principalDesc, privHiveObj);
    return TaskFactory.get(new DDLWork(inputs, outputs, showGrant));
}
Also used : PrincipalDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) PrivilegeObjectDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeObjectDesc) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) ShowGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc)

Aggregations

DDLWork (org.apache.hadoop.hive.ql.ddl.DDLWork)4 ShowGrantDesc (org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc)4 Test (org.junit.Test)3 PrincipalDesc (org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc)1 PrivilegeObjectDesc (org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeObjectDesc)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1