Search in sources :

Example 6 with MDBPrivilege

use of org.apache.hadoop.hive.metastore.model.MDBPrivilege in project hive by apache.

the class ObjectStore method removeRole.

@Override
public boolean removeRole(String roleName) throws MetaException, NoSuchObjectException {
    boolean success = false;
    QueryWrapper queryWrapper = new QueryWrapper();
    try {
        openTransaction();
        MRole mRol = getMRole(roleName);
        pm.retrieve(mRol);
        if (mRol != null) {
            // first remove all the membership, the membership that this role has
            // been granted
            List<MRoleMap> roleMap = listMRoleMembers(mRol.getRoleName());
            if (roleMap.size() > 0) {
                pm.deletePersistentAll(roleMap);
            }
            List<MRoleMap> roleMember = listMSecurityPrincipalMembershipRole(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (roleMember.size() > 0) {
                pm.deletePersistentAll(roleMember);
            }
            queryWrapper.close();
            // then remove all the grants
            List<MGlobalPrivilege> userGrants = listPrincipalMGlobalGrants(mRol.getRoleName(), PrincipalType.ROLE);
            if (userGrants.size() > 0) {
                pm.deletePersistentAll(userGrants);
            }
            List<MDBPrivilege> dbGrants = listPrincipalAllDBGrant(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (dbGrants.size() > 0) {
                pm.deletePersistentAll(dbGrants);
            }
            queryWrapper.close();
            List<MTablePrivilege> tabPartGrants = listPrincipalAllTableGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (tabPartGrants.size() > 0) {
                pm.deletePersistentAll(tabPartGrants);
            }
            queryWrapper.close();
            List<MPartitionPrivilege> partGrants = listPrincipalAllPartitionGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (partGrants.size() > 0) {
                pm.deletePersistentAll(partGrants);
            }
            queryWrapper.close();
            List<MTableColumnPrivilege> tblColumnGrants = listPrincipalAllTableColumnGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (tblColumnGrants.size() > 0) {
                pm.deletePersistentAll(tblColumnGrants);
            }
            queryWrapper.close();
            List<MPartitionColumnPrivilege> partColumnGrants = listPrincipalAllPartitionColumnGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (partColumnGrants.size() > 0) {
                pm.deletePersistentAll(partColumnGrants);
            }
            queryWrapper.close();
            // finally remove the role
            pm.deletePersistent(mRol);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        queryWrapper.close();
    }
    return success;
}
Also used : MRole(org.apache.hadoop.hive.metastore.model.MRole) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MDBPrivilege(org.apache.hadoop.hive.metastore.model.MDBPrivilege) MGlobalPrivilege(org.apache.hadoop.hive.metastore.model.MGlobalPrivilege) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)

Example 7 with MDBPrivilege

use of org.apache.hadoop.hive.metastore.model.MDBPrivilege 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)

Example 8 with MDBPrivilege

use of org.apache.hadoop.hive.metastore.model.MDBPrivilege in project hive by apache.

the class ObjectStore method getDBPrivilege.

public List<PrivilegeGrantInfo> getDBPrivilege(String dbName, String principalName, PrincipalType principalType) throws InvalidObjectException, MetaException {
    dbName = HiveStringUtils.normalizeIdentifier(dbName);
    if (principalName != null) {
        List<MDBPrivilege> userNameDbPriv = this.listPrincipalMDBGrants(principalName, principalType, dbName);
        if (userNameDbPriv != null && userNameDbPriv.size() > 0) {
            List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(userNameDbPriv.size());
            for (int i = 0; i < userNameDbPriv.size(); i++) {
                MDBPrivilege item = userNameDbPriv.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) MDBPrivilege(org.apache.hadoop.hive.metastore.model.MDBPrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 9 with MDBPrivilege

use of org.apache.hadoop.hive.metastore.model.MDBPrivilege in project hive by apache.

the class ObjectStore method listPrincipalDBGrants.

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

Example 10 with MDBPrivilege

use of org.apache.hadoop.hive.metastore.model.MDBPrivilege in project hive by apache.

the class ObjectStore method dropDatabase.

@Override
public boolean dropDatabase(String dbname) throws NoSuchObjectException, MetaException {
    boolean success = false;
    LOG.info("Dropping database " + dbname + " along with all tables");
    dbname = HiveStringUtils.normalizeIdentifier(dbname);
    QueryWrapper queryWrapper = new QueryWrapper();
    try {
        openTransaction();
        // then drop the database
        MDatabase db = getMDatabase(dbname);
        pm.retrieve(db);
        if (db != null) {
            List<MDBPrivilege> dbGrants = this.listDatabaseGrants(dbname, queryWrapper);
            if (dbGrants != null && dbGrants.size() > 0) {
                pm.deletePersistentAll(dbGrants);
            }
            pm.deletePersistent(db);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        queryWrapper.close();
    }
    return success;
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) MDBPrivilege(org.apache.hadoop.hive.metastore.model.MDBPrivilege)

Aggregations

MDBPrivilege (org.apache.hadoop.hive.metastore.model.MDBPrivilege)10 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)4 List (java.util.List)4 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)4 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)4 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)4 Query (javax.jdo.Query)3 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)3 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)3 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)3 MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)3 MGlobalPrivilege (org.apache.hadoop.hive.metastore.model.MGlobalPrivilege)3 MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)3 MPartitionPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)3 MTableColumnPrivilege (org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)3 MTablePrivilege (org.apache.hadoop.hive.metastore.model.MTablePrivilege)3 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)2 MTable (org.apache.hadoop.hive.metastore.model.MTable)2 HashSet (java.util.HashSet)1