Skip to content
Snippets Groups Projects

Iss #18 - Add check for email domain while in test mode

Merged Martin Lowe requested to merge malowe/eclipsefdn-hellosign-api:malowe/main/18 into main
2 files
+ 53
10
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -21,6 +21,7 @@ import java.util.stream.Collectors;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.NotAcceptableException;
import javax.ws.rs.ServerErrorException;
import javax.ws.rs.core.Response;
@@ -54,8 +55,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Implementation of the binding to the Hellosign service, using the SDK provided by Dropbox to action requests for information and new
* signature requests.
* Implementation of the binding to the Hellosign service, using the SDK provided by Dropbox to action requests for
* information and new signature requests.
*
* @author Martin Lowe
*
@@ -98,7 +99,8 @@ public class DefaultHellosignBindingService implements HellosignBindingService {
});
// check the error state and throw if the document couldn't be retrieved
if (pdfContents.isEmpty()) {
throw new ServerErrorException("Error while retrieving PDF contents for current request, the document may not be available",
throw new ServerErrorException(
"Error while retrieving PDF contents for current request, the document may not be available",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
return pdfContents.get();
@@ -107,6 +109,12 @@ public class DefaultHellosignBindingService implements HellosignBindingService {
@Override
public SignatureRequestResponse createSignatureRequest(DocumentSignatureTemplate template, SignatureRequest request,
List<DocumentSigner> signers) {
// add safety check to prevent external users from getting notifications for tests
if (config.testMode()
&& signers.stream().anyMatch(s -> !s.getMail().toLowerCase().endsWith("@eclipse-foundation.org"))) {
throw new NotAcceptableException("Found emails outside of the eclipse-foundation.org domain in test mode");
}
try {
// build and submit the request for signature, using the passed data to build the full Hellosign request
SignatureRequestGetResponse r = signatureRequest
@@ -126,8 +134,10 @@ public class DefaultHellosignBindingService implements HellosignBindingService {
// log the success and return the response when complete
if (LOGGER.isDebugEnabled()) {
LOGGER
.debug("Created signature request for template {} with signers '{}' (testing? {})", template.templateName(),
signers.stream().map(DocumentSigner::getMail).collect(Collectors.toList()), config.testMode());
.debug("Created signature request for template {} with signers '{}' (testing? {})",
template.templateName(),
signers.stream().map(DocumentSigner::getMail).collect(Collectors.toList()),
config.testMode());
}
return r.getSignatureRequest();
} catch (ApiException e) {
@@ -160,17 +170,20 @@ public class DefaultHellosignBindingService implements HellosignBindingService {
// persist the new record
List<DocumentSignatureEvent> updatedRecords = dao
.add(new RDBMSQuery<>(new FlatRequestWrapper(URI.create("https://api.eclipse.org/foundation/hellosign")),
.add(new RDBMSQuery<>(
new FlatRequestWrapper(URI.create("https://api.eclipse.org/foundation/hellosign")),
filters.get(DocumentSignatureEvent.class)), Arrays.asList(dse));
if (updatedRecords.isEmpty()) {
LOGGER
.error("Error while persisting event callback of type {} for request {}", payload.getEvent().getEventType().getValue(),
.error("Error while persisting event callback of type {} for request {}",
payload.getEvent().getEventType().getValue(),
payload.getSignatureRequest().getSignatureRequestId());
}
}
/**
* Serializes the signature request response from Hellosign, converting it into JSON data to be stored along with the request record.
* Serializes the signature request response from Hellosign, converting it into JSON data to be stored along with
* the request record.
*
* @param r the response from Hellosign for creating the signature request
* @return the JSON data for the response, or null if it can't be converted
@@ -179,7 +192,9 @@ public class DefaultHellosignBindingService implements HellosignBindingService {
try {
return om.writeValueAsString(r);
} catch (JsonProcessingException e) {
LOGGER.error("Error processing event callback for request {}", r.getSignatureRequest().getSignatureRequestId());
LOGGER
.error("Error processing event callback for request {}",
r.getSignatureRequest().getSignatureRequestId());
return null;
}
}
Loading