use of io.jans.scim.model.GluuFido2Device 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.GluuFido2Device in project jans by JanssenProject.
the class Fido2DeviceWebService method deleteF2Device.
@Path("{id}")
@DELETE
@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" })
public Response deleteF2Device(@PathParam("id") String id) {
Response response;
try {
log.debug("Executing web service method. deleteDevice");
GluuFido2Device device = fidoDeviceService.getFido2DeviceById(null, id);
if (device == null)
return notFoundResponse(id, fido2ResourceType);
response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.DELETE, fido2ResourceType);
if (response != null)
return response;
fidoDeviceService.removeFido2Device(device);
response = Response.noContent().build();
} catch (Exception e) {
log.error("Failure at deleteDevice method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.GluuFido2Device in project jans by JanssenProject.
the class Fido2DeviceService method getFido2DeviceById.
public GluuFido2Device getFido2DeviceById(String userId, String id) {
GluuFido2Device f2d = null;
try {
String dn = getDnForFido2Device(id, userId);
if (StringUtils.isNotEmpty(userId)) {
f2d = ldapEntryManager.find(GluuFido2Device.class, dn);
} else {
Filter filter = Filter.createEqualityFilter("jansId", id);
f2d = ldapEntryManager.findEntries(dn, GluuFido2Device.class, filter).get(0);
}
} catch (Exception e) {
log.error("Failed to find Fido 2 device with id " + id, e);
}
return f2d;
}
use of io.jans.scim.model.GluuFido2Device 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;
}
use of io.jans.scim.model.GluuFido2Device 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;
}
Aggregations