From 2f364044c51fb3155df3dc9e1d8c2914ad97310a Mon Sep 17 00:00:00 2001 From: john Date: Mon, 8 May 2017 13:51:04 -0400 Subject: [PATCH] PB-1004. Support for signer verification. --- .../com/silanis/esl/api/model/Signer.java | 32 ---- .../silanis/esl/api/model/Verification.java | 67 +++++++ .../silanis/esl/sdk/AuthenticationMethod.java | 4 - .../java/com/silanis/esl/sdk/EslClient.java | 10 +- .../main/java/com/silanis/esl/sdk/Signer.java | 21 +-- .../com/silanis/esl/sdk/Verification.java | 28 +++ .../esl/sdk/builder/SignerBuilder.java | 38 ++-- ...le.java => SignerVerificationExample.java} | 7 +- .../esl/sdk/examples/UpdateSignerExample.java | 2 - .../silanis/esl/sdk/internal/UrlTemplate.java | 3 + .../internal/converter/SignerConverter.java | 17 -- .../converter/VerificationConverter.java | 66 +++++++ .../esl/sdk/service/PackageService.java | 166 ++++++++++++------ .../AuthenticationMethodConverterTest.java | 20 --- .../converter/SignerConverterTest.java | 8 - .../AuthenticatedSigningExampleTest.java | 21 --- .../SignerVerificationExampleTest.java | 20 +++ 17 files changed, 331 insertions(+), 199 deletions(-) create mode 100644 sdk/src/main/java/com/silanis/esl/api/model/Verification.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/Verification.java rename sdk/src/main/java/com/silanis/esl/sdk/examples/{AuthenticatedSigningExample.java => SignerVerificationExample.java} (87%) create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/internal/converter/VerificationConverter.java delete mode 100644 tester/src/test/java/com/silanis/esl/sdk/examples/AuthenticatedSigningExampleTest.java create mode 100644 tester/src/test/java/com/silanis/esl/sdk/examples/SignerVerificationExampleTest.java diff --git a/sdk/src/main/java/com/silanis/esl/api/model/Signer.java b/sdk/src/main/java/com/silanis/esl/api/model/Signer.java index 388013772..3a8bbfbd7 100644 --- a/sdk/src/main/java/com/silanis/esl/api/model/Signer.java +++ b/sdk/src/main/java/com/silanis/esl/api/model/Signer.java @@ -28,8 +28,6 @@ public class Signer extends User @JsonIgnore public static final String FIELD_DELIVERY = "delivery"; @JsonIgnore - public static final String FIELD_AUTHS = "auths"; - @JsonIgnore public static final String FIELD_EMAIL = "email"; @JsonIgnore public static final String FIELD_EXTERNAL = "external"; @@ -67,7 +65,6 @@ public Signer ( ) {} // Fields protected Auth _auth; - protected List _auths = new ArrayList(); protected Delivery _delivery; protected Group _group = null; protected KnowledgeBasedAuthentication _knowledgeBasedAuthentication = null; @@ -171,35 +168,6 @@ public Delivery getDelivery(){ } - public Signer setAuths(List value) { - SchemaSanitizer.throwOnNull(FIELD_AUTHS, value); - // TODO With proper compare - // if ( this._customFields == value ) return this; - this._auths = value; - setDirty(FIELD_AUTHS); - return this; - } - - // Used internally by aws. Invokes a the corresponding setter if the value is not null - @JsonIgnore - public Signer safeSetAuths( List value ){ - if ( value != null ) { this.setAuths(value); } - return this; - } - - // List adder - public Signer addAuth(Auth value) { - if (value == null) { throw new IllegalArgumentException("Argument cannot be null"); } - this._auths.add(value); - setDirty(FIELD_AUTHS); - return this; - } - - public List getAuths() { - return _auths; - } - - @Override public Signer setEmail( String value ){ super.setEmail(value); diff --git a/sdk/src/main/java/com/silanis/esl/api/model/Verification.java b/sdk/src/main/java/com/silanis/esl/api/model/Verification.java new file mode 100644 index 000000000..390be82b5 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/api/model/Verification.java @@ -0,0 +1,67 @@ +package com.silanis.esl.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.apache.commons.lang3.StringUtils; + +import static com.silanis.esl.api.util.SchemaSanitizer.throwOnNull; +import static com.silanis.esl.api.util.SchemaSanitizer.trim; + +public class Verification extends Entity + implements java.io.Serializable { + + @JsonIgnore + public static final String FIELD_TYPE_KEY = "typeKey"; + @JsonIgnore + public static final String FIELD_PAYLOAD = "payload"; + + // Empty Constructor + public Verification() { + } + + protected String _typeKey = ""; + protected String _payload = ""; + + public Verification setTypeKey(String value) { + throwOnNull(FIELD_TYPE_KEY, value); + value = trim(value); + + if (StringUtils.equals(this._typeKey, value)) return this; + + this._typeKey = value; + setDirty(FIELD_TYPE_KEY); + return this; + } + + @JsonIgnore + public Verification safeSetTypeKey(String value) { + if (value != null) { + this.setTypeKey(value); + } + return this; + } + + public String getTypeKey() { + return _typeKey; + } + + + public Verification setPayload(String value) { + if (StringUtils.equals(this._payload, value)) return this; + + this._payload = value; + setDirty(FIELD_PAYLOAD); + return this; + } + + @JsonIgnore + public Verification safeSetPayload(String value) { + if (value != null) { + this.setPayload(value); + } + return this; + } + + public String getPayload() { + return _payload; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/AuthenticationMethod.java b/sdk/src/main/java/com/silanis/esl/sdk/AuthenticationMethod.java index ae78c83af..cfa815df8 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/AuthenticationMethod.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/AuthenticationMethod.java @@ -11,8 +11,6 @@ public class AuthenticationMethod extends EslEnumeration { public static final AuthenticationMethod CHALLENGE = new AuthenticationMethod("CHALLENGE", "CHALLENGE", 1); public static final AuthenticationMethod SMS = new AuthenticationMethod("SMS", "SMS", 2); public static final AuthenticationMethod KBA = new AuthenticationMethod("KBA", "KBA", 3); - public static final AuthenticationMethod CERTIFICATE = new AuthenticationMethod("CERTIFICATE", "CERTIFICATE", 4); - public static final AuthenticationMethod EXTERNAL = new AuthenticationMethod("EXTERNAL", "EXTERNAL", 5); /** * DO NOT USE! This is an internal implementation concern. It is there to avoid crashes in existing code when new values are added to the enumerations @@ -32,8 +30,6 @@ public static final AuthenticationMethod UNRECOGNIZED(String unknownValue){ sdkValues.put(CHALLENGE.name(), CHALLENGE); sdkValues.put(SMS.name(), SMS); sdkValues.put(KBA.name(), KBA); - sdkValues.put(CERTIFICATE.name(), CERTIFICATE); - sdkValues.put(EXTERNAL.name(), EXTERNAL); } private AuthenticationMethod(String apiValue, String sdkValue, int index) { diff --git a/sdk/src/main/java/com/silanis/esl/sdk/EslClient.java b/sdk/src/main/java/com/silanis/esl/sdk/EslClient.java index 48fdd00de..ed9ee20b3 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/EslClient.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/EslClient.java @@ -1,7 +1,7 @@ package com.silanis.esl.sdk; +import com.silanis.esl.api.model.*; import com.silanis.esl.api.model.Package; -import com.silanis.esl.api.model.SignedDocuments; import com.silanis.esl.sdk.internal.Asserts; import com.silanis.esl.sdk.internal.RestClient; import com.silanis.esl.sdk.internal.SignerRestClient; @@ -265,6 +265,8 @@ public PackageId createPackage(DocumentPackage documentPackage) { uploadDocument(document, id); } + packageService.createSignerVerifications(id.getId(), documentPackage); + return id; } @@ -333,7 +335,11 @@ public PackageId createPackageOneStep(DocumentPackage documentPackage) { packageToCreate.addDocument(apiDocument); } Collection documents = documentPackage.getDocuments(); - return packageService.createPackageOneStep(packageToCreate, documents); + + PackageId id = packageService.createPackageOneStep(packageToCreate, documents); + + packageService.createSignerVerifications(id.getId(), documentPackage); + return id; } diff --git a/sdk/src/main/java/com/silanis/esl/sdk/Signer.java b/sdk/src/main/java/com/silanis/esl/sdk/Signer.java index 8e2a84dee..f087f7d5d 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/Signer.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/Signer.java @@ -27,7 +27,7 @@ public class Signer implements Serializable { private boolean locked; private List attachments; private KnowledgeBasedAuthentication knowledgeBasedAuthentication; - private List authentications = new ArrayList(); + private String verificationType; /** *

The constructor of the Signer class.

@@ -124,18 +124,6 @@ public Authentication getAuthentication() { return authentication; } - public List getAuthentications() { - return authentications; - } - - public void addAuthentication(Authentication authentication) { - this.authentications.add(authentication); - } - - public void setAuthentications(List authentications) { - this.authentications = authentications; - } - /** * Accessor method used to retrieve the authentication method used by the signer * @@ -319,4 +307,11 @@ public void setKnowledgeBasedAuthentication(KnowledgeBasedAuthentication knowled this.knowledgeBasedAuthentication = knowledgeBasedAuthentication; } + public String getVerificationType() { + return verificationType; + } + + public void setVerificationType(String verificationType) { + this.verificationType = verificationType; + } } \ No newline at end of file diff --git a/sdk/src/main/java/com/silanis/esl/sdk/Verification.java b/sdk/src/main/java/com/silanis/esl/sdk/Verification.java new file mode 100644 index 000000000..c8db11e59 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/Verification.java @@ -0,0 +1,28 @@ +package com.silanis.esl.sdk; + +import java.io.Serializable; + +/** + * Created by schoi on 08/05/17. + */ +public class Verification implements Serializable { + + private String type; + private String payload; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/builder/SignerBuilder.java b/sdk/src/main/java/com/silanis/esl/sdk/builder/SignerBuilder.java index 98c023fc8..064fb1c5a 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/builder/SignerBuilder.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/builder/SignerBuilder.java @@ -29,7 +29,7 @@ final public class SignerBuilder { private String placeholderName = null; private List attachments = new ArrayList(); private KnowledgeBasedAuthentication knowledgeBasedAuthentication; - private List authentications = new ArrayList(); + private String verificationType = ""; /** *

The constructor of the SignerBuilderClass.

@@ -143,6 +143,17 @@ public SignerBuilder withLastName(String lastName) { return this; } + /** + * Sets the signer's verification type. + * + * @param verificationType the signer's verification type. + * @return the signer builder itself + */ + public SignerBuilder withSignerVerification(String verificationType) { + this.verificationType = verificationType; + return this; + } + /** * Sets the signing order. If all signers can sign in any order, don't set this setting. *

@@ -164,7 +175,7 @@ private Signer buildGroupSigner(){ result.setMessage(message); result.setId(id); result.setAttachmentRequirements(attachments); - result.setAuthentications(authentications); + result.setVerificationType(verificationType); return result; } @@ -178,7 +189,7 @@ private Signer buildPlaceholderSigner(){ result.setCanChangeSigner(canChangeSigner); result.setMessage(message); result.setAttachmentRequirements(attachments); - result.setAuthentications(authentications); + result.setVerificationType(verificationType); return result; } @@ -195,7 +206,6 @@ private Signer buildRegularSigner(){ result.setTitle(title); result.setCompany(company); result.setDeliverSignedDocumentsByEmail(deliverSignedDocumentsByEmail); - result.setAuthentications(authentications); result.setSigningOrder(signingOrder); result.setCanChangeSigner(canChangeSigner); @@ -203,6 +213,7 @@ private Signer buildRegularSigner(){ result.setId(id); result.setAttachmentRequirements(attachments); result.setKnowledgeBasedAuthentication(knowledgeBasedAuthentication); + result.setVerificationType(verificationType); return result; } @@ -308,25 +319,6 @@ public SignerBuilder canChangeSigner() { return this; } - /** - *

Sets the certificateSigning.

- * @return the signer builder object itself - */ - public SignerBuilder withCertificateSigning() { - Authentication authentication = new Authentication(AuthenticationMethod.CERTIFICATE); - authentications.add(authentication); - return this; - } - - /** - *

Sets the externalSigning.

- * @return the signer builder object itself - */ - public SignerBuilder withExternalSigning() { - Authentication authentication = new Authentication(AuthenticationMethod.EXTERNAL); - authentications.add(authentication); - return this; - } /** * Sets the signer's email message they will receive in the email invitation to start the signing ceremony. diff --git a/sdk/src/main/java/com/silanis/esl/sdk/examples/AuthenticatedSigningExample.java b/sdk/src/main/java/com/silanis/esl/sdk/examples/SignerVerificationExample.java similarity index 87% rename from sdk/src/main/java/com/silanis/esl/sdk/examples/AuthenticatedSigningExample.java rename to sdk/src/main/java/com/silanis/esl/sdk/examples/SignerVerificationExample.java index 20f886fa5..1a4504cc3 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/examples/AuthenticatedSigningExample.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/examples/SignerVerificationExample.java @@ -11,12 +11,12 @@ /** * Created by schoi on 19/04/17. */ -public class AuthenticatedSigningExample extends SDKSample { +public class SignerVerificationExample extends SDKSample { public DocumentPackage sentPackage; public static void main( String... args ) { - new AuthenticatedSigningExample().run(); + new SignerVerificationExample().run(); } public void execute() { @@ -25,8 +25,7 @@ public void execute() { .withSigner(newSignerWithEmail(email1) .withFirstName("John1") .withLastName("Smith1") - .withCertificateSigning() - .withExternalSigning()) + .withSignerVerification("CERTIFICATE")) .withDocument(newDocumentWithName("First Document") .fromStream(documentInputStream1, DocumentType.PDF) .withSignature(signatureFor(email1) diff --git a/sdk/src/main/java/com/silanis/esl/sdk/examples/UpdateSignerExample.java b/sdk/src/main/java/com/silanis/esl/sdk/examples/UpdateSignerExample.java index 7a1f8603b..a0c11ffee 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/examples/UpdateSignerExample.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/examples/UpdateSignerExample.java @@ -52,8 +52,6 @@ public void execute() { Signer signer3 = newSignerWithEmail(email3) .withFirstName(SIGNER3_FIRST_NAME) .withLastName(SIGNER3_LAST_NAME) - .withCertificateSigning() - .withExternalSigning() .challengedWithQuestions(firstQuestion(SIGNER3_FIRST_QUESTION) .answer(SIGNER3_FIRST_ANSWER) .secondQuestion(SIGNER3_SECOND_QUESTION) diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java index 1613efb7c..824b65b5e 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java @@ -109,6 +109,9 @@ public class UrlTemplate { // Reminders Service public static final String REMINDERS_PATH = "/packages/{packageId}/reminders"; + // Signer Verification Service + public static final String SIGNER_VERIFICATION_PATH = "/packages/{packageId}/roles/{roleId}/verification"; + // Signing Service public static final String SIGN_DOCUMENT_PATH = "/packages/{packageId}/documents/signConfirm"; public static final String SIGN_DOCUMENTS_PATH = "/packages/{packageId}/documents/signed_documents"; diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/SignerConverter.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/SignerConverter.java index ef3b8ba90..25bc7c0b6 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/SignerConverter.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/SignerConverter.java @@ -68,16 +68,6 @@ public com.silanis.esl.api.model.Signer toAPISigner() { .setKnowledgeBasedAuthentication(new KnowledgeBasedAuthenticationConverter(sdkSigner.getKnowledgeBasedAuthentication()).toAPIKnowledgeBasedAuthentication()) .setDelivery(new Delivery().setEmail(sdkSigner.isDeliverSignedDocumentsByEmail())); - if(!sdkSigner.getAuthentications().isEmpty()) { - List auths = result.getAuths(); - for(Authentication authentication : sdkSigner.getAuthentications()) { - Auth auth = new Auth(); - auth.setScheme(authentication.getMethod().name()); - auths.add(auth); - } - result.setAuths(auths); - } - } else { result.setGroup(new com.silanis.esl.api.model.Group().setId(sdkSigner.getGroupId().toString())); } @@ -130,13 +120,6 @@ private Signer newRegularSignerFromAPIRole(){ Signer signer = signerBuilder.build(); - List auths = apiSigner.getAuths(); - if(auths != null && !auths.isEmpty()) { - for(Auth auth : auths) { - signer.addAuthentication(new AuthenticationConverter(auth).toSDKAuthentication()); - } - } - if ( apiRole.evalLocked() ) { signer.setLocked(true); } diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/VerificationConverter.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/VerificationConverter.java new file mode 100644 index 000000000..7416f389f --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/VerificationConverter.java @@ -0,0 +1,66 @@ +package com.silanis.esl.sdk.internal.converter; + +import com.silanis.esl.sdk.FieldId; +import com.silanis.esl.sdk.FieldStyle; + +/** + * Created by schoi on 08/05/17. + */ +public class VerificationConverter { + + private com.silanis.esl.sdk.Verification sdkVerification = null; + private com.silanis.esl.api.model.Verification apiVerification = null; + + /** + * Construct with API verification object involved in conversion. + * + * @param apiVerification + */ + public VerificationConverter(com.silanis.esl.api.model.Verification apiVerification) { + this.apiVerification = apiVerification; + } + + /** + * Construct with SDK verification object involved in conversion. + * @param sdkVerification + */ + public VerificationConverter(com.silanis.esl.sdk.Verification sdkVerification) { + this.sdkVerification = sdkVerification; + } + + /** + * Convert from SDK verification to API verification. + * + * @return an API verification object. + */ + public com.silanis.esl.api.model.Verification toAPIVerification() { + if (sdkVerification == null) { + return apiVerification; + } + + com.silanis.esl.api.model.Verification result = new com.silanis.esl.api.model.Verification(); + result.setTypeKey(sdkVerification.getType()); + result.setPayload(sdkVerification.getPayload()); + + return result; + } + + /** + * Convert from API field to SDK field. + * + * @return an SDK Verification object. + */ + public com.silanis.esl.sdk.Verification toSDKVerification() { + + if (apiVerification == null) { + return sdkVerification; + } + + com.silanis.esl.sdk.Verification result = new com.silanis.esl.sdk.Verification(); + + result.setType(apiVerification.getTypeKey()); + result.setPayload(apiVerification.getPayload()); + + return result; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java b/sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java index 46900d364..f57fcf505 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java @@ -3,57 +3,23 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.silanis.esl.api.model.Approval; +import com.silanis.esl.api.model.*; import com.silanis.esl.api.model.Document; import com.silanis.esl.api.model.Field; import com.silanis.esl.api.model.Package; -import com.silanis.esl.api.model.Result; -import com.silanis.esl.api.model.Role; import com.silanis.esl.api.model.Signer; -import com.silanis.esl.api.model.SigningUrl; +import com.silanis.esl.api.model.Verification; import com.silanis.esl.api.util.JacksonUtil; -import com.silanis.esl.sdk.DocumentId; -import com.silanis.esl.sdk.DocumentPackage; -import com.silanis.esl.sdk.DocumentVisibility; -import com.silanis.esl.sdk.EslException; -import com.silanis.esl.sdk.FastTrackRole; -import com.silanis.esl.sdk.FastTrackSigner; -import com.silanis.esl.sdk.GroupId; -import com.silanis.esl.sdk.PackageId; -import com.silanis.esl.sdk.PackageStatus; -import com.silanis.esl.sdk.Page; -import com.silanis.esl.sdk.PageRequest; -import com.silanis.esl.sdk.RoleList; -import com.silanis.esl.sdk.SignerId; -import com.silanis.esl.sdk.SigningStatus; -import com.silanis.esl.sdk.SupportConfiguration; +import com.silanis.esl.sdk.*; import com.silanis.esl.sdk.builder.FastTrackRoleBuilder; -import com.silanis.esl.sdk.internal.DateHelper; -import com.silanis.esl.sdk.internal.EslServerException; -import com.silanis.esl.sdk.internal.RedirectResolver; -import com.silanis.esl.sdk.internal.RequestException; -import com.silanis.esl.sdk.internal.RestClient; -import com.silanis.esl.sdk.internal.Serialization; -import com.silanis.esl.sdk.internal.UrlTemplate; -import com.silanis.esl.sdk.internal.converter.DocumentConverter; -import com.silanis.esl.sdk.internal.converter.DocumentPackageConverter; -import com.silanis.esl.sdk.internal.converter.DocumentVisibilityConverter; -import com.silanis.esl.sdk.internal.converter.NotaryJournalEntryConverter; -import com.silanis.esl.sdk.internal.converter.PackageStatusConverter; -import com.silanis.esl.sdk.internal.converter.SignerConverter; -import com.silanis.esl.sdk.internal.converter.SupportConfigurationConverter; +import com.silanis.esl.sdk.internal.*; +import com.silanis.esl.sdk.internal.converter.*; import com.silanis.esl.sdk.io.DownloadedFile; import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.UUID; +import java.util.*; + +import static org.apache.commons.lang3.StringUtils.isNotBlank; /** * The PackageService class provides methods to help create packages and download documents after the @@ -221,6 +187,72 @@ public void changePackageStatusToDraft(PackageId packageId) throws EslException } } + /** + * Creates a signer verifications. + * + * @param documentPackage + * @throws com.silanis.esl.sdk.EslException + */ + public void createSignerVerifications(String packageId, DocumentPackage documentPackage) { + Package createdPackage = getApiPackage(packageId); + for(com.silanis.esl.sdk.Signer signer : documentPackage.getSigners()) { + if(isNotBlank(signer.getVerificationType())) { + Role role = getRoleByEmail(createdPackage, signer.getEmail()); + Verification verification = new Verification(); + verification.setTypeKey(signer.getVerificationType()); + createSignerVerification(createdPackage.getId(), role.getId(), verification); + } + } + } + + private Verification createSignerVerification(String packageId, String roleId, Verification verification) throws EslException { + String path = template.urlFor(UrlTemplate.SIGNER_VERIFICATION_PATH) + .replace("{packageId}", packageId) + .replace("{roleId}", roleId) + .build(); + + String verificationJson = Serialization.toJson(verification); + + try { + String response = client.post(path, verificationJson); + return Serialization.fromJson(response, Verification.class); + } catch (RequestException e) { + throw new EslServerException("Could not create a signer verification", e); + } catch (Exception e) { + throw new EslException("Could not create a signer verification", e); + } + } + + /** + * Gets the a signer verification. + * + * @param packageId + * @param roleId + * @return Verification + * @throws EslException + */ + private Verification getSignerVerification(String packageId, String roleId) throws EslException { + String path = template.urlFor(UrlTemplate.SIGNER_VERIFICATION_PATH) + .replace("{packageId}", packageId) + .replace("{roleId}", roleId) + .build(); + + String stringResponse; + try { + stringResponse = client.get(path); + } catch (RequestException e) { + throw new EslServerException("Could not get signer verification.", e); + } catch (Exception e) { + throw new EslException("Could not get signer verification.", e); + } + + if(StringUtils.isBlank(stringResponse)) { + return null; + } + + return Serialization.fromJson(stringResponse, Verification.class); + } + /** * Configure a document visibility. * @@ -228,7 +260,7 @@ public void changePackageStatusToDraft(PackageId packageId) throws EslException * @param visibility the document visibility * @throws EslException */ - public void configureDocumentVisibility(PackageId packageId, DocumentVisibility visibility) throws EslException { + public void configureDocumentVisibility(PackageId packageId, com.silanis.esl.sdk.DocumentVisibility visibility) throws EslException { String path = template.urlFor( UrlTemplate.DOCUMENT_VISIBILITY_PATH ) .replace("{packageId}", packageId.getId()) .build(); @@ -251,7 +283,7 @@ public void configureDocumentVisibility(PackageId packageId, DocumentVisibility * @param packageId * @throws EslException */ - public DocumentVisibility getDocumentVisibility(PackageId packageId) throws EslException { + public com.silanis.esl.sdk.DocumentVisibility getDocumentVisibility(PackageId packageId) throws EslException { String path = template.urlFor( UrlTemplate.DOCUMENT_VISIBILITY_PATH ) .replace("{packageId}", packageId.getId()) .build(); @@ -269,20 +301,37 @@ public DocumentVisibility getDocumentVisibility(PackageId packageId) throws EslE public DocumentPackage getPackage(PackageId packageId) { Package aPackage = getApiPackage(packageId.getId()); + DocumentPackage documentPackage = packageConverter(aPackage).toSDKPackage(); + if(!StringUtils.equalsIgnoreCase(BasePackageType.TEMPLATE.name(), aPackage.getType())) { + setSignerVerificationToSDKPackage(aPackage, documentPackage); + } - return packageConverter(aPackage).toSDKPackage(); + return documentPackage; + } + + private void setSignerVerificationToSDKPackage(Package aPackage, DocumentPackage documentPackage) { + for(Role role : aPackage.getRoles()) { + if(role.getSigners().isEmpty()) + continue; + + Verification verification = getSignerVerification(aPackage.getId(), role.getId()); + if(verification != null && isNotBlank(verification.getTypeKey())) { + String signerEmail = role.getSigners().get(0).getEmail(); + documentPackage.getSigner(signerEmail).setVerificationType(verification.getTypeKey()); + } + } } public List getDocuments(PackageId packageId, String signerId) { DocumentPackage documentPackage = getPackage(packageId); - final DocumentVisibility visibility = getDocumentVisibility(packageId); + final com.silanis.esl.sdk.DocumentVisibility visibility = getDocumentVisibility(packageId); return visibility.getDocuments(documentPackage, signerId); } public List getSigners(PackageId packageId, String documentId) { DocumentPackage documentPackage = getPackage(packageId); - final DocumentVisibility visibility = getDocumentVisibility(packageId); + final com.silanis.esl.sdk.DocumentVisibility visibility = getDocumentVisibility(packageId); return visibility.getSigners(documentPackage, documentId); } @@ -753,7 +802,7 @@ public SigningStatus getSigningStatus(PackageId packageId, SignerId signerId, Do * @param request Identifying which page of results to return * @return List of DocumentPackages that populate the specified page */ - public Page getPackages(String status, PageRequest request) { + public com.silanis.esl.sdk.Page getPackages(String status, PageRequest request) { String path = template.urlFor(UrlTemplate.PACKAGE_LIST_PATH) .replace("{status}", status) .replace("{from}", Integer.toString(request.getFrom())) @@ -782,7 +831,7 @@ public Page getPackages(String status, PageRequest request) { * @param to Date range ending of this date included * @return List of DocumentPackages that populate the specified page */ - public Page getUpdatedPackagesWithinDateRange(PackageStatus status, PageRequest request, Date from, Date to) { + public com.silanis.esl.sdk.Page getUpdatedPackagesWithinDateRange(PackageStatus status, PageRequest request, Date from, Date to) { String fromDate = DateHelper.dateToIsoUtcFormat(from); String toDate = DateHelper.dateToIsoUtcFormat(to); @@ -807,7 +856,7 @@ public Page getUpdatedPackagesWithinDateRange(PackageStatus sta } } - private Page convertToPage(Result results, PageRequest request) { + private com.silanis.esl.sdk.Page convertToPage(Result results, PageRequest request) { List converted = new ArrayList(); for (Package aPackage : results.getResults()) { @@ -815,7 +864,7 @@ private Page convertToPage(Result results, PageRequest converted.add(dp); } - return new Page(converted, results.getCount(), request); + return new com.silanis.esl.sdk.Page(converted, results.getCount(), request); } /** @@ -985,7 +1034,7 @@ private void notifySigner(PackageId packageId, String roleId) { } } - public Page getTemplates(PageRequest request) { + public com.silanis.esl.sdk.Page getTemplates(PageRequest request) { String path = template.urlFor(UrlTemplate.TEMPLATE_LIST_PATH) .replace("{from}", Integer.toString(request.getFrom())) .replace("{to}", Integer.toString(request.to())) @@ -1218,6 +1267,17 @@ private Role getRole(Package apiPackage, String sigenrId) { return new Role(); } + private Role getRoleByEmail(Package apiPackage, String signerEmail) { + for(Role role : apiPackage.getRoles()) { + for(Signer signer : role.getSigners()) { + if(signer.getEmail().equals(signerEmail)) { + return role; + } + } + } + return new Role(); + } + private String getSigningUrl(PackageId packageId, Role role) { String path = template.urlFor(UrlTemplate.SIGNER_URL_PATH) @@ -1399,7 +1459,7 @@ public String getThankYouDialogContent(PackageId packageId) { * @param packageId The id of the package to get package support configuration. * @return package support configuration */ - public SupportConfiguration getConfig(PackageId packageId) { + public com.silanis.esl.sdk.SupportConfiguration getConfig(PackageId packageId) { String path = template.urlFor(UrlTemplate.PACKAGE_INFORMATION_CONFIG_PATH) .replace("{packageId}", packageId.getId()) .build(); diff --git a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/AuthenticationMethodConverterTest.java b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/AuthenticationMethodConverterTest.java index 4319ae461..5e33f4a9e 100644 --- a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/AuthenticationMethodConverterTest.java +++ b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/AuthenticationMethodConverterTest.java @@ -88,16 +88,6 @@ public void convertAPIToSDK() { sdkAuthenticationMethod = converter.toSDKAuthMethod(); assertThat("AuthenticationMethod was not set correctly", sdkAuthenticationMethod, is(AuthenticationMethod.KBA)); - apiAuthenticationMethod = "CERTIFICATE"; - converter = new AuthenticationMethodConverter(apiAuthenticationMethod); - sdkAuthenticationMethod = converter.toSDKAuthMethod(); - assertThat("AuthenticationMethod was not set correctly", sdkAuthenticationMethod, is(AuthenticationMethod.CERTIFICATE)); - - apiAuthenticationMethod = "EXTERNAL"; - converter = new AuthenticationMethodConverter(apiAuthenticationMethod); - sdkAuthenticationMethod = converter.toSDKAuthMethod(); - assertThat("AuthenticationMethod was not set correctly", sdkAuthenticationMethod, is(AuthenticationMethod.EXTERNAL)); - apiAuthenticationMethod = "UNKNOWN"; converter = new AuthenticationMethodConverter(apiAuthenticationMethod); sdkAuthenticationMethod = converter.toSDKAuthMethod(); @@ -126,16 +116,6 @@ public void convertSDKToAPI() { apiAuthenticationMethod = converter.toAPIAuthMethod(); assertThat("AuthenticationMethod was not set correctly", apiAuthenticationMethod, is("KBA")); - sdkAuthenticationMethod = com.silanis.esl.sdk.AuthenticationMethod.CERTIFICATE; - converter = new AuthenticationMethodConverter(sdkAuthenticationMethod); - apiAuthenticationMethod = converter.toAPIAuthMethod(); - assertThat("AuthenticationMethod was not set correctly", apiAuthenticationMethod, is("CERTIFICATE")); - - sdkAuthenticationMethod = com.silanis.esl.sdk.AuthenticationMethod.EXTERNAL; - converter = new AuthenticationMethodConverter(sdkAuthenticationMethod); - apiAuthenticationMethod = converter.toAPIAuthMethod(); - assertThat("AuthenticationMethod was not set correctly", apiAuthenticationMethod, is("EXTERNAL")); - sdkAuthenticationMethod = com.silanis.esl.sdk.AuthenticationMethod.UNRECOGNIZED("UNKNOWN"); converter = new AuthenticationMethodConverter(sdkAuthenticationMethod); apiAuthenticationMethod = converter.toAPIAuthMethod(); diff --git a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/SignerConverterTest.java b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/SignerConverterTest.java index c4235585e..59f484a79 100644 --- a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/SignerConverterTest.java +++ b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/SignerConverterTest.java @@ -99,8 +99,6 @@ public void convertAPIToSDK() { assertThat("Last name was not correctly set", apiSigner1.getLastName(), is(equalTo(sdkSigner1.getLastName()))); assertThat("Company was not correctly set", apiSigner1.getCompany(), is(equalTo(sdkSigner1.getCompany()))); assertThat("Title was not correctly set", apiSigner1.getTitle(), is(equalTo(sdkSigner1.getTitle()))); - assertThat("Authenticated signing flag was not correctly set", apiSigner1.getAuths(), hasSize(1)); - assertThat("Authenticated signing flag was not correctly set", apiSigner1.getAuths().get(0).getScheme(), is("CERTIFICATE")); assertThat("Signer ID was not correctly set", apiRole.getId(), is(equalTo(sdkSigner1.getId()))); assertThat("Signing order was not correctly set", apiRole.getIndex(), is(equalTo(sdkSigner1.getSigningOrder()))); assertThat("Can change signer flag was not correctly set", apiRole.getReassign(), is(equalTo(sdkSigner1.canChangeSigner()))); @@ -229,12 +227,6 @@ private com.silanis.esl.api.model.Role createTypicalAPIRole() { apiSigner.setCompany("ABC Inc."); apiSigner.setTitle("Doctor"); - List auths = new ArrayList(); - Auth auth = new Auth(); - auth.setScheme("CERTIFICATE"); - auths.add(auth); - apiSigner.setAuths(auths); - Delivery delivery = new Delivery(); delivery.setDownload(true); delivery.setEmail(true); diff --git a/tester/src/test/java/com/silanis/esl/sdk/examples/AuthenticatedSigningExampleTest.java b/tester/src/test/java/com/silanis/esl/sdk/examples/AuthenticatedSigningExampleTest.java deleted file mode 100644 index 34c622a1a..000000000 --- a/tester/src/test/java/com/silanis/esl/sdk/examples/AuthenticatedSigningExampleTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.silanis.esl.sdk.examples; - -import org.junit.Test; - -/** - * Created by schoi on 19/04/17. - */ -public class AuthenticatedSigningExampleTest { - - @Test - public void verifyResult() { - AuthenticatedSigningExample example = new AuthenticatedSigningExample(); - example.run(); - -/* - assertThat("Authenticated Signing is not set correctly.", example.sentPackage.getSigner(example.email1).getAuthentications(), hasSize(2)); - assertThat("Authenticated Signing is not set correctly.", example.sentPackage.getSigner(example.email1).getAuthentications().get(0).getMethod(), is(AuthenticationMethod.CERTIFICATE)); - assertThat("Authenticated Signing is not set correctly.", example.sentPackage.getSigner(example.email1).getAuthentications().get(1).getMethod(), is(AuthenticationMethod.EXTERNAL)); -*/ - } -} diff --git a/tester/src/test/java/com/silanis/esl/sdk/examples/SignerVerificationExampleTest.java b/tester/src/test/java/com/silanis/esl/sdk/examples/SignerVerificationExampleTest.java new file mode 100644 index 000000000..5099be5ac --- /dev/null +++ b/tester/src/test/java/com/silanis/esl/sdk/examples/SignerVerificationExampleTest.java @@ -0,0 +1,20 @@ +package com.silanis.esl.sdk.examples; + +import org.junit.Test; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +/** + * Created by schoi on 19/04/17. + */ +public class SignerVerificationExampleTest { + + @Test + public void verifyResult() { + SignerVerificationExample example = new SignerVerificationExample(); + example.run(); + + assertThat("Signer Verification is not set correctly.", example.sentPackage.getSigner(example.email1).getVerificationType(), is("CERTIFICATE")); + } +}