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;
}
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)
}
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;
}
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());
}
Aggregations