summaryrefslogtreecommitdiff
path: root/pdf-over-signer/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-over-signer/src/main/java')
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java3
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/UserCancelledException.java44
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java50
3 files changed, 82 insertions, 15 deletions
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java
index d91e8466..3ef9cfd5 100644
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java
+++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java
@@ -27,6 +27,7 @@ public interface BkuSlConnector {
* @param request
* @return SL Response
* @throws SignatureException
+ * @throws UserCancelledException
*/
- public String handleSLRequest(PdfAs4SLRequest request) throws SignatureException;
+ public String handleSLRequest(PdfAs4SLRequest request) throws SignatureException, UserCancelledException;
}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/UserCancelledException.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/UserCancelledException.java
new file mode 100644
index 00000000..ff1b4db8
--- /dev/null
+++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/UserCancelledException.java
@@ -0,0 +1,44 @@
+package at.asit.pdfover.signer;
+
+/**
+ * The user cancelled the operation.
+ */
+public class UserCancelledException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7341854663858331004L;
+
+ /**
+ * Empty constructor
+ */
+ public UserCancelledException() {
+ super();
+ }
+
+ /**
+ * Constructor with causing exception
+ * @param cause the cause
+ */
+ public UserCancelledException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructor with message
+ * @param msg the message
+ */
+ public UserCancelledException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructor with message and causing exception
+ * @param message the message
+ * @param cause the cause
+ */
+ public UserCancelledException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java
index 533a0487..7dd2fedc 100644
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java
+++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import at.asit.pdfover.signer.BkuSlConnector;
import at.asit.pdfover.signer.SignatureException;
+import at.asit.pdfover.signer.UserCancelledException;
import at.asit.pdfover.signer.pdfas.exceptions.PdfAs4SLRequestException;
import at.gv.egiz.pdfas.common.exceptions.PDFIOException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
@@ -68,22 +69,29 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector {
throws PdfAsException {
JAXBElement<?> element = null;
try {
- String slRequestString = SLMarschaller.marshalToString(this.of.createInfoboxReadRequest(request));
-
- PdfAs4SLRequest slRequest = new PdfAs4SLRequest(slRequestString, null);
- String slResponse = this.connector.handleSLRequest(slRequest);
-
- element = (JAXBElement<?>) SLMarschaller.unmarshalFromString(slResponse);
+ try {
+ String slRequestString = SLMarschaller.marshalToString(this.of.createInfoboxReadRequest(request));
+
+ String slResponse = this.connector.handleSLRequest(new PdfAs4SLRequest(slRequestString, null));
+
+ element = (JAXBElement<?>) SLMarschaller.unmarshalFromString(slResponse);
+ } catch (SignatureException e) {
+ Throwable c = e;
+ while (c.getCause() != null)
+ c = c.getCause();
+ if (c instanceof IllegalStateException) // TODO: this is a legacy hack, remove it?
+ throw new UserCancelledException(e);
+ else
+ throw e;
+ }
} catch (JAXBException e) {
throw new PDFIOException("error.pdf.io.03", e);
} catch (PdfAs4SLRequestException e) {
throw new PDFIOException("error.pdf.io.03", e);
} catch (SignatureException e) {
- Throwable e2 = e;
- while (e2.getCause() != null)
- e2 = e2.getCause();
- /*if (e2 instanceof IllegalStateException) // user cancelled (TODO: this is a pretty big hack honestly)
- return null;*/
+ throw new PDFIOException("error.pdf.io.03", e);
+ } catch (UserCancelledException e) {
+ // TODO: find out how to communicate this out to PDF-AS?
throw new PDFIOException("error.pdf.io.03", e);
}
@@ -108,23 +116,37 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector {
SignParameter parameter) throws PdfAsException {
JAXBElement<?> element = null;
try {
+
String slRequestString = SLMarschaller.marshalToString(this.of.createCreateCMSSignatureRequest(pack.getRequestType()));
- //log.trace(slRequestString);
byte[] signatureData = pack.getSignatureData();
if (IConfigurationConstants.SL_REQUEST_TYPE_UPLOAD.equals(parameter.getConfiguration().getValue(IConfigurationConstants.SL_REQUEST_TYPE)))
signatureData = PDFUtils.blackOutSignature(signatureData, pack.getByteRange());
PdfAs4SLRequest slRequest = new PdfAs4SLRequest(slRequestString, signatureData);
- String slResponse = this.connector.handleSLRequest(slRequest);
- element = (JAXBElement<?>) SLMarschaller.unmarshalFromString(slResponse);
+ try {
+ String slResponse = this.connector.handleSLRequest(slRequest);
+
+ element = (JAXBElement<?>) SLMarschaller.unmarshalFromString(slResponse);
+ } catch (SignatureException e) {
+ Throwable c = e;
+ while (c.getCause() != null)
+ c = c.getCause();
+ if (c instanceof IllegalStateException) // TODO: this is a legacy hack, remove it?
+ throw new UserCancelledException(e);
+ else
+ throw e;
+ }
} catch (JAXBException e) {
throw new PDFIOException("error.pdf.io.03", e);
} catch (PdfAs4SLRequestException e) {
throw new PDFIOException("error.pdf.io.03", e);
} catch (SignatureException e) {
throw new PDFIOException("error.pdf.io.03", e);
+ } catch (UserCancelledException e) {
+ // TODO: find out how to communicate this out to PDF-AS?
+ throw new PDFIOException("error.pdf.io.03", e);
}
if (element == null) {