Search in sources :

Example 6 with ListResponse

use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.

the class BaseScimWebService method getListResponseSerialized.

String getListResponseSerialized(int total, int startIndex, List<BaseScimResource> resources, String attrsList, String excludedAttrsList, boolean ignoreResults) throws IOException {
    ListResponse listResponse = new ListResponse(startIndex, resources.size(), total);
    listResponse.setResources(resources);
    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
    module.addSerializer(ListResponse.class, new ListResponseJsonSerializer(resourceSerializer, attrsList, excludedAttrsList, ignoreResults));
    mapper.registerModule(module);
    return mapper.writeValueAsString(listResponse);
}
Also used : ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponseJsonSerializer(io.jans.scim.service.scim2.serialization.ListResponseJsonSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 7 with ListResponse

use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.

the class SearchResourcesWebService method search.

@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(scopes = { "https://jans.io/scim/all-resources.search" })
@RefAdjusted
public Response search(SearchRequest searchRequest) {
    SearchRequest searchReq = new SearchRequest();
    Response response = prepareSearchRequest(searchRequest.getSchemas(), searchRequest.getFilter(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr(), searchReq);
    if (response == null) {
        try {
            List<JsonNode> resources = new ArrayList<>();
            Pair<Integer, Integer> totals = computeResults(searchReq, resources);
            ListResponseJsonSerializer custSerializer = new ListResponseJsonSerializer(resourceSerializer, searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr(), searchReq.getCount() == 0);
            if (resources.size() > 0)
                custSerializer.setJsonResources(resources);
            ObjectMapper objmapper = new ObjectMapper();
            SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
            module.addSerializer(ListResponse.class, custSerializer);
            objmapper.registerModule(module);
            // Provide to constructor original start index, and totals calculated in computeResults call
            ListResponse listResponse = new ListResponse(searchReq.getStartIndex(), totals.getFirst(), totals.getSecond());
            String json = objmapper.writeValueAsString(listResponse);
            response = Response.ok(json).location(new URI(endpointUrl)).build();
        } catch (Exception e) {
            log.error("Failure at search method", e);
            response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
        }
    }
    return response;
}
Also used : SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ListResponseJsonSerializer(io.jans.scim.service.scim2.serialization.ListResponseJsonSerializer) URI(java.net.URI) Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Example 8 with ListResponse

use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.

the class GroupAssignUserTest method getAdminId.

private String getAdminId() {
    // Search the id of the admin user
    SearchRequest sr = new SearchRequest();
    sr.setFilter("userName eq \"admin\"");
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse lr = response.readEntity(ListResponse.class);
    assertTrue(lr.getResources().size() > 0);
    return lr.getResources().get(0).getId();
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse)

Example 9 with ListResponse

use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.

the class ComplexSearchUserTest method searchSortByExternalId.

@Test
public void searchSortByExternalId() {
    Response response = client.searchUsers(null, null, null, "externalId", "descending", "externalId", null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
    assertEquals(listResponse.getStartIndex(), 1);
    assertEquals(listResponse.getItemsPerPage(), users.length);
    assertEquals(listResponse.getResources().size(), users.length);
    for (int i = 1; i < users.length; i++) {
        String exId1 = users[i - 1].getExternalId();
        String exId2 = users[i].getExternalId();
        if (exId2 != null)
            assertNotNull(exId1);
        if (exId1 == null)
            assertNull(exId2);
        if (// In descending order exId1 must be higher than exId2
        exId1 != null && exId2 != null)
            assertFalse(exId1.compareTo(exId2) < 0);
    }
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponse(io.jans.scim.model.scim2.ListResponse) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 10 with ListResponse

use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.

the class MultipleResourcesSearchTest method search5.

@Test(dependsOnMethods = "search4")
public void search5() {
    // Means 1
    sr.setStartIndex(null);
    // Returns no resources, only total
    sr.setCount(0);
    Response response = client.searchResourcesPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse anotherLR = response.readEntity(ListResponse.class);
    assertEquals(listResponse.getTotalResults(), anotherLR.getTotalResults());
    assertNull(anotherLR.getResources());
    // unassigned
    assertEquals(anotherLR.getItemsPerPage(), 0);
    // unassigned
    assertEquals(anotherLR.getStartIndex(), 0);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponse(io.jans.scim.model.scim2.ListResponse) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Aggregations

Response (javax.ws.rs.core.Response)38 ListResponse (io.jans.scim.model.scim2.ListResponse)36 Test (org.testng.annotations.Test)26 UserBaseTest (io.jans.scim2.client.UserBaseTest)16 SearchRequest (io.jans.scim.model.scim2.SearchRequest)12 UserResource (io.jans.scim.model.scim2.user.UserResource)11 URI (java.net.URI)11 BaseTest (io.jans.scim2.client.BaseTest)10 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)9 DefaultValue (javax.ws.rs.DefaultValue)8 HeaderParam (javax.ws.rs.HeaderParam)8 Produces (javax.ws.rs.Produces)8 ArrayList (java.util.ArrayList)7 GET (javax.ws.rs.GET)7 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 RejectFilterParam (io.jans.scim.service.scim2.interceptor.RejectFilterParam)2