-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from getyoti/release_2.9.0
Release 2.9.0
- Loading branch information
Showing
47 changed files
with
1,838 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,3 +205,5 @@ $RECYCLE.BIN/ | |
|
||
.idea | ||
*.iml | ||
|
||
*.pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/DocScanSandboxClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package com.yoti.api.client.sandbox.docs; | ||
|
||
import static com.yoti.api.client.spi.remote.call.YotiConstants.DEFAULT_YOTI_HOST; | ||
import static com.yoti.api.client.spi.remote.call.YotiConstants.PROPERTY_YOTI_DOCS_URL; | ||
import static com.yoti.api.client.spi.remote.util.Validation.notNull; | ||
import static com.yoti.api.client.spi.remote.util.Validation.notNullOrEmpty; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.security.GeneralSecurityException; | ||
import java.security.KeyPair; | ||
|
||
import com.yoti.api.client.InitialisationException; | ||
import com.yoti.api.client.KeyPairSource; | ||
import com.yoti.api.client.sandbox.SandboxException; | ||
import com.yoti.api.client.sandbox.docs.request.ResponseConfig; | ||
import com.yoti.api.client.spi.remote.KeyStreamVisitor; | ||
import com.yoti.api.client.spi.remote.call.HttpMethod; | ||
import com.yoti.api.client.spi.remote.call.ResourceException; | ||
import com.yoti.api.client.spi.remote.call.SignedRequest; | ||
import com.yoti.api.client.spi.remote.call.SignedRequestBuilder; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DocScanSandboxClient { | ||
|
||
private static final String DOC_SCAN_SANDBOX_PATH_PREFIX = "/sandbox/idverify/v1"; | ||
private static final String DEFAULT_DOC_SCAN_SANDBOX_API_URL = DEFAULT_YOTI_HOST + DOC_SCAN_SANDBOX_PATH_PREFIX; | ||
|
||
private final String docScanBaseUrl; | ||
private final ObjectMapper mapper; | ||
private final String sdkId; | ||
private final KeyPair keyPair; | ||
|
||
DocScanSandboxClient(String sdkId, KeyPair keyPair, ObjectMapper mapper) { | ||
this.sdkId = sdkId; | ||
this.keyPair = keyPair; | ||
this.mapper = mapper; | ||
this.docScanBaseUrl = System.getProperty(PROPERTY_YOTI_DOCS_URL, DEFAULT_DOC_SCAN_SANDBOX_API_URL); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* Configures the response for the given session ID. | ||
* | ||
* @param sessionId the session ID | ||
* @param responseConfig the response configuration | ||
* @throws SandboxException - if there was a problem configuring the response | ||
*/ | ||
public void configureSessionResponse(String sessionId, ResponseConfig responseConfig) throws SandboxException { | ||
String path = String.format("/sessions/%s/response-config", sessionId); | ||
|
||
try { | ||
byte[] body = mapper.writeValueAsBytes(responseConfig); | ||
|
||
SignedRequest signedRequest = getSignedRequestBuilder() | ||
.withBaseUrl(docScanBaseUrl) | ||
.withEndpoint(path) | ||
.withKeyPair(keyPair) | ||
.withHttpMethod(HttpMethod.HTTP_PUT) | ||
.withPayload(body) | ||
.withQueryParameter("sdkId", sdkId) | ||
.build(); | ||
|
||
signedRequest.execute(); | ||
} catch (URISyntaxException | GeneralSecurityException | ResourceException | IOException e) { | ||
throw new SandboxException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Configures the default response for the application | ||
* | ||
* @param sandboxExpectation | ||
*/ | ||
public void configureApplicationResponse(ResponseConfig sandboxExpectation) throws SandboxException { | ||
String path = String.format("/apps/%s/response-config", sdkId); | ||
|
||
try { | ||
byte[] body = mapper.writeValueAsBytes(sandboxExpectation); | ||
|
||
SignedRequest signedRequest = getSignedRequestBuilder() | ||
.withBaseUrl(docScanBaseUrl) | ||
.withEndpoint(path) | ||
.withKeyPair(keyPair) | ||
.withHttpMethod(HttpMethod.HTTP_PUT) | ||
.withPayload(body) | ||
.build(); | ||
|
||
signedRequest.execute(); | ||
} catch (URISyntaxException | GeneralSecurityException | ResourceException | IOException e) { | ||
throw new SandboxException(e); | ||
} | ||
} | ||
|
||
SignedRequestBuilder getSignedRequestBuilder() { | ||
return SignedRequestBuilder.newInstance(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(Builder.class); | ||
|
||
private String sdkId; | ||
private KeyPair keyPair; | ||
|
||
private Builder() { | ||
} | ||
|
||
public Builder withSdkId(String sdkId) { | ||
this.sdkId = sdkId; | ||
return this; | ||
} | ||
|
||
public Builder withKeyPair(KeyPairSource keyPairSource) { | ||
try { | ||
LOGGER.debug("Loading key pair from '{}'", keyPairSource); | ||
this.keyPair = keyPairSource.getFromStream(new KeyStreamVisitor()); | ||
} catch (IOException e) { | ||
throw new InitialisationException("Cannot load key pair", e); | ||
} | ||
return this; | ||
} | ||
|
||
public DocScanSandboxClient build() { | ||
notNullOrEmpty(sdkId, "sdkId"); | ||
notNull(keyPair, "keyPair"); | ||
|
||
return new DocScanSandboxClient(sdkId, keyPair, new ObjectMapper()); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/ResponseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.yoti.api.client.sandbox.docs.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class ResponseConfig { | ||
|
||
@JsonProperty("task_results") | ||
private SandboxTaskResults taskResults; | ||
|
||
@JsonProperty("check_reports") | ||
private SandboxCheckReports checkReports; | ||
|
||
ResponseConfig(SandboxTaskResults taskResults, SandboxCheckReports checkReports) { | ||
this.taskResults = taskResults; | ||
this.checkReports = checkReports; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public SandboxTaskResults getTaskResults() { | ||
return taskResults; | ||
} | ||
|
||
public SandboxCheckReports getCheckReports() { | ||
return checkReports; | ||
} | ||
|
||
/** | ||
* Builder for {@link ResponseConfig} | ||
*/ | ||
public static class Builder { | ||
|
||
private SandboxTaskResults taskResults; | ||
|
||
private SandboxCheckReports sandboxCheckReports; | ||
|
||
public Builder withTaskResults(SandboxTaskResults taskResults) { | ||
this.taskResults = taskResults; | ||
return this; | ||
} | ||
|
||
public Builder withCheckReports(SandboxCheckReports sandboxCheckReports) { | ||
this.sandboxCheckReports = sandboxCheckReports; | ||
return this; | ||
} | ||
|
||
public ResponseConfig build() { | ||
return new ResponseConfig(taskResults, sandboxCheckReports); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.