Search in sources :

Example 26 with SearchRequest

use of io.jans.scim.model.scim2.SearchRequest in project oxTrust by GluuFederation.

the class GroupWebServiceDecorator method searchGroupsPost.

public Response searchGroupsPost(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) {
        response = service.searchGroupsPost(searchReq);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SearchRequest(org.gluu.oxtrust.model.scim2.SearchRequest)

Example 27 with SearchRequest

use of io.jans.scim.model.scim2.SearchRequest in project oxTrust by GluuFederation.

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
@RefAdjusted
@ApiOperation(value = "General search POST /.search", notes = "Returns a list of resources (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response search(@ApiParam(value = "SearchRequest", required = true) 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<JsonNode>();
            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(org.gluu.oxtrust.model.scim2.SearchRequest) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) ListResponseJsonSerializer(org.gluu.oxtrust.service.scim2.serialization.ListResponseJsonSerializer) URI(java.net.URI) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 28 with SearchRequest

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

the class SpecialCharsTest method equality.

@Test(dependsOnMethods = "containabilityAny")
public void equality() {
    // Based on usernames list built in test containabilityAny, n searches with EQ filter are issued
    for (String userName : userNames) {
        SearchRequest sr = new SearchRequest();
        sr.setFilter(String.format("userName eq \"%s\"", StringEscapeUtils.escapeJson(userName)));
        sr.setAttributes("userName, name.givenName");
        Response response = client.searchUsersPost(sr);
        UserResource user = (UserResource) response.readEntity(ListResponse.class).getResources().get(0);
        logger.info("User {} found with userName {}", user.getName().getGivenName(), user.getUserName());
        assertEquals(userName, user.getUserName());
    }
}
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) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 29 with SearchRequest

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

the class ComplexSearchUserTest method searchNoAttributesParam.

@Test
public void searchNoAttributesParam() {
    final String ims = "Skype";
    logger.debug("Searching users with attribute nickName existent or ims.value={} using POST verb", ims);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("nickName pr or ims.value eq \"" + ims + "\"");
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    if (listResponse.getResources() != null) {
        for (BaseScimResource resource : listResponse.getResources()) {
            UserResource other = (UserResource) resource;
            boolean c1 = other.getNickName() != null;
            boolean c2 = true;
            if (other.getIms() != null)
                c2 = other.getIms().stream().anyMatch(im -> im.getValue().toLowerCase().equals(ims.toLowerCase()));
            assertTrue(c1 || c2);
        }
    }
}
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) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 30 with SearchRequest

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

the class ComplexSearchUserTest method searchAttributesParam.

@Test
public void searchAttributesParam() throws Exception {
    int count = 3;
    List<String> attrList = Arrays.asList("name.familyName", "active");
    logger.debug("Searching at most {} users using POST verb", count);
    logger.debug("Sorted by family name descending");
    logger.debug("Retrieving only the attributes {}", attrList);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("name.familyName pr");
    sr.setSortBy("name.familyName");
    sr.setSortOrder("descending");
    // Generate a string with the attributes desired to be returned separated by comma
    sr.setAttributes(attrList.toString().replaceFirst("\\[", "").replaceFirst("]", ""));
    sr.setCount(count);
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    if (listResponse.getResources().size() < count)
        logger.warn("Less than {} users satisfying the criteria. TESTER please check manually", count);
    else {
        // Obtain an array of results
        UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
        assertEquals(users.length, count);
        // Build a set of all attributes that should not appear in the response
        Set<String> check = new HashSet<>();
        check.addAll(IntrospectUtil.allAttrs.get(usrClass));
        // Remove from the ALL list, those requested plus its "parents"
        for (String attr : attrList) {
            String part = attr;
            for (int i = part.length(); i > 0; i = part.lastIndexOf(".")) {
                part = part.substring(0, i);
                check.remove(part);
            }
        }
        // Remove those that are ALWAYS present (per spec)
        check.removeAll(IntrospectUtil.alwaysCoreAttrs.get(usrClass).keySet());
        // Confirm for every user, those attributes are not there
        for (UserResource user : users) {
            for (String path : check) {
                String val = null;
                try {
                    val = BeanUtils.getProperty(user, path);
                } catch (NestedNullException nne) {
                // Intentionally left empty
                } finally {
                    assertNull(val);
                }
            }
        }
        boolean correctSorting = true;
        for (int i = 1; i < users.length && correctSorting; i++) {
            String familyName = users[i - 1].getName().getFamilyName();
            String familyName2 = users[i].getName().getFamilyName();
            // First string has to be greater than or equal second
            correctSorting = familyName.compareTo(familyName2) >= 0;
        }
        if (!correctSorting) {
            // LDAP may ignore case sensitivity, try again using lowercasing
            correctSorting = true;
            for (int i = 1; i < users.length && correctSorting; i++) {
                String familyName = users[i - 1].getName().getFamilyName().toLowerCase();
                String familyName2 = users[i].getName().getFamilyName().toLowerCase();
                // First string has to be greater than or equal second
                correctSorting = familyName.compareTo(familyName2) >= 0;
            }
        }
        assertTrue(correctSorting);
    }
}
Also used : SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) UserResource(io.jans.scim.model.scim2.user.UserResource) Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) NestedNullException(org.apache.commons.beanutils.NestedNullException) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Aggregations

Response (javax.ws.rs.core.Response)31 SearchRequest (io.jans.scim.model.scim2.SearchRequest)23 ListResponse (io.jans.scim.model.scim2.ListResponse)21 Test (org.testng.annotations.Test)15 UserResource (io.jans.scim.model.scim2.user.UserResource)13 UserBaseTest (io.jans.scim2.client.UserBaseTest)13 SearchRequest (com.google.cloud.retail.v2.SearchRequest)7 SearchResponse (com.google.cloud.retail.v2.SearchResponse)7 SearchServiceClient (com.google.cloud.retail.v2.SearchServiceClient)7 URI (java.net.URI)6 SearchRequest (org.gluu.oxtrust.model.scim2.SearchRequest)6 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)5 SkipTest (io.jans.scim2.listener.SkipTest)5 SCIMException (io.jans.scim.model.exception.SCIMException)4 URISyntaxException (java.net.URISyntaxException)4 BeforeTest (org.testng.annotations.BeforeTest)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)2 GroupResource (io.jans.scim.model.scim2.group.GroupResource)2 Annotation (java.lang.annotation.Annotation)2