Search in sources :

Example 26 with PrivilegeGrantInfo

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

the class ObjectStore method getColumnPrivilege.

private List<PrivilegeGrantInfo> getColumnPrivilege(String dbName, String tableName, String columnName, String partitionName, String principalName, PrincipalType principalType) {
    tableName = HiveStringUtils.normalizeIdentifier(tableName);
    dbName = HiveStringUtils.normalizeIdentifier(dbName);
    columnName = HiveStringUtils.normalizeIdentifier(columnName);
    if (partitionName == null) {
        List<MTableColumnPrivilege> userNameColumnPriv = this.listPrincipalMTableColumnGrants(principalName, principalType, dbName, tableName, columnName);
        if (userNameColumnPriv != null && userNameColumnPriv.size() > 0) {
            List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(userNameColumnPriv.size());
            for (int i = 0; i < userNameColumnPriv.size(); i++) {
                MTableColumnPrivilege item = userNameColumnPriv.get(i);
                grantInfos.add(new PrivilegeGrantInfo(item.getPrivilege(), item.getCreateTime(), item.getGrantor(), getPrincipalTypeFromStr(item.getGrantorType()), item.getGrantOption()));
            }
            return grantInfos;
        }
    } else {
        List<MPartitionColumnPrivilege> userNameColumnPriv = this.listPrincipalMPartitionColumnGrants(principalName, principalType, dbName, tableName, partitionName, columnName);
        if (userNameColumnPriv != null && userNameColumnPriv.size() > 0) {
            List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(userNameColumnPriv.size());
            for (int i = 0; i < userNameColumnPriv.size(); i++) {
                MPartitionColumnPrivilege item = userNameColumnPriv.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) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 27 with PrivilegeGrantInfo

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

the class ObjectStore method getDBPrivilegeSet.

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

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

the class ObjectStore method getUserPrivilegeSet.

@Override
public PrincipalPrivilegeSet getUserPrivilegeSet(String userName, List<String> groupNames) throws InvalidObjectException, MetaException {
    boolean commited = false;
    PrincipalPrivilegeSet ret = new PrincipalPrivilegeSet();
    try {
        openTransaction();
        if (userName != null) {
            List<MGlobalPrivilege> user = this.listPrincipalMGlobalGrants(userName, PrincipalType.USER);
            if (user.size() > 0) {
                Map<String, List<PrivilegeGrantInfo>> userPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
                List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(user.size());
                for (int i = 0; i < user.size(); i++) {
                    MGlobalPrivilege item = user.get(i);
                    grantInfos.add(new PrivilegeGrantInfo(item.getPrivilege(), item.getCreateTime(), item.getGrantor(), getPrincipalTypeFromStr(item.getGrantorType()), item.getGrantOption()));
                }
                userPriv.put(userName, grantInfos);
                ret.setUserPrivileges(userPriv);
            }
        }
        if (groupNames != null && groupNames.size() > 0) {
            Map<String, List<PrivilegeGrantInfo>> groupPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
            for (String groupName : groupNames) {
                List<MGlobalPrivilege> group = this.listPrincipalMGlobalGrants(groupName, PrincipalType.GROUP);
                if (group.size() > 0) {
                    List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(group.size());
                    for (int i = 0; i < group.size(); i++) {
                        MGlobalPrivilege item = group.get(i);
                        grantInfos.add(new PrivilegeGrantInfo(item.getPrivilege(), item.getCreateTime(), item.getGrantor(), getPrincipalTypeFromStr(item.getGrantorType()), item.getGrantOption()));
                    }
                    groupPriv.put(groupName, grantInfos);
                }
            }
            ret.setGroupPrivileges(groupPriv);
        }
        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) ArrayList(java.util.ArrayList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MGlobalPrivilege(org.apache.hadoop.hive.metastore.model.MGlobalPrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 29 with PrivilegeGrantInfo

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

the class ObjectStore method listAllTableGrants.

@Override
public List<HiveObjectPrivilege> listAllTableGrants(String principalName, PrincipalType principalType, String dbName, String tableName) {
    List<MTablePrivilege> mTbls = listAllMTableGrants(principalName, principalType, dbName, tableName);
    if (mTbls.isEmpty()) {
        return Collections.<HiveObjectPrivilege>emptyList();
    }
    List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
    for (int i = 0; i < mTbls.size(); i++) {
        MTablePrivilege sTbl = mTbls.get(i);
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.TABLE, dbName, tableName, null, null);
        HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef, sTbl.getPrincipalName(), principalType, new PrivilegeGrantInfo(sTbl.getPrivilege(), sTbl.getCreateTime(), sTbl.getGrantor(), PrincipalType.valueOf(sTbl.getGrantorType()), sTbl.getGrantOption()));
        result.add(secObj);
    }
    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) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 30 with PrivilegeGrantInfo

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

the class ObjectStore method convertDB.

private List<HiveObjectPrivilege> convertDB(List<MDBPrivilege> privs) {
    List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
    for (MDBPrivilege priv : privs) {
        String pname = priv.getPrincipalName();
        PrincipalType ptype = PrincipalType.valueOf(priv.getPrincipalType());
        String database = priv.getDatabase().getName();
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.DATABASE, database, 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) MDBPrivilege(org.apache.hadoop.hive.metastore.model.MDBPrivilege) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

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