Search in sources :

Example 16 with XXGroup

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;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXPermMap(org.apache.ranger.view.VXPermMap) XXGroup(org.apache.ranger.entity.XXGroup) Random(java.util.Random) ArrayList(java.util.ArrayList) VXPermObj(org.apache.ranger.view.VXPermObj) Date(java.util.Date)

Example 17 with XXGroup

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;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) ArrayList(java.util.ArrayList) SearchCriteria(org.apache.ranger.common.SearchCriteria) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXGroup(org.apache.ranger.entity.XXGroup)

Example 18 with XXGroup

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;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXPolicyItemGroupPerm(org.apache.ranger.entity.XXPolicyItemGroupPerm) XXPolicyItemUserPerm(org.apache.ranger.entity.XXPolicyItemUserPerm) VXString(org.apache.ranger.view.VXString) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JSONException(org.codehaus.jettison.json.JSONException) XXPolicyItemCondition(org.apache.ranger.entity.XXPolicyItemCondition) XXPolicyItem(org.apache.ranger.entity.XXPolicyItem) XXPolicyItemAccess(org.apache.ranger.entity.XXPolicyItemAccess) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyConditionDef(org.apache.ranger.entity.XXPolicyConditionDef) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) RangerPolicyItemAccess(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess) RangerPolicyItemCondition(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemCondition)

Example 19 with XXGroup

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;
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup) VXGroupPermission(org.apache.ranger.view.VXGroupPermission)

Example 20 with XXGroup

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;
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup) VXGroup(org.apache.ranger.view.VXGroup)

Aggregations

XXGroup (org.apache.ranger.entity.XXGroup)24 ArrayList (java.util.ArrayList)11 XXUser (org.apache.ranger.entity.XXUser)10 VXGroup (org.apache.ranger.view.VXGroup)7 XXGroupDao (org.apache.ranger.db.XXGroupDao)6 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 XXTrxLog (org.apache.ranger.entity.XXTrxLog)4 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)3 XXPermMap (org.apache.ranger.entity.XXPermMap)3 XXPortalUser (org.apache.ranger.entity.XXPortalUser)3 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)3 Field (java.lang.reflect.Field)2 Date (java.util.Date)2 Random (java.util.Random)2 SearchCriteria (org.apache.ranger.common.SearchCriteria)2 SearchField (org.apache.ranger.common.SearchField)2 VTrxLogAttr (org.apache.ranger.common.view.VTrxLogAttr)2 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)2