Skip to content

Commit

Permalink
PB-1004. Support for authenticate signing
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed Apr 25, 2017
1 parent 0fb2ec5 commit 4c9a29f
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 12 deletions.
45 changes: 39 additions & 6 deletions sdk/src/main/java/com/silanis/esl/api/model/Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.silanis.esl.api.util.JsonDateDeserializer;
import com.silanis.esl.api.util.SchemaSanitizer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@JsonIgnoreProperties(ignoreUnknown=true)
Expand All @@ -26,6 +28,8 @@ 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 @@ -63,6 +67,7 @@ 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 All @@ -81,9 +86,9 @@ public Signer safeSetAddress( Address value ){
if ( value != null ) { this.setAddress( value ); }
return this;
}



public Signer setAuth( Auth value ){
SchemaSanitizer.throwOnNull(FIELD_AUTH,value);
// TODO With proper compare
Expand All @@ -101,7 +106,7 @@ public Signer safeSetAuth( Auth value ){
public Auth getAuth(){
return _auth;
}



@Override
Expand Down Expand Up @@ -164,8 +169,36 @@ public Signer safeSetDelivery( Delivery value ){
public Delivery getDelivery(){
return _delivery;
}




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 ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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 @@ -30,6 +32,8 @@ 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
14 changes: 14 additions & 0 deletions sdk/src/main/java/com/silanis/esl/sdk/Signer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.silanis.esl.sdk;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -26,6 +27,7 @@ public class Signer implements Serializable {
private boolean locked;
private List<AttachmentRequirement> attachments;
private KnowledgeBasedAuthentication knowledgeBasedAuthentication;
private List<Authentication> authentications = new ArrayList<Authentication>();

/**
* <p>The constructor of the Signer class.</p>
Expand Down Expand Up @@ -122,6 +124,18 @@ 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
24 changes: 24 additions & 0 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,6 +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>();

/**
* <p>The constructor of the SignerBuilderClass.</p>
Expand Down Expand Up @@ -163,6 +164,7 @@ private Signer buildGroupSigner(){
result.setMessage(message);
result.setId(id);
result.setAttachmentRequirements(attachments);
result.setAuthentications(authentications);

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

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

result.setSigningOrder(signingOrder);
result.setCanChangeSigner(canChangeSigner);
Expand Down Expand Up @@ -304,6 +308,26 @@ 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
@@ -0,0 +1,41 @@
package com.silanis.esl.sdk.examples;

import com.silanis.esl.sdk.DocumentPackage;
import com.silanis.esl.sdk.DocumentType;

import static com.silanis.esl.sdk.builder.DocumentBuilder.newDocumentWithName;
import static com.silanis.esl.sdk.builder.PackageBuilder.newPackageNamed;
import static com.silanis.esl.sdk.builder.SignatureBuilder.signatureFor;
import static com.silanis.esl.sdk.builder.SignerBuilder.newSignerWithEmail;

/**
* Created by schoi on 19/04/17.
*/
public class AuthenticatedSigningExample extends SDKSample {

public DocumentPackage sentPackage;

public static void main( String... args ) {
new AuthenticatedSigningExample().run();
}

public void execute() {
DocumentPackage superDuperPackage = newPackageNamed(getPackageName())
.describedAs("This is a package created using the eSignLive SDK")
.withSigner(newSignerWithEmail(email1)
.withFirstName("John1")
.withLastName("Smith1")
.withCertificateSigning()
.withExternalSigning())
.withDocument(newDocumentWithName("First Document")
.fromStream(documentInputStream1, DocumentType.PDF)
.withSignature(signatureFor(email1)
.onPage(0)
.atPosition(100, 100)))
.build();

packageId = eslClient.createPackage( superDuperPackage );
eslClient.sendPackage(packageId);
sentPackage = eslClient.getPackage(packageId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ 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)
.answer(SIGNER3_SECOND_ANSWER))
.answer(SIGNER3_FIRST_ANSWER)
.secondQuestion(SIGNER3_SECOND_QUESTION)
.answer(SIGNER3_SECOND_ANSWER))
.withCustomId(SIGNER1_CUSTOM_ID).build();

Signer signer4 = newSignerWithEmail(email2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.silanis.esl.sdk.internal.converter;

import com.silanis.esl.api.model.Auth;
import com.silanis.esl.api.model.BaseMessage;
import com.silanis.esl.api.model.Delivery;
import com.silanis.esl.api.model.Role;
import com.silanis.esl.sdk.Authentication;
import com.silanis.esl.sdk.GroupId;
import com.silanis.esl.sdk.Placeholder;
import com.silanis.esl.sdk.Signer;
import com.silanis.esl.sdk.builder.SignerBuilder;
import com.silanis.esl.sdk.internal.Asserts;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
* User: jessica
* Date: 03/12/13
Expand Down Expand Up @@ -56,15 +60,26 @@ public com.silanis.esl.api.model.Signer toAPISigner() {
com.silanis.esl.api.model.Signer result = new com.silanis.esl.api.model.Signer();

if ( !sdkSigner.isGroupSigner() ) {
result.setEmail( sdkSigner.getEmail() )
result.setEmail(sdkSigner.getEmail())
.setFirstName(sdkSigner.getFirstName())
.setLastName(sdkSigner.getLastName())
.setTitle(sdkSigner.getTitle())
.setCompany(sdkSigner.getCompany())
.setKnowledgeBasedAuthentication(new KnowledgeBasedAuthenticationConverter(sdkSigner.getKnowledgeBasedAuthentication()).toAPIKnowledgeBasedAuthentication())
.setDelivery( new Delivery().setEmail( sdkSigner.isDeliverSignedDocumentsByEmail() ) );
.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() ) );
result.setGroup(new com.silanis.esl.api.model.Group().setId(sdkSigner.getGroupId().toString()));
}

if ( sdkSigner.getId() != null ) {
Expand Down Expand Up @@ -115,6 +130,13 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ 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();
Expand Down Expand Up @@ -116,6 +126,16 @@ 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
Expand Down Expand Up @@ -98,6 +99,8 @@ 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())));
Expand Down Expand Up @@ -226,6 +229,12 @@ private com.silanis.esl.api.model.Role createTypicalAPIRole() {
apiSigner.setCompany("ABC Inc.");
apiSigner.setTitle("Doctor");

List<Auth> auths = new ArrayList<Auth>();
Auth auth = new Auth();
auth.setScheme("CERTIFICATE");
auths.add(auth);
apiSigner.setAuths(auths);

Delivery delivery = new Delivery();
delivery.setDownload(true);
delivery.setEmail(true);
Expand Down
Loading

0 comments on commit 4c9a29f

Please sign in to comment.