Search in sources :

Example 21 with ListResponse

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

the class ResourceTypesTest method init.

@BeforeTest
public void init() throws Exception {
    Response response = client.getResourceTypes();
    listResponse = response.readEntity(ListResponse.class);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponse(io.jans.scim.model.scim2.ListResponse) BeforeTest(org.testng.annotations.BeforeTest)

Example 22 with ListResponse

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

the class Fido2DeviceTest method search.

@Test
public void search() {
    logger.debug("Searching all fido 2 devices");
    Response response = client.searchF2Devices(null, "id pr", null, null, null, null, null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    // Work upon the first device of the list only
    device = (Fido2DeviceResource) listResponse.getResources().get(0);
    assertNotNull(device);
    logger.debug("First device {} picked", device.getId());
}
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)

Example 23 with ListResponse

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

the class MultipleResourcesSearchTest method search3.

@Test(dependsOnMethods = "search2")
public void search3() {
    // Move the start index to the last item
    sr.setStartIndex(listResponse.getTotalResults());
    Response response = client.searchResourcesPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse anotherLR = response.readEntity(ListResponse.class);
    // Verify there is only one result
    assertEquals(anotherLR.getItemsPerPage(), 1);
}
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)

Example 24 with ListResponse

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

the class FidoDeviceWebService method searchDevices.

@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search devices", notes = "Returns a list of devices (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchDevices(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam("userId") final String userId, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        if (count > getMaxCount()) {
            String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
            return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
        } else {
            log.info(" Searching devices from LDAP ");
            String baseDn = fidoDeviceService.getDnForFidoDevice(userId, null);
            log.info("##### baseDn = " + baseDn);
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuCustomFidoDevice> gluuCustomFidoDevices = search(baseDn, GluuCustomFidoDevice.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            ListResponse devicesListResponse = new ListResponse();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
            log.info(" setting schema");
            devicesListResponse.setSchemas(schema);
            // Set total
            devicesListResponse.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && gluuCustomFidoDevices != null && !gluuCustomFidoDevices.isEmpty()) {
                for (GluuCustomFidoDevice gluuCustomFidoDevice : gluuCustomFidoDevices) {
                    FidoDevice fidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
                    devicesListResponse.getResources().add(fidoDevice);
                }
                // Set the rest of results info
                devicesListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
                devicesListResponse.setStartIndex(vlvResponse.getStartIndex());
            }
            // Serialize to JSON
            String json = serializeToJson(devicesListResponse, attributesArray);
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices");
            return Response.ok(json).location(location).build();
        }
    } catch (Exception e) {
        log.error("Error in searchDevices", e);
        e.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) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 25 with ListResponse

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

the class GroupWebService method searchGroups.

@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search groups", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        if (count > getMaxCount()) {
            String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
            return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
        } else {
            log.info(" Searching groups from LDAP ");
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuGroup> groupList = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            // List<GluuGroup> groupList = groupService.getAllGroupsList();
            ListResponse groupsListResponse = new ListResponse();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
            log.info(" setting schema");
            groupsListResponse.setSchemas(schema);
            // Set total
            groupsListResponse.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && groupList != null && !groupList.isEmpty()) {
                for (GluuGroup gluuGroup : groupList) {
                    Group group = copyUtils2.copy(gluuGroup, null);
                    log.info(" group to be added displayName : " + group.getDisplayName());
                    groupsListResponse.getResources().add(group);
                    log.info(" group added? : " + groupsListResponse.getResources().contains(group));
                }
                // Set the rest of results info
                groupsListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
                groupsListResponse.setStartIndex(vlvResponse.getStartIndex());
            }
            // Serialize to JSON
            String json = serializeToJson(groupsListResponse, attributesArray);
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups");
            return Response.ok(json).location(location).build();
        }
    } catch (Exception ex) {
        log.error("Error in searchGroups", 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) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

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