use of io.jans.scim.model.scim2.fido.Fido2DeviceResource in project jans by JanssenProject.
the class BulkWebService method execute.
private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
Response response = null;
String idCreated = null;
try {
if (ws == userWS)
switch(verb) {
case PUT:
UserResource user = mapper.readValue(data, UserResource.class);
response = userWS.updateUser(user, fragment, "id", null);
break;
case DELETE:
response = userWS.deleteUser(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = userWS.patchUser(pr, fragment, "id", null);
break;
case POST:
user = mapper.readValue(data, UserResource.class);
response = userWS.createUser(user, "id", null);
if (CREATED.getStatusCode() == response.getStatus()) {
user = mapper.readValue(response.getEntity().toString(), UserResource.class);
idCreated = user.getId();
}
break;
}
else if (ws == groupWS)
switch(verb) {
case PUT:
GroupResource group = mapper.readValue(data, GroupResource.class);
response = groupWS.updateGroup(group, fragment, "id", null);
break;
case DELETE:
response = groupWS.deleteGroup(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = groupWS.patchGroup(pr, fragment, "id", null);
break;
case POST:
group = mapper.readValue(data, GroupResource.class);
response = groupWS.createGroup(group, "id", null);
if (CREATED.getStatusCode() == response.getStatus()) {
group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
idCreated = group.getId();
}
break;
}
else if (ws == fidoDeviceWS)
switch(verb) {
case PUT:
FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
break;
case DELETE:
response = fidoDeviceWS.deleteDevice(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
break;
case POST:
response = fidoDeviceWS.createDevice();
break;
}
else if (ws == fido2DeviceWS)
switch(verb) {
case PUT:
Fido2DeviceResource dev = mapper.readValue(data, Fido2DeviceResource.class);
response = fido2DeviceWS.updateF2Device(dev, fragment, "id", null);
break;
case DELETE:
response = fido2DeviceWS.deleteF2Device(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = fido2DeviceWS.patchF2Device(pr, fragment, "id", null);
break;
case POST:
response = fido2DeviceWS.createDevice();
break;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return new Pair<>(response, idCreated);
}
use of io.jans.scim.model.scim2.fido.Fido2DeviceResource in project jans by JanssenProject.
the class Fido2DeviceWebService method updateF2Device.
@Path("{id}")
@PUT
@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(scopes = { "https://jans.io/scim/fido2.write" })
@RefAdjusted
public Response updateF2Device(Fido2DeviceResource fidoDeviceResource, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
Response response;
try {
log.debug("Executing web service method. updateDevice");
// remove externalId, no place to store it in LDAP
fidoDeviceResource.setExternalId(null);
if (fidoDeviceResource.getId() != null && !fidoDeviceResource.getId().equals(id))
throw new SCIMException("Parameter id does not match id attribute of Device");
String userId = fidoDeviceResource.getUserId();
GluuFido2Device device = fidoDeviceService.getFido2DeviceById(userId, id);
if (device == null)
return notFoundResponse(id, fido2ResourceType);
response = externalConstraintsService.applyEntityCheck(device, fidoDeviceResource, httpHeaders, uriInfo, HttpMethod.PUT, fido2ResourceType);
if (response != null)
return response;
executeValidation(fidoDeviceResource, true);
Fido2DeviceResource updatedResource = new Fido2DeviceResource();
transferAttributesToFido2Resource(device, updatedResource, endpointUrl, userId);
updatedResource.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
updatedResource = (Fido2DeviceResource) ScimResourceUtil.transferToResourceReplace(fidoDeviceResource, updatedResource, extService.getResourceExtensions(updatedResource.getClass()));
transferAttributesToDevice(updatedResource, device);
fidoDeviceService.updateFido2Device(device);
String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
} catch (SCIMException e) {
log.error("Validation check error: {}", e.getMessage());
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
} catch (InvalidAttributeValueException e) {
log.error(e.getMessage());
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
} catch (Exception e) {
log.error("Failure at updateDevice method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.scim2.fido.Fido2DeviceResource 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());
}
use of io.jans.scim.model.scim2.fido.Fido2DeviceResource in project jans by JanssenProject.
the class Fido2DeviceTest method updateWithObject.
@Test(dependsOnMethods = "updateWithJson")
public void updateWithObject() throws Exception {
logger.debug("Updating device to original attributes");
Response response = client.updateF2Device(device, device.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
Fido2DeviceResource updated = response.readEntity(fido2Class);
// 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(fido2Class)) {
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
updated.setCounter(Integer.MIN_VALUE);
response = client.updateF2Device(updated, updated.getId(), null, null);
assertEquals(response.getStatus(), BAD_REQUEST.getStatusCode());
}
use of io.jans.scim.model.scim2.fido.Fido2DeviceResource in project jans by JanssenProject.
the class Fido2DeviceTest method updateWithJson.
@Test(dependsOnMethods = "retrieve")
public void updateWithJson() throws Exception {
// shallow clone device
Fido2DeviceResource clone = (Fido2DeviceResource) BeanUtils.cloneBean(device);
String name = "The quick brown fox jumps over the lazy dog";
clone.setDisplayName(name);
String json = mapper.writeValueAsString(clone);
logger.debug("Updating device with json");
Response response = client.updateF2Device(json, device.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
Fido2DeviceResource updated = response.readEntity(fido2Class);
assertNotEquals(updated.getDisplayName(), device.getDisplayName());
assertEquals(updated.getDisplayName(), name);
}
Aggregations