use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XPolicyService method mapPermObjToPermList.
private List<VXPermMap> mapPermObjToPermList(List<VXPermObj> permObjList) {
List<VXPermMap> permMapList = new ArrayList<VXPermMap>();
Random rand = new Random();
for (VXPermObj permObj : permObjList) {
String ipAddress = permObj.getIpAddress();
if (!stringUtil.isEmpty(permObj.getUserList())) {
String permGrp = new Date() + " : " + rand.nextInt(9999);
for (String user : permObj.getUserList()) {
XXUser xxUser = xaDaoMgr.getXXUser().findByUserName(user);
if (xxUser == null) {
logger.error("No User found with this name : " + user);
throw restErrorUtil.createRESTException("No User found with name : " + user, MessageEnums.DATA_NOT_FOUND);
}
for (String permission : permObj.getPermList()) {
VXPermMap vXPermMap = new VXPermMap();
int permType = AppConstants.getEnumFor_XAPermType(permission);
vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_USER);
vXPermMap.setPermGroup(permGrp);
vXPermMap.setPermType(permType);
vXPermMap.setUserId(xxUser.getId());
vXPermMap.setIpAddress(ipAddress);
permMapList.add(vXPermMap);
}
}
}
if (!stringUtil.isEmpty(permObj.getGroupList())) {
String permGrp = new Date() + " : " + rand.nextInt(9999);
for (String group : permObj.getGroupList()) {
XXGroup xxGroup = xaDaoMgr.getXXGroup().findByGroupName(group);
if (xxGroup == null) {
logger.error("No UserGroup found with this name : " + group);
throw restErrorUtil.createRESTException("No User found with name : " + group, MessageEnums.DATA_NOT_FOUND);
}
for (String permission : permObj.getPermList()) {
VXPermMap vXPermMap = new VXPermMap();
int permType = AppConstants.getEnumFor_XAPermType(permission);
vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_GROUP);
vXPermMap.setPermGroup(permGrp);
vXPermMap.setPermType(permType);
vXPermMap.setGroupId(xxGroup.getId());
vXPermMap.setIpAddress(ipAddress);
permMapList.add(vXPermMap);
}
}
}
}
return permMapList;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XUserMgr method getXGroupUserFromMap.
public VXGroupUserInfo getXGroupUserFromMap(String groupName) {
checkAdminAccess();
VXGroupUserInfo vxGUInfo = new VXGroupUserInfo();
XXGroup xGroup = daoManager.getXXGroup().findByGroupName(groupName);
if (xGroup == null) {
return vxGUInfo;
}
VXGroup xgroupInfo = xGroupService.populateViewBean(xGroup);
vxGUInfo.setXgroupInfo(xgroupInfo);
SearchCriteria searchCriteria = new SearchCriteria();
searchCriteria.addParam("xGroupId", xGroup.getId());
VXGroupUserList vxGroupUserList = searchXGroupUsers(searchCriteria);
List<VXUser> vxu = new ArrayList<VXUser>();
logger.debug("removing all the group user mapping for : " + xGroup.getName());
for (VXGroupUser groupUser : vxGroupUserList.getList()) {
XXUser xUser = daoManager.getXXUser().getById(groupUser.getUserId());
if (xUser != null) {
VXUser vxUser = new VXUser();
vxUser.setName(xUser.getName());
XXPortalUser xXPortalUser = daoManager.getXXPortalUser().findByLoginId(xUser.getName());
if (xXPortalUser != null) {
List<String> existingRole = daoManager.getXXPortalUserRole().findXPortalUserRolebyXPortalUserId(xXPortalUser.getId());
if (existingRole != null) {
vxUser.setUserRoleList(existingRole);
}
}
vxu.add(vxUser);
}
}
vxGUInfo.setXuserInfo(vxu);
return vxGUInfo;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class ServiceDBStore method createNewPolicyItemForPolicy.
private XXPolicyItem createNewPolicyItemForPolicy(RangerPolicy policy, XXPolicy xPolicy, RangerPolicyItem policyItem, XXServiceDef xServiceDef, int itemOrder, int policyItemType) throws Exception {
XXPolicyItem xPolicyItem = new XXPolicyItem();
xPolicyItem = rangerAuditFields.populateAuditFields(xPolicyItem, xPolicy);
xPolicyItem.setDelegateAdmin(policyItem.getDelegateAdmin());
xPolicyItem.setItemType(policyItemType);
xPolicyItem.setIsEnabled(Boolean.TRUE);
xPolicyItem.setComments(null);
xPolicyItem.setPolicyId(policy.getId());
xPolicyItem.setOrder(itemOrder);
xPolicyItem = daoMgr.getXXPolicyItem().create(xPolicyItem);
List<RangerPolicyItemAccess> accesses = policyItem.getAccesses();
for (int i = 0; i < accesses.size(); i++) {
RangerPolicyItemAccess access = accesses.get(i);
XXAccessTypeDef xAccTypeDef = daoMgr.getXXAccessTypeDef().findByNameAndServiceId(access.getType(), xPolicy.getService());
if (xAccTypeDef == null) {
throw new Exception(access.getType() + ": is not a valid access-type. policy='" + policy.getName() + "' service='" + policy.getService() + "'");
}
XXPolicyItemAccess xPolItemAcc = new XXPolicyItemAccess();
xPolItemAcc = (XXPolicyItemAccess) rangerAuditFields.populateAuditFields(xPolItemAcc, xPolicyItem);
xPolItemAcc.setIsAllowed(access.getIsAllowed());
xPolItemAcc.setType(xAccTypeDef.getId());
xPolItemAcc.setPolicyitemid(xPolicyItem.getId());
xPolItemAcc.setOrder(i);
daoMgr.getXXPolicyItemAccess().create(xPolItemAcc);
}
List<String> users = policyItem.getUsers();
for (int i = 0; i < users.size(); i++) {
String user = users.get(i);
if (StringUtils.isBlank(user)) {
continue;
}
XXUser xUser = daoMgr.getXXUser().findByUserName(user);
if (xUser == null) {
throw new Exception(user + ": user does not exist. policy='" + policy.getName() + "' service='" + policy.getService() + "' user='" + user + "'");
}
XXPolicyItemUserPerm xUserPerm = new XXPolicyItemUserPerm();
xUserPerm = rangerAuditFields.populateAuditFields(xUserPerm, xPolicyItem);
xUserPerm.setUserId(xUser.getId());
xUserPerm.setPolicyItemId(xPolicyItem.getId());
xUserPerm.setOrder(i);
xUserPerm = daoMgr.getXXPolicyItemUserPerm().create(xUserPerm);
}
List<String> groups = policyItem.getGroups();
for (int i = 0; i < groups.size(); i++) {
String group = groups.get(i);
if (StringUtils.isBlank(group)) {
continue;
}
XXGroup xGrp = daoMgr.getXXGroup().findByGroupName(group);
if (xGrp == null) {
throw new Exception(group + ": group does not exist. policy='" + policy.getName() + "' service='" + policy.getService() + "' group='" + group + "'");
}
XXPolicyItemGroupPerm xGrpPerm = new XXPolicyItemGroupPerm();
xGrpPerm = rangerAuditFields.populateAuditFields(xGrpPerm, xPolicyItem);
xGrpPerm.setGroupId(xGrp.getId());
xGrpPerm.setPolicyItemId(xPolicyItem.getId());
xGrpPerm.setOrder(i);
xGrpPerm = daoMgr.getXXPolicyItemGroupPerm().create(xGrpPerm);
}
List<RangerPolicyItemCondition> conditions = policyItem.getConditions();
for (RangerPolicyItemCondition condition : conditions) {
XXPolicyConditionDef xPolCond = daoMgr.getXXPolicyConditionDef().findByServiceDefIdAndName(xServiceDef.getId(), condition.getType());
if (xPolCond == null) {
throw new Exception(condition.getType() + ": is not a valid condition-type. policy='" + xPolicy.getName() + "' service='" + xPolicy.getService() + "'");
}
for (int i = 0; i < condition.getValues().size(); i++) {
String value = condition.getValues().get(i);
XXPolicyItemCondition xPolItemCond = new XXPolicyItemCondition();
xPolItemCond = rangerAuditFields.populateAuditFields(xPolItemCond, xPolicyItem);
xPolItemCond.setPolicyItemId(xPolicyItem.getId());
xPolItemCond.setType(xPolCond.getId());
xPolItemCond.setValue(value);
xPolItemCond.setOrder(i);
daoMgr.getXXPolicyItemCondition().create(xPolItemCond);
}
}
return xPolicyItem;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XGroupPermissionService method populateViewBean.
@Override
public VXGroupPermission populateViewBean(XXGroupPermission xObj) {
VXGroupPermission vObj = super.populateViewBean(xObj);
XXGroup xGroup = daoManager.getXXGroup().getById(xObj.getGroupId());
if (xGroup == null) {
throw restErrorUtil.createRESTException(xGroup + " is Not Found", MessageEnums.DATA_NOT_FOUND);
}
vObj.setGroupName(xGroup.getName());
return vObj;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XGroupService method readResourceWithOutLogin.
public VXGroup readResourceWithOutLogin(Long id) {
XXGroup resource = getDao().getById(id);
if (resource == null) {
// Returns code 400 with DATA_NOT_FOUND as the error message
throw restErrorUtil.createRESTException(getResourceName() + " not found", MessageEnums.DATA_NOT_FOUND, id, null, "preRead: " + id + " not found.");
}
VXGroup view = populateViewBean(resource);
if (view != null) {
view.setGroupSource(resource.getGroupSource());
}
return view;
}
Aggregations