Search in sources :

Example 1 with GrantDesc

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

the class TestHiveAuthorizationTaskFactory method testGrantGroupTable.

/**
 * GRANT ... ON TABLE ... TO GROUP ...
 */
@Test
public void testGrantGroupTable() throws Exception {
    DDLWork work = analyze("GRANT " + SELECT + " ON TABLE " + TABLE + " TO GROUP " + GROUP);
    GrantDesc grantDesc = (GrantDesc) work.getDDLDesc();
    Assert.assertNotNull("Grant should not be null", grantDesc);
    for (PrincipalDesc principal : ListSizeMatcher.inList(grantDesc.getPrincipals()).ofSize(1)) {
        Assert.assertEquals(PrincipalType.GROUP, principal.getType());
        Assert.assertEquals(GROUP, principal.getName());
    }
    for (PrivilegeDesc privilege : ListSizeMatcher.inList(grantDesc.getPrivileges()).ofSize(1)) {
        Assert.assertEquals(Privilege.SELECT, privilege.getPrivilege());
    }
    Assert.assertTrue("Expected table", grantDesc.getPrivilegeSubject().getTable());
    Assert.assertEquals(TABLE_QNAME, grantDesc.getPrivilegeSubject().getObject());
}
Also used : PrincipalDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) GrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.grant.GrantDesc) ShowRoleGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.rolegrant.ShowRoleGrantDesc) ShowGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc) PrivilegeDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeDesc) Test(org.junit.Test)

Example 2 with GrantDesc

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

the class TestHiveAuthorizationTaskFactory method testGrantUserTable.

/**
 * GRANT ... ON TABLE ... TO USER ...
 */
@Test
public void testGrantUserTable() throws Exception {
    DDLWork work = analyze("GRANT " + SELECT + " ON TABLE " + TABLE + " TO USER " + USER);
    GrantDesc grantDesc = (GrantDesc) work.getDDLDesc();
    Assert.assertNotNull("Grant should not be null", grantDesc);
    for (PrincipalDesc principal : ListSizeMatcher.inList(grantDesc.getPrincipals()).ofSize(1)) {
        Assert.assertEquals(PrincipalType.USER, principal.getType());
        Assert.assertEquals(USER, principal.getName());
    }
    for (PrivilegeDesc privilege : ListSizeMatcher.inList(grantDesc.getPrivileges()).ofSize(1)) {
        Assert.assertEquals(Privilege.SELECT, privilege.getPrivilege());
    }
    Assert.assertTrue("Expected table", grantDesc.getPrivilegeSubject().getTable());
    Assert.assertEquals(TABLE_QNAME, grantDesc.getPrivilegeSubject().getObject());
}
Also used : PrincipalDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) GrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.grant.GrantDesc) ShowRoleGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.rolegrant.ShowRoleGrantDesc) ShowGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc) PrivilegeDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeDesc) Test(org.junit.Test)

Example 3 with GrantDesc

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

the class TestHiveAuthorizationTaskFactory method testGrantRoleTable.

/**
 * GRANT ... ON TABLE ... TO ROLE ...
 */
@Test
public void testGrantRoleTable() throws Exception {
    DDLWork work = analyze("GRANT " + SELECT + " ON TABLE " + TABLE + " TO ROLE " + ROLE);
    GrantDesc grantDesc = (GrantDesc) work.getDDLDesc();
    Assert.assertNotNull("Grant should not be null", grantDesc);
    for (PrincipalDesc principal : ListSizeMatcher.inList(grantDesc.getPrincipals()).ofSize(1)) {
        Assert.assertEquals(PrincipalType.ROLE, principal.getType());
        Assert.assertEquals(ROLE, principal.getName());
    }
    for (PrivilegeDesc privilege : ListSizeMatcher.inList(grantDesc.getPrivileges()).ofSize(1)) {
        Assert.assertEquals(Privilege.SELECT, privilege.getPrivilege());
    }
    Assert.assertTrue("Expected table", grantDesc.getPrivilegeSubject().getTable());
    Assert.assertEquals(TABLE_QNAME, grantDesc.getPrivilegeSubject().getObject());
}
Also used : PrincipalDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) GrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.grant.GrantDesc) ShowRoleGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.rolegrant.ShowRoleGrantDesc) ShowGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc) PrivilegeDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeDesc) Test(org.junit.Test)

Example 4 with GrantDesc

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

the class HiveAuthorizationTaskFactoryImpl method createGrantTask.

@Override
public Task<?> createGrantTask(ASTNode ast, Set<ReadEntity> inputs, Set<WriteEntity> outputs) throws SemanticException {
    List<PrivilegeDesc> privilegeDesc = analyzePrivilegeListDef((ASTNode) ast.getChild(0));
    List<PrincipalDesc> principalDesc = AuthorizationParseUtils.analyzePrincipalListDef((ASTNode) ast.getChild(1));
    boolean grantOption = false;
    PrivilegeObjectDesc privilegeObj = null;
    if (ast.getChildCount() > 2) {
        for (int i = 2; i < ast.getChildCount(); i++) {
            ASTNode astChild = (ASTNode) ast.getChild(i);
            if (astChild.getType() == HiveParser.TOK_GRANT_WITH_OPTION) {
                grantOption = true;
            } else if (astChild.getType() == HiveParser.TOK_PRIV_OBJECT) {
                privilegeObj = analyzePrivilegeObject(astChild, outputs);
            }
        }
    }
    String userName = SessionState.getUserFromAuthenticator();
    GrantDesc grantDesc = new GrantDesc(privilegeObj, privilegeDesc, principalDesc, userName, PrincipalType.USER, grantOption);
    return TaskFactory.get(new DDLWork(inputs, outputs, grantDesc));
}
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) GrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.grant.GrantDesc) ShowRoleGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.rolegrant.ShowRoleGrantDesc) ShowGrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc) PrivilegeDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeDesc)

Example 5 with GrantDesc

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

the class PrivilegesTestBase method grantUserTable.

public static void grantUserTable(String privStr, PrivilegeType privType, QueryState queryState, Hive db) throws Exception {
    Context ctx = new Context(new HiveConf());
    DDLWork work = AuthorizationTestUtil.analyze("GRANT " + privStr + " ON TABLE " + TABLE + " TO USER " + USER, queryState, db, ctx);
    GrantDesc grantDesc = (GrantDesc) work.getDDLDesc();
    Assert.assertNotNull("Grant should not be null", grantDesc);
    // check privileges
    for (PrivilegeDesc privilege : ListSizeMatcher.inList(grantDesc.getPrivileges()).ofSize(1)) {
        Assert.assertEquals(privType, privilege.getPrivilege().getPriv());
    }
    // check other parts
    for (PrincipalDesc principal : ListSizeMatcher.inList(grantDesc.getPrincipals()).ofSize(1)) {
        Assert.assertEquals(PrincipalType.USER, principal.getType());
        Assert.assertEquals(USER, principal.getName());
    }
    Assert.assertTrue("Expected table", grantDesc.getPrivilegeSubject().getTable());
    Assert.assertEquals(TABLE_QNAME, grantDesc.getPrivilegeSubject().getObject());
}
Also used : Context(org.apache.hadoop.hive.ql.Context) PrincipalDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) GrantDesc(org.apache.hadoop.hive.ql.ddl.privilege.grant.GrantDesc) HiveConf(org.apache.hadoop.hive.conf.HiveConf) PrivilegeDesc(org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeDesc)

Aggregations

DDLWork (org.apache.hadoop.hive.ql.ddl.DDLWork)5 PrincipalDesc (org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc)5 PrivilegeDesc (org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeDesc)5 GrantDesc (org.apache.hadoop.hive.ql.ddl.privilege.grant.GrantDesc)5 ShowGrantDesc (org.apache.hadoop.hive.ql.ddl.privilege.show.grant.ShowGrantDesc)4 ShowRoleGrantDesc (org.apache.hadoop.hive.ql.ddl.privilege.show.rolegrant.ShowRoleGrantDesc)4 Test (org.junit.Test)3 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 Context (org.apache.hadoop.hive.ql.Context)1 PrivilegeObjectDesc (org.apache.hadoop.hive.ql.ddl.privilege.PrivilegeObjectDesc)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1