Search in sources :

Example 11 with FidoDeviceResource

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

the class FidoDeviceWebService method getDeviceById.

@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
@RefAdjusted
@ApiOperation(value = "Find device by id", notes = "Returns a device by id as path param", response = FidoDeviceResource.class)
public Response getDeviceById(@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. getDeviceById");
        FidoDeviceResource fidoResource = new FidoDeviceResource();
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            throw new SCIMException("Resource " + id + " not found");
        transferAttributesToFidoResource(device, fidoResource, endpointUrl, userId);
        String json = resourceSerializer.serialize(fidoResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(fidoResource.getMeta().getLocation())).entity(json).build();
    } catch (SCIMException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at getDeviceById method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 12 with FidoDeviceResource

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

the class FidoU2fDeviceTest method updateWithObject.

@Test(dependsOnMethods = "updateWithJson")
public void updateWithObject() throws Exception {
    logger.debug("Updating device to original attributes");
    Response response = client.updateDevice(device, device.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    FidoDeviceResource updated = response.readEntity(fidoClass);
    // Naively compare (property-to-property) the original and new object. It's feasible since all of them are strings
    for (String path : IntrospectUtil.allAttrs.get(fidoClass)) {
        String val = BeanUtils.getProperty(device, path);
        // Exclude metas since they diverge and skip if original attribute was null (when passing null for an update, server ignores)
        if (!path.startsWith("meta") && val != null)
            assertEquals(BeanUtils.getProperty(updated, path), val);
    }
    // Update an immutable attribute (originally null). Per spec, uninitialized immutable attributes can be set
    assertNull(updated.getDeviceData());
    updated.setDeviceData("Dummy device data");
    response = client.updateDevice(updated, updated.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    updated = response.readEntity(fidoClass);
    assertNotNull(updated.getDeviceData());
// NOTE: if you don't see device data attribute for this device in LDAP is because the attribute is marked as being
// ignored upon update (see io.jans.scim.model.fido.GluuCustomFidoDevice)
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Example 13 with FidoDeviceResource

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

the class FidoDeviceWebService method getDeviceById.

@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/fido.read" })
@RefAdjusted
public Response getDeviceById(@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. getDeviceById");
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fidoResourceType);
        response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.GET, fidoResourceType);
        if (response != null)
            return response;
        FidoDeviceResource fidoResource = new FidoDeviceResource();
        transferAttributesToFidoResource(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 getDeviceById method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) 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 14 with FidoDeviceResource

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

the class FidoDeviceWebService method transferAttributesToFidoResource.

private void transferAttributesToFidoResource(GluuCustomFidoDevice fidoDevice, FidoDeviceResource res, String url, String userId) {
    res.setId(fidoDevice.getId());
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    String strDate = fidoDevice.getCreationDate();
    meta.setCreated(ldapBackend ? DateUtil.generalizedToISOStringDate(strDate) : (strDate + "Z"));
    meta.setLastModified(fidoDevice.getMetaLastModified());
    meta.setLocation(fidoDevice.getMetaLocation());
    if (meta.getLocation() == null)
        meta.setLocation(url + "/" + fidoDevice.getId());
    res.setMeta(meta);
    // Set values in order of appearance in FidoDeviceResource class
    res.setUserId(userId);
    res.setCreationDate(meta.getCreated());
    res.setApplication(fidoDevice.getApplication());
    res.setCounter(fidoDevice.getCounter());
    res.setDeviceData(fidoDevice.getDeviceData());
    res.setDeviceHashCode(fidoDevice.getDeviceHashCode());
    res.setDeviceKeyHandle(fidoDevice.getDeviceKeyHandle());
    res.setDeviceRegistrationConf(fidoDevice.getDeviceRegistrationConf());
    strDate = fidoDevice.getLastAccessTime();
    if (strDate != null) {
        res.setLastAccessTime(ldapBackend ? DateUtil.generalizedToISOStringDate(strDate) : (strDate + "Z"));
    }
    res.setStatus(fidoDevice.getStatus());
    res.setDisplayName(fidoDevice.getDisplayName());
    res.setDescription(fidoDevice.getDescription());
    res.setNickname(fidoDevice.getNickname());
}
Also used : Meta(io.jans.scim.model.scim2.Meta)

Aggregations

Response (javax.ws.rs.core.Response)11 FidoDeviceResource (io.jans.scim.model.scim2.fido.FidoDeviceResource)8 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 URI (java.net.URI)5 DefaultValue (javax.ws.rs.DefaultValue)5 HeaderParam (javax.ws.rs.HeaderParam)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 SCIMException (io.jans.scim.model.exception.SCIMException)4 ListResponse (io.jans.scim.model.scim2.ListResponse)4 BaseTest (io.jans.scim2.client.BaseTest)4 URISyntaxException (java.net.URISyntaxException)4 FidoDeviceResource (org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource)4 Test (org.testng.annotations.Test)4 GluuCustomFidoDevice (io.jans.scim.model.fido.GluuCustomFidoDevice)3 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)3 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)3 Consumes (javax.ws.rs.Consumes)3 PUT (javax.ws.rs.PUT)3 GluuCustomFidoDevice (org.gluu.oxtrust.model.fido.GluuCustomFidoDevice)3