use of org.apache.hadoop.hive.metastore.model.MRoleMap 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.MRoleMap 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.MRoleMap in project hive by apache.
the class ObjectStore method listMSecurityPrincipalMembershipRole.
private List<MRoleMap> listMSecurityPrincipalMembershipRole(final String roleName, final PrincipalType principalType) throws Exception {
LOG.debug("Executing listMSecurityPrincipalMembershipRole");
Preconditions.checkState(this.currentTransaction.isActive());
try (Query query = pm.newQuery(MRoleMap.class, "principalName == t1 && principalType == t2")) {
query.declareParameters("java.lang.String t1, java.lang.String t2");
final List<MRoleMap> mRoleMemebership = (List<MRoleMap>) query.execute(roleName, principalType.toString());
LOG.debug("Retrieving all objects for listMSecurityPrincipalMembershipRole");
pm.retrieveAll(mRoleMemebership);
LOG.debug("Done retrieving all objects for listMSecurityPrincipalMembershipRole: {}", mRoleMemebership);
return Collections.unmodifiableList(new ArrayList<>(mRoleMemebership));
}
}
use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.
the class ObjectStore method listMRoleMembers.
public List<MRoleMap> listMRoleMembers(String roleName) {
boolean success = false;
Query query = null;
List<MRoleMap> mRoleMemeberList = new ArrayList<>();
try {
LOG.debug("Executing listRoleMembers");
openTransaction();
query = pm.newQuery(MRoleMap.class, "role.roleName == t1");
query.declareParameters("java.lang.String t1");
query.setUnique(false);
List<MRoleMap> mRoles = (List<MRoleMap>) query.execute(roleName);
pm.retrieveAll(mRoles);
success = commitTransaction();
mRoleMemeberList.addAll(mRoles);
LOG.debug("Done retrieving all objects for listRoleMembers");
} finally {
rollbackAndCleanup(success, query);
}
return mRoleMemeberList;
}
use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.
the class ObjectStore method getMSecurityUserRoleMap.
private MRoleMap getMSecurityUserRoleMap(String userName, PrincipalType principalType, String roleName) {
MRoleMap mRoleMember = null;
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MRoleMap.class, "principalName == t1 && principalType == t2 && role.roleName == t3");
query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
query.setUnique(true);
mRoleMember = (MRoleMap) query.executeWithArray(userName, principalType.toString(), roleName);
pm.retrieve(mRoleMember);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
return mRoleMember;
}
Aggregations