use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice in project oxTrust by GluuFederation.
the class FidoDeviceService method searchFidoDevice.
private GluuCustomFidoDevice searchFidoDevice(Filter filter, String userId, String id) throws Exception {
GluuCustomFidoDevice gluuCustomFidoDevice = null;
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuCustomFidoDevice> gluuCustomFidoDevices = ldapEntryManager.findEntriesVirtualListView(getDnForFidoDevice(userId, id), GluuCustomFidoDevice.class, filter, 1, 1, "oxId", SortOrder.ASCENDING, vlvResponse, null);
if (gluuCustomFidoDevices != null && !gluuCustomFidoDevices.isEmpty() && vlvResponse.getTotalResults() > 0) {
gluuCustomFidoDevice = gluuCustomFidoDevices.get(0);
}
return gluuCustomFidoDevice;
}
use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice in project oxTrust by GluuFederation.
the class FidoDeviceService method getGluuCustomFidoDeviceById.
@Override
public GluuCustomFidoDevice getGluuCustomFidoDeviceById(String userId, String id) {
GluuCustomFidoDevice gluuCustomFidoDevice = null;
try {
Filter filter = Filter.create("oxId=" + id);
gluuCustomFidoDevice = searchFidoDevice(filter, userId, id);
} catch (Exception e) {
log.error("Failed to find device by id " + id, e);
}
return gluuCustomFidoDevice;
}
use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice in project oxTrust by GluuFederation.
the class CopyUtils2 method updateGluuCustomFidoDevice.
public GluuCustomFidoDevice updateGluuCustomFidoDevice(FidoDevice source, GluuCustomFidoDevice destination) {
if (source == null) {
return null;
}
if (destination == null) {
destination = new GluuCustomFidoDevice();
}
// Only update displayName and description
// All the other fields are not editable
destination.setDisplayName(source.getDisplayName());
destination.setDescription(source.getDescription());
return destination;
}
use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
public FidoDevice copy(GluuCustomFidoDevice source, FidoDevice destination) {
if (source == null) {
return null;
}
if (destination == null) {
destination = new FidoDevice();
}
destination.setId(source.getId());
destination.setCreationDate(source.getCreationDate());
destination.setApplication(source.getApplication());
destination.setCounter(source.getCounter());
destination.setDeviceData(source.getDeviceData());
destination.setDeviceHashCode(source.getDeviceHashCode());
destination.setDeviceKeyHandle(source.getDeviceKeyHandle());
destination.setDeviceRegistrationConf(source.getDeviceRegistrationConf());
destination.setLastAccessTime(source.getLastAccessTime());
destination.setStatus(source.getStatus());
destination.setDisplayName(source.getDisplayName());
destination.setDescription(source.getDescription());
if (source.getDn() != null) {
String[] dnArray = source.getDn().split("\\,");
for (String e : dnArray) {
if (e.startsWith("inum=")) {
String[] inumArray = e.split("\\=");
if (inumArray.length > 1) {
destination.setUserId(inumArray[1]);
}
}
}
}
Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
if (source.getMetaVersion() != null) {
meta.setVersion(source.getMetaVersion());
}
String location = source.getMetaLocation();
if (location != null && !location.isEmpty()) {
if (!location.startsWith("https://") && !location.startsWith("http://")) {
location = appConfiguration.getBaseEndpoint() + location;
}
} else {
location = appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices/" + source.getId();
}
meta.setLocation(location);
if (source.getCreationDate() != null && !source.getCreationDate().isEmpty()) {
try {
meta.setCreated(new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'").parse(source.getCreationDate()));
} catch (Exception e) {
log.error(" Date parse exception (OLD format)", e);
}
}
if (source.getMetaLastModified() != null && !source.getMetaLastModified().isEmpty()) {
try {
DateTime dateTimeUtc = new DateTime(source.getMetaLastModified(), DateTimeZone.UTC);
meta.setLastModified(dateTimeUtc.toDate());
} catch (Exception e) {
log.error(" Date parse exception (NEW format), continuing...", e);
try {
meta.setLastModified(new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'").parse(source.getMetaLastModified()));
} catch (Exception ex) {
log.error(" Date parse exception (OLD format)", ex);
}
}
}
destination.setMeta(meta);
return destination;
}
use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice in project oxTrust by GluuFederation.
the class FidoDeviceWebService method getDeviceById.
@Path("{id}")
@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 = "Find device by id", notes = "Returns a device by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.1)", response = FidoDevice.class)
public Response getDeviceById(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @QueryParam("userId") final String userId, @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 {
String baseDn = fidoDeviceService.getDnForFidoDevice(userId, id);
log.info("##### baseDn = " + baseDn);
String filterString = "id eq \"" + id + "\"";
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuCustomFidoDevice> gluuCustomFidoDevices = search(baseDn, GluuCustomFidoDevice.class, filterString, 1, 1, "id", SortOrder.ASCENDING.getValue(), vlvResponse, attributesArray);
if (gluuCustomFidoDevices == null || gluuCustomFidoDevices.isEmpty() || vlvResponse.getTotalResults() == 0) {
// sets HTTP status code 404 Not Found
return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
} else {
log.info(" Resource " + id + " found ");
}
GluuCustomFidoDevice gluuCustomFidoDevice = gluuCustomFidoDevices.get(0);
FidoDevice fidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
// Serialize to JSON
String json = serializeToJson(fidoDevice, attributesArray);
URI uriLocation = new URI(fidoDevice.getMeta().getLocation());
return Response.ok(json).location(uriLocation).build();
} catch (EntryPersistenceException epe) {
log.error("Error in getDeviceById", epe);
epe.printStackTrace();
return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
} catch (Exception e) {
log.error("Error in getDeviceById", e);
e.printStackTrace();
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
Aggregations