Skip to content

Commit

Permalink
Merge pull request #413 from getyoti/SDK-2230
Browse files Browse the repository at this point in the history
SDK-2230: Expose share v2 API
  • Loading branch information
irotech authored Oct 6, 2023
2 parents cc6b6e8 + 84977a4 commit e1034b8
Show file tree
Hide file tree
Showing 79 changed files with 5,063 additions and 726 deletions.
2 changes: 1 addition & 1 deletion examples/doc-scan/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.10</version>
<version>2.7.16</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<!-- plugin versions -->
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
<properties-maven-plugin.version>1.1.0</properties-maven-plugin.version>
<spotbugs-maven-plugin.version>4.7.3.4</spotbugs-maven-plugin.version>
</properties>

<build>
Expand Down Expand Up @@ -56,6 +57,11 @@
</executions>
</plugin>

<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
</plugin>
</plugins>
</build>

Expand Down
6 changes: 6 additions & 0 deletions yoti-sdk-api/spotbugs/exclude-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<Package name="com.yoti.api.client.spi.remote.proto"/>
</Match>

<!-- The IV comes from a trusted source -->
<Match>
<Class name="com.yoti.api.client.spi.remote.call.identity.ReceiptItemKey$Builder"/>
<Bug pattern="STATIC_IV"/>
</Match>

<!-- Legacy exclusions -->
<Match>
<Bug pattern="CRLF_INJECTION_LOGS"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.yoti.api.client;

import java.io.IOException;
import java.security.KeyPair;
import java.security.Security;

import com.yoti.api.client.identity.ShareSession;
import com.yoti.api.client.identity.ShareSessionQrCode;
import com.yoti.api.client.identity.ShareSessionRequest;
import com.yoti.api.client.spi.remote.KeyStreamVisitor;
import com.yoti.api.client.spi.remote.call.identity.DigitalIdentityException;
import com.yoti.api.client.spi.remote.call.identity.DigitalIdentityService;
import com.yoti.api.client.spi.remote.call.identity.Receipt;
import com.yoti.validation.Validation;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class DigitalIdentityClient {

static {
Security.addProvider(new BouncyCastleProvider());
}

private final String sdkId;
private final KeyPair keyPair;
private final DigitalIdentityService identityService;

DigitalIdentityClient(String sdkId, KeyPairSource keyPair, DigitalIdentityService identityService) {
Validation.notNullOrEmpty(sdkId, "SDK ID");
Validation.notNull(keyPair, "Application Key Pair");

this.sdkId = sdkId;
this.keyPair = loadKeyPair(keyPair);
this.identityService = identityService;
}

public ShareSession createShareSession(ShareSessionRequest request) throws DigitalIdentityException {
return identityService.createShareSession(sdkId, keyPair, request);
}

public ShareSession fetchShareSession(String sessionId) throws DigitalIdentityException {
return identityService.fetchShareSession(sdkId, keyPair, sessionId);
}

public ShareSessionQrCode createShareQrCode(String sessionId) throws DigitalIdentityException {
return identityService.createShareQrCode(sdkId, keyPair, sessionId);
}

public ShareSessionQrCode fetchShareQrCode(String qrCodeId) throws DigitalIdentityException {
return identityService.fetchShareQrCode(sdkId, keyPair, qrCodeId);
}

public Receipt fetchShareReceipt(String receiptId) throws DigitalIdentityException {
return identityService.fetchShareReceipt(sdkId, keyPair, receiptId);
}

private KeyPair loadKeyPair(KeyPairSource keyPairSource) throws InitialisationException {
try {
return keyPairSource.getFromStream(new KeyStreamVisitor());
} catch (IOException ex) {
throw new InitialisationException("Cannot load Key Pair", ex);
}
}

public static Builder builder() {
return new Builder();
}

public static class Builder {

private String sdkId;
private KeyPairSource keyPairSource;

private Builder() { }

public Builder withClientSdkId(String sdkId) {
Validation.notNullOrEmpty(sdkId, "SDK ID");

this.sdkId = sdkId;
return this;
}

public Builder withKeyPairSource(KeyPairSource keyPairSource) {
Validation.notNull(keyPairSource, "Key Pair Source");

this.keyPairSource = keyPairSource;
return this;
}

public DigitalIdentityClient build() {
return new DigitalIdentityClient(sdkId, keyPairSource, DigitalIdentityService.newInstance());
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public InitialisationException(String message) {
public InitialisationException(String message, Throwable cause) {
super(message, cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public interface KeyPairSource {
*/
KeyPair getFromStream(StreamVisitor streamVisitor) throws IOException, InitialisationException;

public static interface StreamVisitor {
interface StreamVisitor {
KeyPair accept(InputStream stream) throws IOException, InitialisationException;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public ShareUrlResult createShareUrl(DynamicScenario dynamicScenario) throws Dyn

private KeyPair loadKeyPair(KeyPairSource kpSource) throws InitialisationException {
try {
LOG.debug("Loading key pair from '{}'", kpSource);
return kpSource.getFromStream(new KeyStreamVisitor());
} catch (IOException e) {
throw new InitialisationException("Cannot load key pair", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.yoti.api.client.identity;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ShareSession {

private String id;
private String status;
private String created;
private String updated;
private String expiry;
private String qrCodeId;
private String receiptId;

public String getId() {
return id;
}

public String getStatus() {
return status;
}

public String getCreated() {
return created;
}

public String getUpdated() {
return updated;
}

public String getExpiry() {
return expiry;
}

public String getQrCodeId() {
return qrCodeId;
}

public String getReceiptId() {
return receiptId;
}

@JsonProperty(Property.ID)
public void setId(String id) {
this.id = id;
}

@JsonProperty(Property.STATUS)
public void setStatus(String status) {
this.status = status;
}

@JsonProperty(Property.CREATED)
public void setCreated(String created) {
this.created = created;
}

@JsonProperty(Property.UPDATED)
public void setUpdated(String updated) {
this.updated = updated;
}

@JsonProperty(Property.EXPIRY)
public void setExpiry(String expiry) {
this.expiry = expiry;
}

@JsonProperty(Property.QR_CODE)
public void setQrCodeId(Map<String, Object> qrCode) {
this.qrCodeId = (String) qrCode.get(Property.ID);
}

@JsonProperty(Property.RECEIPT)
public void setReceiptId(Map<String, Object> receipt) {
this.receiptId = (String) receipt.get(Property.ID);
}

private static final class Property {

private static final String ID = "id";
private static final String CREATED = "created";
private static final String UPDATED = "updated";
private static final String STATUS = "status";
private static final String EXPIRY = "expiry";
private static final String QR_CODE = "qrCode";
private static final String RECEIPT = "receipt";

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.yoti.api.client.identity;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import com.yoti.validation.Validation;

import com.fasterxml.jackson.annotation.JsonProperty;

public final class ShareSessionNotification {

@JsonProperty(Property.URL)
private final String url;

@JsonProperty(Property.METHOD)
private final String method;

@JsonProperty(Property.VERIFY_TLS)
private final boolean verifyTls;

@JsonProperty(Property.HEADERS)
private final Map<String, String> headers;

private ShareSessionNotification(Builder builder) {
url = builder.url;
method = builder.method;
verifyTls = builder.verifyTls;
headers = builder.headers;
}

public String getUrl() {
return url;
}

public String getMethod() {
return method;
}

public boolean isVerifyTls() {
return verifyTls;
}

public Map<String, String> getHeaders() {
return headers;
}

public static Builder builder(URI uri) {
return new Builder(uri);
}

public static final class Builder {

private final String url;
private final Map<String, String> headers;

private String method;
private boolean verifyTls;

private Builder(URI uri) {
url = uri.toString();
method = "POST";
verifyTls = true;
headers = new HashMap<>();
}

public Builder withMethod(String method) {
this.method = method;
return this;
}

public Builder withVerifyTls(boolean verifyTls) {
this.verifyTls = verifyTls;
return this;
}

public Builder withHeaders(Map<String, String> headers) {
this.headers.putAll(headers);
return this;
}

public Builder withHeader(String key, String value) {
headers.put(key, value);
return this;
}

public ShareSessionNotification build() {
Validation.notNullOrEmpty(url, Property.URL);

return new ShareSessionNotification(this);
}

}

private static final class Property {

private static final String URL = "url";
private static final String METHOD = "method";
private static final String VERIFY_TLS = "verifyTls";
private static final String HEADERS = "headers";

}

}
Loading

0 comments on commit e1034b8

Please sign in to comment.