Search in sources :

Example 16 with PrincipalPrivilegeSet

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

the class ObjectStore method listPartitionsPsWithAuth.

@Override
public List<Partition> listPartitionsPsWithAuth(String db_name, String tbl_name, List<String> part_vals, short max_parts, String userName, List<String> groupNames) throws MetaException, InvalidObjectException, NoSuchObjectException {
    List<Partition> partitions = new ArrayList<Partition>();
    boolean success = false;
    QueryWrapper queryWrapper = new QueryWrapper();
    try {
        openTransaction();
        LOG.debug("executing listPartitionNamesPsWithAuth");
        Collection parts = getPartitionPsQueryResults(db_name, tbl_name, part_vals, max_parts, null, queryWrapper);
        MTable mtbl = getMTable(db_name, tbl_name);
        for (Object o : parts) {
            Partition part = convertToPart((MPartition) o);
            //set auth privileges
            if (null != userName && null != groupNames && "TRUE".equalsIgnoreCase(mtbl.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))) {
                String partName = Warehouse.makePartName(this.convertToFieldSchemas(mtbl.getPartitionKeys()), part.getValues());
                PrincipalPrivilegeSet partAuth = getPartitionPrivilegeSet(db_name, tbl_name, partName, userName, groupNames);
                part.setPrivileges(partAuth);
            }
            partitions.add(part);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        queryWrapper.close();
    }
    return partitions;
}
Also used : MPartition(org.apache.hadoop.hive.metastore.model.MPartition) Partition(org.apache.hadoop.hive.metastore.api.Partition) MTable(org.apache.hadoop.hive.metastore.model.MTable) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 17 with PrincipalPrivilegeSet

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

the class ObjectStore method getPartitionPrivilegeSet.

@Override
public PrincipalPrivilegeSet getPartitionPrivilegeSet(String dbName, String tableName, String partition, String userName, List<String> groupNames) throws InvalidObjectException, MetaException {
    boolean commited = false;
    PrincipalPrivilegeSet ret = new PrincipalPrivilegeSet();
    tableName = HiveStringUtils.normalizeIdentifier(tableName);
    dbName = HiveStringUtils.normalizeIdentifier(dbName);
    try {
        openTransaction();
        if (userName != null) {
            Map<String, List<PrivilegeGrantInfo>> partUserPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            partUserPriv.put(userName, getPartitionPrivilege(dbName, tableName, partition, userName, PrincipalType.USER));
            ret.setUserPrivileges(partUserPriv);
        }
        if (groupNames != null && groupNames.size() > 0) {
            Map<String, List<PrivilegeGrantInfo>> partGroupPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            for (String groupName : groupNames) {
                partGroupPriv.put(groupName, getPartitionPrivilege(dbName, tableName, partition, groupName, PrincipalType.GROUP));
            }
            ret.setGroupPrivileges(partGroupPriv);
        }
        Set<String> roleNames = listAllRolesInHierarchy(userName, groupNames);
        if (roleNames != null && roleNames.size() > 0) {
            Map<String, List<PrivilegeGrantInfo>> partRolePriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            for (String roleName : roleNames) {
                partRolePriv.put(roleName, getPartitionPrivilege(dbName, tableName, partition, roleName, PrincipalType.ROLE));
            }
            ret.setRolePrivileges(partRolePriv);
        }
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 18 with PrincipalPrivilegeSet

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

the class HBaseStore method listDBGrantsAll.

@Override
public List<HiveObjectPrivilege> listDBGrantsAll(String dbName) {
    List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
    boolean commit = false;
    openTransaction();
    try {
        Database db = getHBase().getDb(dbName);
        PrincipalPrivilegeSet pps = db.getPrivileges();
        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.DATABASE, dbName, 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.DATABASE, dbName, 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) Database(org.apache.hadoop.hive.metastore.api.Database) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 19 with PrincipalPrivilegeSet

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

the class HBaseStore method listPrincipalGlobalGrants.

@Override
public List<HiveObjectPrivilege> listPrincipalGlobalGrants(String principalName, PrincipalType principalType) {
    List<PrivilegeGrantInfo> grants;
    List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
    boolean commit = false;
    openTransaction();
    try {
        PrincipalPrivilegeSet pps = getHBase().getGlobalPrivs();
        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.GLOBAL, null, null, null, null), principalName, principalType, 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)

Example 20 with PrincipalPrivilegeSet

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

the class HBaseStore method listTableGrantsAll.

@Override
public List<HiveObjectPrivilege> listTableGrantsAll(String dbName, String tableName) {
    List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
    boolean commit = false;
    openTransaction();
    try {
        Table table = getHBase().getTable(dbName, tableName);
        PrincipalPrivilegeSet pps = table.getPrivileges();
        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.TABLE, dbName, tableName, 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.TABLE, dbName, tableName, null, null), e.getKey(), PrincipalType.ROLE, 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) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

PrincipalPrivilegeSet (org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet)27 ArrayList (java.util.ArrayList)19 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)17 List (java.util.List)15 LinkedList (java.util.LinkedList)14 IOException (java.io.IOException)13 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)10 HashMap (java.util.HashMap)9 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)9 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)6 Table (org.apache.hadoop.hive.metastore.api.Table)6 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)6 Database (org.apache.hadoop.hive.metastore.api.Database)5 Map (java.util.Map)4 MTable (org.apache.hadoop.hive.metastore.model.MTable)4 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)3 Partition (org.apache.hadoop.hive.metastore.api.Partition)3 MPartition (org.apache.hadoop.hive.metastore.model.MPartition)3 TException (org.apache.thrift.TException)3 FileNotFoundException (java.io.FileNotFoundException)2