Skip to content

Commit

Permalink
SDK-2478: Allow the Relying Business to retrieve tracked devices for …
Browse files Browse the repository at this point in the history
…a session
  • Loading branch information
MrBurtyyy committed Sep 24, 2024
1 parent 1538ee0 commit 9f5b6ee
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.security.KeyPair;
import java.security.Security;
import java.util.List;

import com.yoti.api.client.InitialisationException;
import com.yoti.api.client.KeyPairSource;
Expand All @@ -14,6 +15,7 @@
import com.yoti.api.client.docs.session.create.SessionSpec;
import com.yoti.api.client.docs.session.create.facecapture.CreateFaceCaptureResourcePayload;
import com.yoti.api.client.docs.session.create.facecapture.UploadFaceCaptureImagePayload;
import com.yoti.api.client.docs.session.devicemetadata.MetadataResponse;
import com.yoti.api.client.docs.session.instructions.Instructions;
import com.yoti.api.client.docs.session.retrieve.CreateFaceCaptureResourceResponse;
import com.yoti.api.client.docs.session.retrieve.GetSessionResult;
Expand Down Expand Up @@ -242,6 +244,19 @@ public SessionConfigurationResponse getSessionConfiguration(String sessionId) th
return docScanService.fetchSessionConfiguration(sdkId, keyPair, sessionId);
}

/**
* Fetches the tracked devices used by the end user, to interact with the given sessionID.
*
* @param sessionId the session ID
*
* @return the session configuration
* @throws DocScanException if an error has occurred
*/
public List<MetadataResponse> getTrackedDevices(String sessionId) throws DocScanException {
LOG.debug("Fetching tracked devices for session '{}'", sessionId);
return docScanService.getTrackedDevices(sdkId, keyPair, sessionId);
}

private KeyPair loadKeyPair(KeyPairSource kpSource) throws InitialisationException {
try {
LOG.debug("Loading key pair from '{}'", kpSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.yoti.api.client.docs.session.create.SessionSpec;
import com.yoti.api.client.docs.session.create.facecapture.CreateFaceCaptureResourcePayload;
import com.yoti.api.client.docs.session.create.facecapture.UploadFaceCaptureImagePayload;
import com.yoti.api.client.docs.session.devicemetadata.MetadataResponse;
import com.yoti.api.client.docs.session.instructions.Instructions;
import com.yoti.api.client.docs.session.retrieve.CreateFaceCaptureResourceResponse;
import com.yoti.api.client.docs.session.retrieve.GetSessionResult;
Expand All @@ -39,6 +40,7 @@
import com.yoti.api.client.spi.remote.call.factory.UnsignedPathFactory;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand All @@ -52,6 +54,9 @@
final class DocScanService {

private static final Logger LOG = LoggerFactory.getLogger(DocScanService.class);

private static final TypeReference<List<MetadataResponse>> METADATA_RESPONSE_TYPE_REF = new TypeReference<List<MetadataResponse>>() {};

private static final int HTTP_STATUS_NO_CONTENT = 204;
private static final String YOTI_MULTIPART_BOUNDARY = "yoti-doc-scan-boundary";

Expand Down Expand Up @@ -527,6 +532,30 @@ public void triggerIbvEmailNotification(String sdkId, KeyPair keyPair, String se
}
}

public List<MetadataResponse> getTrackedDevices(String sdkId, KeyPair keyPair, String sessionId) throws DocScanException {
notNullOrEmpty(sdkId, "SDK ID");
notNull(keyPair, "Application key Pair");
notNullOrEmpty(sessionId, "sessionId");

String path = unsignedPathFactory.createFetchTrackedDevices(sdkId, sessionId);
LOG.info("Fetching tracked devices at '{}'", path);

try {
SignedRequest signedRequest = signedRequestBuilderFactory.create()
.withKeyPair(keyPair)
.withBaseUrl(apiUrl)
.withEndpoint(path)
.withHttpMethod(HTTP_GET)
.build();

return signedRequest.execute(METADATA_RESPONSE_TYPE_REF);
} catch (GeneralSecurityException | ResourceException ex) {
throw new DocScanException("Error executing the GET: " + ex.getMessage(), ex);
} catch (IOException | URISyntaxException ex) {
throw new DocScanException("Error building the request: " + ex.getMessage(), ex);
}
}

private String findContentType(SignedRequestResponse response) {
List<String> contentTypeValues = null;
for (Map.Entry<String, List<String>> entry : response.getResponseHeaders().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.yoti.api.client.docs.session.devicemetadata;

import com.fasterxml.jackson.annotation.JsonProperty;

public class DeviceResponse {

@JsonProperty("ip_address")
private String ipAddress;

@JsonProperty("ip_iso_country_code")
private String ipIsoCountryCode;

@JsonProperty("manufacture_name")
private String manufactureName;

@JsonProperty("model_name")
private String modelName;

@JsonProperty("os_name")
private String osName;

@JsonProperty("os_version")
private String osVersion;

@JsonProperty("browser_name")
private String browserName;

@JsonProperty("browser_version")
private String browserVersion;

@JsonProperty("locale")
private String locale;

@JsonProperty("client_version")
private String clientVersion;

public String getIpAddress() {
return ipAddress;
}

public String getIpIsoCountryCode() {
return ipIsoCountryCode;
}

public String getManufactureName() {
return manufactureName;
}

public String getModelName() {
return modelName;
}

public String getOsName() {
return osName;
}

public String getOsVersion() {
return osVersion;
}

public String getBrowserName() {
return browserName;
}

public String getBrowserVersion() {
return browserVersion;
}

public String getLocale() {
return locale;
}

public String getClientVersion() {
return clientVersion;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.yoti.api.client.docs.session.devicemetadata;

import com.fasterxml.jackson.annotation.JsonProperty;

public class MetadataResponse {

@JsonProperty("event")
private String event;

@JsonProperty("created")
private String created;

@JsonProperty("device")
private DeviceResponse device;

public String getEvent() {
return event;
}

public String getCreated() {
return created;
}

public DeviceResponse getDevice() {
return device;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.yoti.api.client.docs.session.retrieve.configuration.capture.liveness.RequiredLivenessResourceResponse;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
Expand Down Expand Up @@ -40,4 +41,9 @@ public <T> T doRequest(SignedRequest signedRequest, Class<T> resourceClass) thro
return objectMapper.readValue(signedRequestResponse.getResponseBody(), resourceClass);
}

public <T> T doRequest(SignedRequest signedRequest, TypeReference<T> resourceClass) throws ResourceException, IOException {
SignedRequestResponse signedRequestResponse = rawResourceFetcher.doRequest(signedRequest);
return objectMapper.readValue(signedRequestResponse.getResponseBody(), resourceClass);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import com.yoti.api.client.Image;

import com.fasterxml.jackson.core.type.TypeReference;

public class SignedRequest {

private final URI uri;
Expand Down Expand Up @@ -56,6 +58,10 @@ public <T> T execute(Class<T> clazz) throws ResourceException, IOException {
return jsonResourceFetcher.doRequest(this, clazz);
}

public <T> T execute(TypeReference<T> typeReference) throws ResourceException, IOException {
return jsonResourceFetcher.doRequest(this, typeReference);
}

public SignedRequestResponse execute() throws ResourceException, IOException {
return rawResourceFetcher.doRequest(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class UnsignedPathFactory {
private static final String DOCS_NEW_FACE_CAPTURE_RESOURCE = "/sessions/%s/resources/face-capture?sdkId=%s";
private static final String DOCS_UPLOAD_FACE_CAPTURE_IMAGE = "/sessions/%s/resources/face-capture/%s/image?sdkId=%s";
private static final String DOCS_TRIGGER_IBV_NOTIFICATION = "/sessions/%s/instructions/email?sdkId=%s";
private static final String DOCS_FETCH_TRACKED_DEVICES = "/sessions/%s/tracked-devices?sdkId=%s";

public String createAmlPath(String appId) {
return format(AML, appId);
Expand Down Expand Up @@ -121,4 +122,8 @@ public String createTriggerIbvEmailNotificationPath(String sdkId, String session
return format(DOCS_TRIGGER_IBV_NOTIFICATION, sessionId, sdkId);
}

public String createFetchTrackedDevices(String sdkId, String sessionId) {
return format(DOCS_FETCH_TRACKED_DEVICES, sessionId, sdkId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,15 @@ public void getSupportedDocuments_shouldFailWithExceptionFromYotiDocsService() t
assertThat(thrown, is(original));
}

@Test
public void getTrackedDevices_shouldFailWithExceptionFromYotiDocsService() throws Exception {
DocScanException original = new DocScanException("Test exception");
doThrow(original).when(docScanServiceMock).getTrackedDevices(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID));
DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock);

DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getTrackedDevices(SOME_SESSION_ID));

assertThat(thrown, is(original));
}

}
Loading

0 comments on commit 9f5b6ee

Please sign in to comment.