use of org.apache.hadoop.hive.metastore.model.MGlobalPrivilege 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;
}
use of org.apache.hadoop.hive.metastore.model.MGlobalPrivilege 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;
}
use of org.apache.hadoop.hive.metastore.model.MGlobalPrivilege in project hive by apache.
the class ObjectStore method listPrincipalMGlobalGrants.
@SuppressWarnings("unchecked")
public List<MGlobalPrivilege> listPrincipalMGlobalGrants(String principalName, PrincipalType principalType) {
boolean commited = false;
Query query = null;
List<MGlobalPrivilege> userNameDbPriv = new ArrayList<MGlobalPrivilege>();
try {
List<MGlobalPrivilege> mPrivs = null;
openTransaction();
if (principalName != null) {
query = pm.newQuery(MGlobalPrivilege.class, "principalName == t1 && principalType == t2 ");
query.declareParameters("java.lang.String t1, java.lang.String t2");
mPrivs = (List<MGlobalPrivilege>) query.executeWithArray(principalName, principalType.toString());
pm.retrieveAll(mPrivs);
}
commited = commitTransaction();
if (mPrivs != null) {
userNameDbPriv.addAll(mPrivs);
}
} finally {
if (!commited) {
rollbackTransaction();
}
if (query != null) {
query.closeAll();
}
}
return userNameDbPriv;
}
Aggregations