Search in sources :

Example 1 with SearchRequest

use of org.gluu.oxtrust.model.scim2.SearchRequest in project oxTrust by GluuFederation.

the class GroupWebService method searchGroupsPost.

@Path("/.search")
@POST
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search group POST /.search", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchGroupsPost(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) throws Exception {
    try {
        log.info("IN GroupWebService.searchGroupsPost()...");
        // Authorization check is done in searchGroups()
        Response response = searchGroups(authorization, token, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesArray());
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/.search");
        log.info("LEAVING GroupWebService.searchGroupsPost()...");
        return Response.fromResponse(response).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Error in searchGroupsPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource not found");
    } catch (Exception ex) {
        log.error("Error in searchGroupsPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 2 with SearchRequest

use of org.gluu.oxtrust.model.scim2.SearchRequest in project oxTrust by GluuFederation.

the class BaseScimWebService method prepareSearchRequest.

protected Response prepareSearchRequest(List<String> schemas, String filter, String sortBy, String sortOrder, Integer startIndex, Integer count, String attrsList, String excludedAttrsList, SearchRequest request) {
    Response response = null;
    if (schemas != null && schemas.size() == 1 && schemas.get(0).equals(SEARCH_REQUEST_SCHEMA_ID)) {
        count = count == null ? getMaxCount() : count;
        // Per spec, a negative value SHALL be interpreted as "0" for count
        if (count < 0)
            count = 0;
        if (count <= getMaxCount()) {
            startIndex = (startIndex == null || startIndex < 1) ? 1 : startIndex;
            if (StringUtils.isEmpty(sortOrder) || !sortOrder.equals(SortOrder.DESCENDING.getValue()))
                sortOrder = SortOrder.ASCENDING.getValue();
            request.setSchemas(schemas);
            request.setAttributes(attrsList);
            request.setExcludedAttributes(excludedAttrsList);
            request.setFilter(filter);
            request.setSortBy(sortBy);
            request.setSortOrder(sortOrder);
            request.setStartIndex(startIndex);
            request.setCount(count);
        } else
            response = getErrorResponse(BAD_REQUEST, ErrorScimType.TOO_MANY, "Maximum number of results per page is " + getMaxCount());
    } else
        response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Wrong schema(s) supplied in Search Request");
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.gluu.oxtrust.model.scim2.ErrorResponse)

Example 3 with SearchRequest

use of org.gluu.oxtrust.model.scim2.SearchRequest in project oxTrust by GluuFederation.

the class FidoDeviceWebService method searchDevicesPost.

@Path(SEARCH_SUFFIX)
@POST
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Search devices POST /.search", notes = "Returns a list of fido devices", response = ListResponse.class)
public Response searchDevicesPost(SearchRequest searchRequest, @QueryParam("userId") String userId) {
    log.debug("Executing web service method. searchDevicesPost");
    URI uri = null;
    Response response = searchDevices(userId, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr());
    try {
        uri = new URI(endpointUrl + "/" + SEARCH_SUFFIX);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return Response.fromResponse(response).location(uri).build();
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 4 with SearchRequest

use of org.gluu.oxtrust.model.scim2.SearchRequest in project oxTrust by GluuFederation.

the class GroupWebService method searchGroupsPost.

@Path(SEARCH_SUFFIX)
@POST
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Search group POST /.search", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchGroupsPost(@ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) {
    log.debug("Executing web service method. searchGroupsPost");
    // Calling searchGroups here does not provoke that method's interceptor/decorator being called (only this one's)
    URI uri = null;
    Response response = searchGroups(searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr());
    try {
        uri = new URI(endpointUrl + "/" + SEARCH_SUFFIX);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return Response.fromResponse(response).location(uri).build();
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 5 with SearchRequest

use of org.gluu.oxtrust.model.scim2.SearchRequest in project oxTrust by GluuFederation.

the class SearchResourcesWebService method getListResponseTree.

/**
 * Returns a JsonNode with the response obtained from sending a POST to a search method given the SearchRequest passed
 * @param index Determines the concrete search method to be executed: (0 - user; 1 - group; 2 - fido device)
 * @param searchRequest
 * @return
 */
private JsonNode getListResponseTree(int index, SearchRequest searchRequest) {
    try {
        log.debug("getListResponseTree. Resource type is: {}", ScimResourceUtil.getType(resourceClasses[index]));
        Response r = null;
        switch(index) {
            case 0:
                r = userWS.searchUsersPost(searchRequest);
                break;
            case 1:
                r = groupWS.searchGroupsPost(searchRequest);
                break;
            case 2:
                r = fidoWS.searchDevicesPost(searchRequest, null);
                break;
        }
        if (r.getStatus() != OK.getStatusCode())
            throw new Exception("Intermediate POST search returned " + r.getStatus());
        // readEntity does not work here since data is not backed by an input stream, so we just get the raw entity
        String jsonStr = r.getEntity().toString();
        return mapper.readTree(jsonStr);
    } catch (Exception e) {
        log.error("Error in getListResponseTree {}", e.getMessage());
        log.error(e.getMessage(), e);
        return null;
    }
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response)

Aggregations

Response (javax.ws.rs.core.Response)13 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)9 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)7 URI (java.net.URI)7 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 POST (javax.ws.rs.POST)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 SearchRequest (org.gluu.oxtrust.model.scim2.SearchRequest)6 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)4 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 Consumes (javax.ws.rs.Consumes)3 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)3 ListViewResponse (org.gluu.persist.model.ListViewResponse)3 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)3 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)3 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)3 Annotation (java.lang.annotation.Annotation)1