Search in sources :

Example 21 with SearchCriteria

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

the class AssetREST method getXResourceFile.

@GET
@Path("/resource/{id}")
public Response getXResourceFile(@Context HttpServletRequest request, @PathParam("id") Long id) {
    String fileType = searchUtil.extractString(request, new SearchCriteria(), "fileType", "File type", StringUtil.VALIDATION_TEXT);
    VXResource resource = getXResource(id);
    Response response = null;
    if (resource != null && StringUtils.isNotEmpty(fileType)) {
        File file = null;
        file = assetMgr.getXResourceFile(resource, fileType);
        if (file != null) {
            response = Response.ok(file, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment;filename=" + file.getName()).build();
            file = null;
        }
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) RESTResponse(org.apache.ranger.admin.client.datatype.RESTResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) File(java.io.File) SearchCriteria(org.apache.ranger.common.SearchCriteria) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 22 with SearchCriteria

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

the class AssetMgr method getAccessLogs.

public VXAccessAuditList getAccessLogs(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");
    }
    if (RangerBizUtil.AUDIT_STORE_SOLR.equalsIgnoreCase(xaBizUtil.getAuditDBType())) {
        return solrAccessAuditsService.searchXAccessAudits(searchCriteria);
    } else {
        return xAccessAuditService.searchXAccessAudits(searchCriteria);
    }
}
Also used : DateUtil(org.apache.ranger.common.DateUtil) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date)

Example 23 with SearchCriteria

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

the class SessionMgr method searchAuthSessions.

/**
 * @param searchCriteria
 * @return
 */
public VXAuthSessionList searchAuthSessions(SearchCriteria searchCriteria) {
    if (searchCriteria == null) {
        searchCriteria = new SearchCriteria();
    }
    if (searchCriteria.getParamList() != null && !searchCriteria.getParamList().isEmpty()) {
        int clientTimeOffsetInMinute = RestUtil.getClientTimeOffset();
        java.util.Date temp = null;
        DateUtil dateUtil = new DateUtil();
        if (searchCriteria.getParamList().containsKey("startDate")) {
            temp = (java.util.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 = (java.util.Date) searchCriteria.getParamList().get("endDate");
            temp = dateUtil.getDateFromGivenDate(temp, 0, 23, 59, 59);
            temp = dateUtil.addTimeOffset(temp, clientTimeOffsetInMinute);
            searchCriteria.getParamList().put("endDate", temp);
        }
    }
    return authSessionService.search(searchCriteria);
}
Also used : DateUtil(org.apache.ranger.common.DateUtil) SearchCriteria(org.apache.ranger.common.SearchCriteria)

Example 24 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria 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 25 with SearchCriteria

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

the class XUserMgr method getXUserGroups.

public VXGroupList getXUserGroups(Long xUserId) {
    SearchCriteria searchCriteria = new SearchCriteria();
    searchCriteria.addParam("xUserId", xUserId);
    VXGroupUserList vXGroupUserList = xGroupUserService.searchXGroupUsers(searchCriteria);
    VXGroupList vXGroupList = new VXGroupList();
    List<VXGroup> vXGroups = new ArrayList<VXGroup>();
    if (vXGroupUserList != null) {
        List<VXGroupUser> vXGroupUsers = vXGroupUserList.getList();
        Set<Long> groupIdList = new HashSet<Long>();
        for (VXGroupUser vXGroupUser : vXGroupUsers) {
            groupIdList.add(vXGroupUser.getParentGroupId());
        }
        for (Long groupId : groupIdList) {
            VXGroup vXGroup = xGroupService.readResource(groupId);
            vXGroups.add(vXGroup);
        }
        vXGroupList.setVXGroups(vXGroups);
    } else {
        logger.debug("No groups found for user id : " + xUserId);
    }
    return vXGroupList;
}
Also used : ArrayList(java.util.ArrayList) SearchCriteria(org.apache.ranger.common.SearchCriteria) HashSet(java.util.HashSet)

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