Search in sources :

Example 6 with PrivilegeGrantInfo

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

the class ObjectStore method convertGlobal.

private List<HiveObjectPrivilege> convertGlobal(List<MGlobalPrivilege> privs) {
    List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
    for (MGlobalPrivilege priv : privs) {
        String pname = priv.getPrincipalName();
        PrincipalType ptype = PrincipalType.valueOf(priv.getPrincipalType());
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.GLOBAL, null, null, null, null);
        PrivilegeGrantInfo grantor = new PrivilegeGrantInfo(priv.getPrivilege(), priv.getCreateTime(), priv.getGrantor(), PrincipalType.valueOf(priv.getGrantorType()), priv.getGrantOption());
        result.add(new HiveObjectPrivilege(objectRef, pname, ptype, grantor));
    }
    return result;
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) MGlobalPrivilege(org.apache.hadoop.hive.metastore.model.MGlobalPrivilege) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Example 7 with PrivilegeGrantInfo

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

the class ObjectStore method getTablePrivilege.

private List<PrivilegeGrantInfo> getTablePrivilege(String dbName, String tableName, String principalName, PrincipalType principalType) {
    tableName = HiveStringUtils.normalizeIdentifier(tableName);
    dbName = HiveStringUtils.normalizeIdentifier(dbName);
    if (principalName != null) {
        List<MTablePrivilege> userNameTabPartPriv = this.listAllMTableGrants(principalName, principalType, dbName, tableName);
        if (userNameTabPartPriv != null && userNameTabPartPriv.size() > 0) {
            List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(userNameTabPartPriv.size());
            for (int i = 0; i < userNameTabPartPriv.size(); i++) {
                MTablePrivilege item = userNameTabPartPriv.get(i);
                grantInfos.add(new PrivilegeGrantInfo(item.getPrivilege(), item.getCreateTime(), item.getGrantor(), getPrincipalTypeFromStr(item.getGrantorType()), item.getGrantOption()));
            }
            return grantInfos;
        }
    }
    return new ArrayList<PrivilegeGrantInfo>(0);
}
Also used : PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) ArrayList(java.util.ArrayList) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 8 with PrivilegeGrantInfo

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

the class ObjectStore method getColumnPrivilegeSet.

@Override
public PrincipalPrivilegeSet getColumnPrivilegeSet(String dbName, String tableName, String partitionName, String columnName, String userName, List<String> groupNames) throws InvalidObjectException, MetaException {
    tableName = HiveStringUtils.normalizeIdentifier(tableName);
    dbName = HiveStringUtils.normalizeIdentifier(dbName);
    columnName = HiveStringUtils.normalizeIdentifier(columnName);
    boolean commited = false;
    PrincipalPrivilegeSet ret = new PrincipalPrivilegeSet();
    try {
        openTransaction();
        if (userName != null) {
            Map<String, List<PrivilegeGrantInfo>> columnUserPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            columnUserPriv.put(userName, getColumnPrivilege(dbName, tableName, columnName, partitionName, userName, PrincipalType.USER));
            ret.setUserPrivileges(columnUserPriv);
        }
        if (groupNames != null && groupNames.size() > 0) {
            Map<String, List<PrivilegeGrantInfo>> columnGroupPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            for (String groupName : groupNames) {
                columnGroupPriv.put(groupName, getColumnPrivilege(dbName, tableName, columnName, partitionName, groupName, PrincipalType.GROUP));
            }
            ret.setGroupPrivileges(columnGroupPriv);
        }
        Set<String> roleNames = listAllRolesInHierarchy(userName, groupNames);
        if (roleNames != null && roleNames.size() > 0) {
            Map<String, List<PrivilegeGrantInfo>> columnRolePriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            for (String roleName : roleNames) {
                columnRolePriv.put(roleName, getColumnPrivilege(dbName, tableName, columnName, partitionName, roleName, PrincipalType.ROLE));
            }
            ret.setRolePrivileges(columnRolePriv);
        }
        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 9 with PrivilegeGrantInfo

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

the class ObjectStore method convertPartition.

private List<HiveObjectPrivilege> convertPartition(List<MPartitionPrivilege> privs) {
    List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
    for (MPartitionPrivilege priv : privs) {
        String pname = priv.getPrincipalName();
        PrincipalType ptype = PrincipalType.valueOf(priv.getPrincipalType());
        MPartition mpartition = priv.getPartition();
        MTable mtable = mpartition.getTable();
        MDatabase mdatabase = mtable.getDatabase();
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.PARTITION, mdatabase.getName(), mtable.getTableName(), mpartition.getValues(), null);
        PrivilegeGrantInfo grantor = new PrivilegeGrantInfo(priv.getPrivilege(), priv.getCreateTime(), priv.getGrantor(), PrincipalType.valueOf(priv.getGrantorType()), priv.getGrantOption());
        result.add(new HiveObjectPrivilege(objectRef, pname, ptype, grantor));
    }
    return result;
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) MTable(org.apache.hadoop.hive.metastore.model.MTable) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 10 with PrivilegeGrantInfo

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

the class ObjectStore method getTablePrivilegeSet.

@Override
public PrincipalPrivilegeSet getTablePrivilegeSet(String dbName, String tableName, 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>> tableUserPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            tableUserPriv.put(userName, getTablePrivilege(dbName, tableName, userName, PrincipalType.USER));
            ret.setUserPrivileges(tableUserPriv);
        }
        if (groupNames != null && groupNames.size() > 0) {
            Map<String, List<PrivilegeGrantInfo>> tableGroupPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            for (String groupName : groupNames) {
                tableGroupPriv.put(groupName, getTablePrivilege(dbName, tableName, groupName, PrincipalType.GROUP));
            }
            ret.setGroupPrivileges(tableGroupPriv);
        }
        Set<String> roleNames = listAllRolesInHierarchy(userName, groupNames);
        if (roleNames != null && roleNames.size() > 0) {
            Map<String, List<PrivilegeGrantInfo>> tableRolePriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            for (String roleName : roleNames) {
                tableRolePriv.put(roleName, getTablePrivilege(dbName, tableName, roleName, PrincipalType.ROLE));
            }
            ret.setRolePrivileges(tableRolePriv);
        }
        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)

Aggregations

PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)49 ArrayList (java.util.ArrayList)43 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)31 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)29 PrincipalPrivilegeSet (org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet)17 List (java.util.List)16 LinkedList (java.util.LinkedList)15 IOException (java.io.IOException)12 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)12 HashMap (java.util.HashMap)10 Database (org.apache.hadoop.hive.metastore.api.Database)8 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)8 PrivilegeBag (org.apache.hadoop.hive.metastore.api.PrivilegeBag)7 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 Role (org.apache.hadoop.hive.metastore.api.Role)5 Map (java.util.Map)4 MTablePrivilege (org.apache.hadoop.hive.metastore.model.MTablePrivilege)4 Test (org.junit.Test)4