Search in sources :

Example 6 with Fido2DeviceResource

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

the class Fido2DeviceTest method retrieve.

@Test(dependsOnMethods = "search")
public void retrieve() {
    logger.debug("Retrieving same device by id");
    Response response = client.getF2DeviceById(device.getId(), device.getUserId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    Fido2DeviceResource same = response.readEntity(fido2Class);
    assertEquals(device.getId(), same.getId());
    assertEquals(device.getStatus(), same.getStatus());
    assertEquals(device.getCounter(), same.getCounter());
    assertEquals(device.getCreationDate(), same.getCreationDate());
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Example 7 with Fido2DeviceResource

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

the class Fido2DeviceWebService method getF2DeviceById.

@Path("{id}")
@GET
@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/fido2.read" })
@RefAdjusted
public Response getF2DeviceById(@PathParam("id") String id, @QueryParam("userId") String userId, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. getF2DeviceById");
        GluuFido2Device device = fidoDeviceService.getFido2DeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fido2ResourceType);
        response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.GET, fido2ResourceType);
        if (response != null)
            return response;
        Fido2DeviceResource fidoResource = new Fido2DeviceResource();
        transferAttributesToFido2Resource(device, fidoResource, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
        String json = resourceSerializer.serialize(fidoResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(fidoResource.getMeta().getLocation())).entity(json).build();
    } catch (Exception e) {
        log.error("Failure at getF2DeviceById method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) URI(java.net.URI) GluuFido2Device(io.jans.scim.model.GluuFido2Device) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Example 8 with Fido2DeviceResource

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

the class Fido2DeviceWebService method searchDevices.

private PagedResult<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count) throws Exception {
    Filter ldapFilter = scimFilterParserService.createFilter(filter, Filter.createPresenceFilter("jansId"), Fido2DeviceResource.class);
    log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}', userId '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count, userId);
    // Currently, searching with SUB scope in Couchbase requires some help (beyond use of baseDN)
    if (StringUtils.isNotEmpty(userId)) {
        ldapFilter = Filter.createANDFilter(ldapFilter, Filter.createEqualityFilter("personInum", userId));
    }
    PagedResult<GluuFido2Device> list;
    try {
        list = entryManager.findPagedEntries(fidoDeviceService.getDnForFido2Device(null, userId), GluuFido2Device.class, ldapFilter, null, sortBy, sortOrder, startIndex - 1, count, getMaxCount());
    } catch (Exception e) {
        log.info("Returning an empty listViewReponse");
        log.error(e.getMessage(), e);
        list = new PagedResult<>();
        list.setEntries(new ArrayList<>());
    }
    List<BaseScimResource> resources = new ArrayList<>();
    for (GluuFido2Device device : list.getEntries()) {
        Fido2DeviceResource scimDev = new Fido2DeviceResource();
        transferAttributesToFido2Resource(device, scimDev, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
        resources.add(scimDev);
    }
    log.info("Found {} matching entries - returning {}", list.getTotalEntriesCount(), list.getEntries().size());
    PagedResult<BaseScimResource> result = new PagedResult<>();
    result.setEntries(resources);
    result.setTotalEntriesCount(list.getTotalEntriesCount());
    return result;
}
Also used : Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) Filter(io.jans.orm.search.filter.Filter) ArrayList(java.util.ArrayList) GluuFido2Device(io.jans.scim.model.GluuFido2Device) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) PagedResult(io.jans.orm.model.PagedResult)

Aggregations

Fido2DeviceResource (io.jans.scim.model.scim2.fido.Fido2DeviceResource)7 Response (javax.ws.rs.core.Response)7 ListResponse (io.jans.scim.model.scim2.ListResponse)4 BaseTest (io.jans.scim2.client.BaseTest)4 Test (org.testng.annotations.Test)4 GluuFido2Device (io.jans.scim.model.GluuFido2Device)3 SCIMException (io.jans.scim.model.exception.SCIMException)3 URISyntaxException (java.net.URISyntaxException)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)2 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)2 URI (java.net.URI)2 DefaultValue (javax.ws.rs.DefaultValue)2 HeaderParam (javax.ws.rs.HeaderParam)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 PagedResult (io.jans.orm.model.PagedResult)1 Filter (io.jans.orm.search.filter.Filter)1 BulkResponse (io.jans.scim.model.scim2.bulk.BulkResponse)1 FidoDeviceResource (io.jans.scim.model.scim2.fido.FidoDeviceResource)1