Search in sources :

Example 11 with HiveObjectRef

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

the class AuthorizationUtils method getPrivilegeInfos.

public static List<HivePrivilegeInfo> getPrivilegeInfos(List<HiveObjectPrivilege> privs) throws HiveException {
    List<HivePrivilegeInfo> hivePrivs = new ArrayList<HivePrivilegeInfo>();
    for (HiveObjectPrivilege priv : privs) {
        PrivilegeGrantInfo grantorInfo = priv.getGrantInfo();
        HiveObjectRef privObject = priv.getHiveObject();
        HivePrincipal hivePrincipal = getHivePrincipal(priv.getPrincipalName(), priv.getPrincipalType());
        HivePrincipal grantor = getHivePrincipal(grantorInfo.getGrantor(), grantorInfo.getGrantorType());
        HivePrivilegeObject object = getHiveObjectRef(privObject);
        HivePrivilege privilege = new HivePrivilege(grantorInfo.getPrivilege(), null);
        hivePrivs.add(new HivePrivilegeInfo(hivePrincipal, privilege, object, grantor, grantorInfo.isGrantOption(), grantorInfo.getCreateTime()));
    }
    return hivePrivs;
}
Also used : HivePrivilegeInfo(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeInfo) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HivePrincipal(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrincipal) HivePrivilege(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilege) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) HivePrivilegeObject(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject)

Example 12 with HiveObjectRef

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

the class HBaseStore method listPrincipalTableGrantsAll.

@Override
public List<HiveObjectPrivilege> listPrincipalTableGrantsAll(String principalName, PrincipalType principalType) {
    List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
    boolean commit = false;
    openTransaction();
    try {
        List<Table> tables = getHBase().scanTables(null, null);
        for (Table table : tables) {
            List<PrivilegeGrantInfo> grants;
            PrincipalPrivilegeSet pps = table.getPrivileges();
            if (pps == null)
                continue;
            Map<String, List<PrivilegeGrantInfo>> map;
            switch(principalType) {
                case USER:
                    map = pps.getUserPrivileges();
                    break;
                case ROLE:
                    map = pps.getRolePrivileges();
                    break;
                default:
                    throw new RuntimeException("Unknown or unsupported principal type " + principalType.toString());
            }
            if (map == null)
                continue;
            grants = map.get(principalName);
            if (grants == null || grants.size() == 0)
                continue;
            for (PrivilegeGrantInfo pgi : grants) {
                privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.TABLE, table.getDbName(), table.getTableName(), null, null), principalName, principalType, pgi));
            }
        }
        commit = true;
        return privileges;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 13 with HiveObjectRef

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

the class HBaseStore method listAllTableGrants.

@Override
public List<HiveObjectPrivilege> listAllTableGrants(String principalName, PrincipalType principalType, String dbName, String tableName) {
    List<PrivilegeGrantInfo> grants;
    List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
    boolean commit = false;
    openTransaction();
    try {
        Table table = getHBase().getTable(dbName, tableName);
        if (table == null)
            return privileges;
        PrincipalPrivilegeSet pps = table.getPrivileges();
        if (pps == null)
            return privileges;
        Map<String, List<PrivilegeGrantInfo>> map;
        switch(principalType) {
            case USER:
                map = pps.getUserPrivileges();
                break;
            case ROLE:
                map = pps.getRolePrivileges();
                break;
            default:
                throw new RuntimeException("Unknown or unsupported principal type " + principalType.toString());
        }
        if (map == null)
            return privileges;
        grants = map.get(principalName);
        if (grants == null || grants.size() == 0)
            return privileges;
        for (PrivilegeGrantInfo pgi : grants) {
            privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.TABLE, dbName, tableName, null, null), principalName, principalType, pgi));
        }
        commit = true;
        return privileges;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 14 with HiveObjectRef

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

the class HBaseStore method listGlobalGrantsAll.

@Override
public List<HiveObjectPrivilege> listGlobalGrantsAll() {
    List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
    boolean commit = false;
    openTransaction();
    try {
        PrincipalPrivilegeSet pps = getHBase().getGlobalPrivs();
        if (pps != null) {
            for (Map.Entry<String, List<PrivilegeGrantInfo>> e : pps.getUserPrivileges().entrySet()) {
                for (PrivilegeGrantInfo pgi : e.getValue()) {
                    privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.GLOBAL, null, null, null, null), e.getKey(), PrincipalType.USER, pgi));
                }
            }
            for (Map.Entry<String, List<PrivilegeGrantInfo>> e : pps.getRolePrivileges().entrySet()) {
                for (PrivilegeGrantInfo pgi : e.getValue()) {
                    privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.GLOBAL, null, null, null, null), e.getKey(), PrincipalType.ROLE, pgi));
                }
            }
        }
        commit = true;
        return privileges;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with HiveObjectRef

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

the class AbstractTestAuthorizationApiAuthorizer method testListPriv.

@Test
public void testListPriv() throws Exception {
    FunctionInvoker invoker = new FunctionInvoker() {

        @Override
        public void invoke() throws Exception {
            msc.list_privileges(null, PrincipalType.USER, new HiveObjectRef());
        }
    };
    testFunction(invoker);
}
Also used : HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) Test(org.junit.Test)

Aggregations

HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)34 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)31 ArrayList (java.util.ArrayList)29 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)29 List (java.util.List)11 LinkedList (java.util.LinkedList)10 PrincipalPrivilegeSet (org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet)10 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)10 IOException (java.io.IOException)8 Database (org.apache.hadoop.hive.metastore.api.Database)7 PrivilegeBag (org.apache.hadoop.hive.metastore.api.PrivilegeBag)7 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)7 Table (org.apache.hadoop.hive.metastore.api.Table)6 Test (org.junit.Test)6 Role (org.apache.hadoop.hive.metastore.api.Role)5 MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)5 MTable (org.apache.hadoop.hive.metastore.model.MTable)5 MDBPrivilege (org.apache.hadoop.hive.metastore.model.MDBPrivilege)4 MGlobalPrivilege (org.apache.hadoop.hive.metastore.model.MGlobalPrivilege)4 MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)4