use of org.apache.hadoop.hive.metastore.model.MRole in project hive by apache.
the class ObjectStore method getRole.
@Override
public Role getRole(String roleName) throws NoSuchObjectException {
MRole mRole = this.getMRole(roleName);
if (mRole == null) {
throw new NoSuchObjectException(roleName + " role can not be found.");
}
Role ret = new Role(mRole.getRoleName(), mRole.getCreateTime(), mRole.getOwnerName());
return ret;
}
use of org.apache.hadoop.hive.metastore.model.MRole in project hive by apache.
the class ObjectStore method listRoles.
@Override
public List<Role> listRoles(String principalName, PrincipalType principalType) {
List<Role> result = new ArrayList<>();
List<MRoleMap> roleMaps = listMRoles(principalName, principalType);
if (roleMaps != null) {
for (MRoleMap roleMap : roleMaps) {
MRole mrole = roleMap.getRole();
Role role = new Role(mrole.getRoleName(), mrole.getCreateTime(), mrole.getOwnerName());
result.add(role);
}
}
return result;
}
use of org.apache.hadoop.hive.metastore.model.MRole in project hive by apache.
the class ObjectStore method addRole.
@Override
public boolean addRole(String roleName, String ownerName) throws InvalidObjectException, MetaException, NoSuchObjectException {
boolean success = false;
boolean commited = false;
try {
openTransaction();
MRole nameCheck = this.getMRole(roleName);
if (nameCheck != null) {
throw new InvalidObjectException("Role " + roleName + " already exists.");
}
int now = (int) (System.currentTimeMillis() / 1000);
MRole mRole = new MRole(roleName, now, ownerName);
pm.makePersistent(mRole);
commited = commitTransaction();
success = true;
} finally {
if (!commited) {
rollbackTransaction();
}
}
return success;
}
use of org.apache.hadoop.hive.metastore.model.MRole in project hive by apache.
the class ObjectStore method grantRole.
@Override
public boolean grantRole(Role role, String userName, PrincipalType principalType, String grantor, PrincipalType grantorType, boolean grantOption) throws MetaException, NoSuchObjectException, InvalidObjectException {
boolean success = false;
boolean commited = false;
try {
openTransaction();
MRoleMap roleMap = null;
try {
roleMap = this.getMSecurityUserRoleMap(userName, principalType, role.getRoleName());
} catch (Exception e) {
}
if (roleMap != null) {
throw new InvalidObjectException("Principal " + userName + " already has the role " + role.getRoleName());
}
if (principalType == PrincipalType.ROLE) {
validateRole(userName);
}
MRole mRole = getMRole(role.getRoleName());
long now = System.currentTimeMillis() / 1000;
MRoleMap roleMember = new MRoleMap(userName, principalType.toString(), mRole, (int) now, grantor, grantorType.toString(), grantOption);
pm.makePersistent(roleMember);
commited = commitTransaction();
success = true;
} finally {
if (!commited) {
rollbackTransaction();
}
}
return success;
}
use of org.apache.hadoop.hive.metastore.model.MRole in project hive by apache.
the class ObjectStore method removeRole.
@Override
public boolean removeRole(String roleName) throws MetaException, NoSuchObjectException {
boolean success = false;
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 (CollectionUtils.isNotEmpty(roleMap)) {
pm.deletePersistentAll(roleMap);
}
List<MRoleMap> roleMember = listMSecurityPrincipalMembershipRole(mRol.getRoleName(), PrincipalType.ROLE);
if (CollectionUtils.isNotEmpty(roleMember)) {
pm.deletePersistentAll(roleMember);
}
// then remove all the grants
List<MGlobalPrivilege> userGrants = listPrincipalMGlobalGrants(mRol.getRoleName(), PrincipalType.ROLE);
if (CollectionUtils.isNotEmpty(userGrants)) {
pm.deletePersistentAll(userGrants);
}
List<MDBPrivilege> dbGrants = listPrincipalAllDBGrant(mRol.getRoleName(), PrincipalType.ROLE);
if (CollectionUtils.isNotEmpty(dbGrants)) {
pm.deletePersistentAll(dbGrants);
}
List<MDCPrivilege> dcGrants = listPrincipalAllDCGrant(mRol.getRoleName(), PrincipalType.ROLE);
if (CollectionUtils.isNotEmpty(dcGrants)) {
pm.deletePersistentAll(dcGrants);
}
List<MTablePrivilege> tabPartGrants = listPrincipalAllTableGrants(mRol.getRoleName(), PrincipalType.ROLE);
if (CollectionUtils.isNotEmpty(tabPartGrants)) {
pm.deletePersistentAll(tabPartGrants);
}
List<MPartitionPrivilege> partGrants = listPrincipalAllPartitionGrants(mRol.getRoleName(), PrincipalType.ROLE);
if (CollectionUtils.isNotEmpty(partGrants)) {
pm.deletePersistentAll(partGrants);
}
List<MTableColumnPrivilege> tblColumnGrants = listPrincipalAllTableColumnGrants(mRol.getRoleName(), PrincipalType.ROLE);
if (CollectionUtils.isNotEmpty(tblColumnGrants)) {
pm.deletePersistentAll(tblColumnGrants);
}
List<MPartitionColumnPrivilege> partColumnGrants = listPrincipalAllPartitionColumnGrants(mRol.getRoleName(), PrincipalType.ROLE);
if (CollectionUtils.isNotEmpty(partColumnGrants)) {
pm.deletePersistentAll(partColumnGrants);
}
// finally remove the role
pm.deletePersistent(mRol);
}
success = commitTransaction();
} catch (Exception e) {
throw new MetaException(e.getMessage());
} finally {
rollbackAndCleanup(success, null);
}
return success;
}
Aggregations