use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice in project oxTrust by GluuFederation.
the class FidoDeviceWebService method searchDevices.
@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search devices", notes = "Returns a list of devices (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchDevices(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam("userId") final String userId, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
Response authorizationResponse;
if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
log.info(" ##### SCIM Test Mode is ACTIVE");
authorizationResponse = processTestModeAuthorization(token);
} else {
authorizationResponse = processAuthorization(authorization);
}
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
} else {
log.info(" Searching devices from LDAP ");
String baseDn = fidoDeviceService.getDnForFidoDevice(userId, null);
log.info("##### baseDn = " + baseDn);
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuCustomFidoDevice> gluuCustomFidoDevices = search(baseDn, GluuCustomFidoDevice.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
ListResponse devicesListResponse = new ListResponse();
List<String> schema = new ArrayList<String>();
schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
log.info(" setting schema");
devicesListResponse.setSchemas(schema);
// Set total
devicesListResponse.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && gluuCustomFidoDevices != null && !gluuCustomFidoDevices.isEmpty()) {
for (GluuCustomFidoDevice gluuCustomFidoDevice : gluuCustomFidoDevices) {
FidoDevice fidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
devicesListResponse.getResources().add(fidoDevice);
}
// Set the rest of results info
devicesListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
devicesListResponse.setStartIndex(vlvResponse.getStartIndex());
}
// Serialize to JSON
String json = serializeToJson(devicesListResponse, attributesArray);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices");
return Response.ok(json).location(location).build();
}
} catch (Exception e) {
log.error("Error in searchDevices", e);
e.printStackTrace();
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice in project oxTrust by GluuFederation.
the class Scim2FidoDeviceService method updateFidoDevice.
public FidoDevice updateFidoDevice(String id, FidoDevice fidoDevice) throws Exception {
GluuCustomFidoDevice gluuCustomFidoDevice = fidoDeviceService.getGluuCustomFidoDeviceById(fidoDevice.getUserId(), id);
if (gluuCustomFidoDevice == null) {
throw new EntryPersistenceException("Scim2FidoDeviceService.updateFidoDevice(): Resource " + id + " not found");
}
GluuCustomFidoDevice updatedGluuCustomFidoDevice = copyUtils2.updateGluuCustomFidoDevice(fidoDevice, gluuCustomFidoDevice);
log.info(" Setting meta: update device ");
// Date should be in UTC format
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
Date dateLastModified = DateTime.now().toDate();
updatedGluuCustomFidoDevice.setMetaLastModified(dateTimeFormatter.print(dateLastModified.getTime()));
if (updatedGluuCustomFidoDevice.getMetaLocation() == null || (updatedGluuCustomFidoDevice.getMetaLocation() != null && updatedGluuCustomFidoDevice.getMetaLocation().isEmpty())) {
String relativeLocation = "/scim/v2/FidoDevices/" + id;
updatedGluuCustomFidoDevice.setMetaLocation(relativeLocation);
}
fidoDeviceService.updateGluuCustomFidoDevice(gluuCustomFidoDevice);
FidoDevice updatedFidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
return updatedFidoDevice;
}
use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice in project oxTrust by GluuFederation.
the class Scim2FidoDeviceService method deleteFidoDevice.
public void deleteFidoDevice(String id) throws Exception {
GluuCustomFidoDevice gluuCustomFidoDevice = fidoDeviceService.getGluuCustomFidoDeviceById(null, id);
if (gluuCustomFidoDevice == null) {
throw new EntryPersistenceException("Scim2FidoDeviceService.deleteFidoDevice(): Resource " + id + " not found");
}
fidoDeviceService.removeGluuCustomFidoDevice(gluuCustomFidoDevice);
}
Aggregations