Skip to content

Commit

Permalink
PB-1004. Support for signer verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed May 8, 2017
1 parent 5114861 commit 75bb681
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 199 deletions.
32 changes: 0 additions & 32 deletions sdk/src/main/java/com/silanis/esl/api/model/Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -67,7 +65,6 @@ public Signer ( ) {}

// Fields
protected Auth _auth;
protected List<Auth> _auths = new ArrayList<Auth>();
protected Delivery _delivery;
protected Group _group = null;
protected KnowledgeBasedAuthentication _knowledgeBasedAuthentication = null;
Expand Down Expand Up @@ -171,35 +168,6 @@ public Delivery getDelivery(){
}


public Signer setAuths(List<Auth> 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<Auth> 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<Auth> getAuths() {
return _auths;
}


@Override
public Signer setEmail( String value ){
super.setEmail(value);
Expand Down
67 changes: 67 additions & 0 deletions sdk/src/main/java/com/silanis/esl/api/model/Verification.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions sdk/src/main/java/com/silanis/esl/sdk/EslClient.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -265,6 +265,8 @@ public PackageId createPackage(DocumentPackage documentPackage) {
uploadDocument(document, id);
}

packageService.createSignerVerifications(id.getId(), documentPackage);

return id;
}

Expand Down Expand Up @@ -333,7 +335,11 @@ public PackageId createPackageOneStep(DocumentPackage documentPackage) {
packageToCreate.addDocument(apiDocument);
}
Collection<Document> documents = documentPackage.getDocuments();
return packageService.createPackageOneStep(packageToCreate, documents);

PackageId id = packageService.createPackageOneStep(packageToCreate, documents);

packageService.createSignerVerifications(id.getId(), documentPackage);
return id;

}

Expand Down
21 changes: 8 additions & 13 deletions sdk/src/main/java/com/silanis/esl/sdk/Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Signer implements Serializable {
private boolean locked;
private List<AttachmentRequirement> attachments;
private KnowledgeBasedAuthentication knowledgeBasedAuthentication;
private List<Authentication> authentications = new ArrayList<Authentication>();
private String verificationType;

/**
* <p>The constructor of the Signer class.</p>
Expand Down Expand Up @@ -124,18 +124,6 @@ public Authentication getAuthentication() {
return authentication;
}

public List<Authentication> getAuthentications() {
return authentications;
}

public void addAuthentication(Authentication authentication) {
this.authentications.add(authentication);
}

public void setAuthentications(List<Authentication> authentications) {
this.authentications = authentications;
}

/**
* Accessor method used to retrieve the authentication method used by the signer
*
Expand Down Expand Up @@ -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;
}
}
38 changes: 15 additions & 23 deletions sdk/src/main/java/com/silanis/esl/sdk/builder/SignerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final public class SignerBuilder {
private String placeholderName = null;
private List<AttachmentRequirement> attachments = new ArrayList<AttachmentRequirement>();
private KnowledgeBasedAuthentication knowledgeBasedAuthentication;
private List<Authentication> authentications = new ArrayList<Authentication>();
private String verificationType = "";

/**
* <p>The constructor of the SignerBuilderClass.</p>
Expand Down Expand Up @@ -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.
* <p>
Expand All @@ -164,7 +175,7 @@ private Signer buildGroupSigner(){
result.setMessage(message);
result.setId(id);
result.setAttachmentRequirements(attachments);
result.setAuthentications(authentications);
result.setVerificationType(verificationType);

return result;
}
Expand All @@ -178,7 +189,7 @@ private Signer buildPlaceholderSigner(){
result.setCanChangeSigner(canChangeSigner);
result.setMessage(message);
result.setAttachmentRequirements(attachments);
result.setAuthentications(authentications);
result.setVerificationType(verificationType);
return result;
}

Expand All @@ -195,14 +206,14 @@ private Signer buildRegularSigner(){
result.setTitle(title);
result.setCompany(company);
result.setDeliverSignedDocumentsByEmail(deliverSignedDocumentsByEmail);
result.setAuthentications(authentications);

result.setSigningOrder(signingOrder);
result.setCanChangeSigner(canChangeSigner);
result.setMessage(message);
result.setId(id);
result.setAttachmentRequirements(attachments);
result.setKnowledgeBasedAuthentication(knowledgeBasedAuthentication);
result.setVerificationType(verificationType);

return result;
}
Expand Down Expand Up @@ -308,25 +319,6 @@ public SignerBuilder canChangeSigner() {
return this;
}

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

/**
* <p>Sets the externalSigning.</p>
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Auth> 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()));
}
Expand Down Expand Up @@ -130,13 +120,6 @@ private Signer newRegularSignerFromAPIRole(){

Signer signer = signerBuilder.build();

List<Auth> auths = apiSigner.getAuths();
if(auths != null && !auths.isEmpty()) {
for(Auth auth : auths) {
signer.addAuthentication(new AuthenticationConverter(auth).toSDKAuthentication());
}
}

if ( apiRole.evalLocked() ) {
signer.setLocked(true);
}
Expand Down
Loading

0 comments on commit 75bb681

Please sign in to comment.