Search in sources :

Example 26 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class XUserMgr method deleteXGroupAndXUser.

/**
 * // public void createXGroupAndXUser(String groupName, String userName) {
 *
 * // Long groupId; // Long userId; // XXGroup xxGroup = //
 * appDaoManager.getXXGroup().findByGroupName(groupName); // VXGroup
 * vxGroup; // if (xxGroup == null) { // vxGroup = new VXGroup(); //
 * vxGroup.setName(groupName); // vxGroup.setDescription(groupName); //
 * vxGroup.setGroupType(AppConstants.XA_GROUP_USER); //
 * vxGroup.setPriAcctId(1l); // vxGroup.setPriGrpId(1l); // vxGroup =
 * xGroupService.createResource(vxGroup); // groupId = vxGroup.getId(); // }
 * else { // groupId = xxGroup.getId(); // } // XXUser xxUser =
 * appDaoManager.getXXUser().findByUserName(userName); // VXUser vxUser; //
 * if (xxUser == null) { // vxUser = new VXUser(); //
 * vxUser.setName(userName); // vxUser.setDescription(userName); //
 * vxUser.setPriGrpId(1l); // vxUser.setPriAcctId(1l); // vxUser =
 * xUserService.createResource(vxUser); // userId = vxUser.getId(); // }
 * else { // userId = xxUser.getId(); // } // VXGroupUser vxGroupUser = new
 * VXGroupUser(); // vxGroupUser.setParentGroupId(groupId); //
 * vxGroupUser.setUserId(userId); // vxGroupUser.setName(groupName); //
 * vxGroupUser.setPriAcctId(1l); // vxGroupUser.setPriGrpId(1l); //
 * vxGroupUser = xGroupUserService.createResource(vxGroupUser);
 *
 * // }
 */
public void deleteXGroupAndXUser(String groupName, String userName) {
    checkAdminAccess();
    xaBizUtil.blockAuditorRoleUser();
    VXGroup vxGroup = xGroupService.getGroupByGroupName(groupName);
    VXUser vxUser = xUserService.getXUserByUserName(userName);
    SearchCriteria searchCriteria = new SearchCriteria();
    searchCriteria.addParam("xGroupId", vxGroup.getId());
    searchCriteria.addParam("xUserId", vxUser.getId());
    VXGroupUserList vxGroupUserList = xGroupUserService.searchXGroupUsers(searchCriteria);
    for (VXGroupUser vxGroupUser : vxGroupUserList.getList()) {
        daoManager.getXXGroupUser().remove(vxGroupUser.getId());
    }
}
Also used : SearchCriteria(org.apache.ranger.common.SearchCriteria)

Example 27 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class AssetMgr method getUgsyncAudits.

public VXUgsyncAuditInfoList getUgsyncAudits(SearchCriteria searchCriteria) {
    if (searchCriteria == null) {
        searchCriteria = new SearchCriteria();
    }
    if (searchCriteria.getParamList() != null && !searchCriteria.getParamList().isEmpty()) {
        int clientTimeOffsetInMinute = RestUtil.getClientTimeOffset();
        Date temp = null;
        DateUtil dateUtil = new DateUtil();
        if (searchCriteria.getParamList().containsKey("startDate")) {
            temp = (Date) searchCriteria.getParamList().get("startDate");
            temp = dateUtil.getDateFromGivenDate(temp, 0, 0, 0, 0);
            temp = dateUtil.addTimeOffset(temp, clientTimeOffsetInMinute);
            searchCriteria.getParamList().put("startDate", temp);
        }
        if (searchCriteria.getParamList().containsKey("endDate")) {
            temp = (Date) searchCriteria.getParamList().get("endDate");
            temp = dateUtil.getDateFromGivenDate(temp, 0, 23, 59, 59);
            temp = dateUtil.addTimeOffset(temp, clientTimeOffsetInMinute);
            searchCriteria.getParamList().put("endDate", temp);
        }
    }
    if (searchCriteria.getSortType() == null) {
        searchCriteria.setSortType("desc");
    } else if (!"asc".equalsIgnoreCase(searchCriteria.getSortType()) && !"desc".equalsIgnoreCase(searchCriteria.getSortType())) {
        searchCriteria.setSortType("desc");
    }
    return xUgsyncAuditInfoService.searchXUgsyncAuditInfoList(searchCriteria);
}
Also used : DateUtil(org.apache.ranger.common.DateUtil) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date)

Example 28 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class AssetMgr method searchXPolicyExportAudits.

/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.apache.ranger.biz.AssetMgrBase#searchXPolicyExportAudits(org.apache.ranger.
	 * common.SearchCriteria)
	 */
@Override
public VXPolicyExportAuditList searchXPolicyExportAudits(SearchCriteria searchCriteria) {
    if (searchCriteria == null) {
        searchCriteria = new SearchCriteria();
    }
    if (searchCriteria.getParamList() != null && !searchCriteria.getParamList().isEmpty()) {
        int clientTimeOffsetInMinute = RestUtil.getClientTimeOffset();
        Date temp = null;
        DateUtil dateUtil = new DateUtil();
        if (searchCriteria.getParamList().containsKey("startDate")) {
            temp = (Date) searchCriteria.getParamList().get("startDate");
            temp = dateUtil.getDateFromGivenDate(temp, 0, 0, 0, 0);
            temp = dateUtil.addTimeOffset(temp, clientTimeOffsetInMinute);
            searchCriteria.getParamList().put("startDate", temp);
        }
        if (searchCriteria.getParamList().containsKey("endDate")) {
            temp = (Date) searchCriteria.getParamList().get("endDate");
            temp = dateUtil.getDateFromGivenDate(temp, 0, 23, 59, 59);
            temp = dateUtil.addTimeOffset(temp, clientTimeOffsetInMinute);
            searchCriteria.getParamList().put("endDate", temp);
        }
    }
    return xPolicyExportAuditService.searchXPolicyExportAudits(searchCriteria);
}
Also used : DateUtil(org.apache.ranger.common.DateUtil) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date)

Example 29 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class AssetMgr method getReportLogs.

public VXTrxLogList getReportLogs(SearchCriteria searchCriteria) {
    if (xaBizUtil.isAdmin() || xaBizUtil.isKeyAdmin() || xaBizUtil.isAuditAdmin() || xaBizUtil.isAuditKeyAdmin()) {
        if (searchCriteria == null) {
            searchCriteria = new SearchCriteria();
        }
        if (searchCriteria.getParamList() != null && !searchCriteria.getParamList().isEmpty()) {
            int clientTimeOffsetInMinute = RestUtil.getClientTimeOffset();
            Date temp = null;
            DateUtil dateUtil = new DateUtil();
            if (searchCriteria.getParamList().containsKey("startDate")) {
                temp = (Date) searchCriteria.getParamList().get("startDate");
                temp = dateUtil.getDateFromGivenDate(temp, 0, 0, 0, 0);
                temp = dateUtil.addTimeOffset(temp, clientTimeOffsetInMinute);
                searchCriteria.getParamList().put("startDate", temp);
            }
            if (searchCriteria.getParamList().containsKey("endDate")) {
                temp = (Date) searchCriteria.getParamList().get("endDate");
                temp = dateUtil.getDateFromGivenDate(temp, 0, 23, 59, 59);
                temp = dateUtil.addTimeOffset(temp, clientTimeOffsetInMinute);
                searchCriteria.getParamList().put("endDate", temp);
            }
            if (searchCriteria.getParamList().containsKey("owner")) {
                XXPortalUser xXPortalUser = rangerDaoManager.getXXPortalUser().findByLoginId((searchCriteria.getParamList().get("owner").toString()));
                if (xXPortalUser != null) {
                    searchCriteria.getParamList().put("owner", xXPortalUser.getId());
                } else {
                    searchCriteria.getParamList().put("owner", 0);
                }
            }
        }
        VXTrxLogList vXTrxLogList = xTrxLogService.searchXTrxLogs(searchCriteria);
        Long count = xTrxLogService.searchXTrxLogsCount(searchCriteria);
        vXTrxLogList.setTotalCount(count);
        List<VXTrxLog> newList = validateXXTrxLogList(vXTrxLogList.getVXTrxLogs());
        vXTrxLogList.setVXTrxLogs(newList);
        return vXTrxLogList;
    } else {
        throw restErrorUtil.create403RESTException("Permission Denied !");
    }
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) DateUtil(org.apache.ranger.common.DateUtil) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date)

Example 30 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class PatchMigration_J10002 method getPolicyItemListForRes.

private List<RangerPolicyItem> getPolicyItemListForRes(XXResource xRes, XXServiceDef svcDef) {
    List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
    SearchCriteria sc = new SearchCriteria();
    sc.addParam("resourceId", xRes.getId());
    List<VXPermMap> permMapList = xPermMapService.searchXPermMaps(sc).getVXPermMaps();
    HashMap<String, List<VXPermMap>> sortedPermMap = new HashMap<String, List<VXPermMap>>();
    // re-group the list with permGroup as the key
    if (permMapList != null) {
        for (VXPermMap permMap : permMapList) {
            String permGrp = permMap.getPermGroup();
            List<VXPermMap> sortedList = sortedPermMap.get(permGrp);
            if (sortedList == null) {
                sortedList = new ArrayList<VXPermMap>();
                sortedPermMap.put(permGrp, sortedList);
            }
            sortedList.add(permMap);
        }
    }
    for (Entry<String, List<VXPermMap>> entry : sortedPermMap.entrySet()) {
        List<String> userList = new ArrayList<String>();
        List<String> groupList = new ArrayList<String>();
        List<RangerPolicyItemAccess> accessList = new ArrayList<RangerPolicyItemAccess>();
        String ipAddress = null;
        RangerPolicy.RangerPolicyItem policyItem = new RangerPolicy.RangerPolicyItem();
        for (VXPermMap permMap : entry.getValue()) {
            if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_USER) {
                String userName = getUserName(permMap);
                if (!userList.contains(userName)) {
                    userList.add(userName);
                }
            } else if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_GROUP) {
                String groupName = getGroupName(permMap);
                if (!groupList.contains(groupName)) {
                    groupList.add(groupName);
                }
            }
            String accessType = ServiceUtil.toAccessType(permMap.getPermType());
            if (StringUtils.isBlank(accessType) || unsupportedLegacyPermTypes.contains(accessType)) {
                logger.info(accessType + ": is not a valid access-type, ignoring accesstype for policy: " + xRes.getPolicyName());
                continue;
            }
            if (StringUtils.equalsIgnoreCase(accessType, "Admin")) {
                policyItem.setDelegateAdmin(Boolean.TRUE);
                if (svcDef.getId() == EmbeddedServiceDefsUtil.instance().getHBaseServiceDefId()) {
                    addAccessType(accessType, accessList);
                }
            } else {
                addAccessType(accessType, accessList);
            }
            ipAddress = permMap.getIpAddress();
        }
        if (CollectionUtils.isEmpty(accessList)) {
            logger.info("no access specified. ignoring policyItem for policy: " + xRes.getPolicyName());
            continue;
        }
        if (CollectionUtils.isEmpty(userList) && CollectionUtils.isEmpty(groupList)) {
            logger.info("no user or group specified. ignoring policyItem for policy: " + xRes.getPolicyName());
            continue;
        }
        policyItem.setUsers(userList);
        policyItem.setGroups(groupList);
        policyItem.setAccesses(accessList);
        if (ipAddress != null && !ipAddress.isEmpty()) {
            XXPolicyConditionDef policyCond = daoMgr.getXXPolicyConditionDef().findByServiceDefIdAndName(svcDef.getId(), "ip-range");
            if (policyCond != null) {
                RangerPolicy.RangerPolicyItemCondition ipCondition = new RangerPolicy.RangerPolicyItemCondition("ip-range", Collections.singletonList(ipAddress));
                policyItem.getConditions().add(ipCondition);
            }
        }
        policyItems.add(policyItem);
    }
    return policyItems;
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) SearchCriteria(org.apache.ranger.common.SearchCriteria) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXPolicyConditionDef(org.apache.ranger.entity.XXPolicyConditionDef) RangerPolicyItemAccess(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SearchCriteria (org.apache.ranger.common.SearchCriteria)61 Test (org.junit.Test)29 SortField (org.apache.ranger.common.SortField)27 ArrayList (java.util.ArrayList)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)20 GET (javax.ws.rs.GET)13 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 VXLong (org.apache.ranger.view.VXLong)10 Date (java.util.Date)9 DateUtil (org.apache.ranger.common.DateUtil)6 HashMap (java.util.HashMap)4 XXPortalUser (org.apache.ranger.entity.XXPortalUser)4 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)4 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)4 VXPermMap (org.apache.ranger.view.VXPermMap)4 VXUserList (org.apache.ranger.view.VXUserList)4 List (java.util.List)3 XXServiceDef (org.apache.ranger.entity.XXServiceDef)3