diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-09-30 15:03:04 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-09-30 15:03:04 +0200 |
commit | 58db0733866b26411c07b7b17e741663d2f1c438 (patch) | |
tree | 2f15bb9ca6aaa6b5fec04b80b07d2f711221c7f3 /pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas | |
parent | 9a513d43b310f2e6283fa195a8aa11493a7dcb2c (diff) | |
download | pdf-over-58db0733866b26411c07b7b17e741663d2f1c438.tar.gz pdf-over-58db0733866b26411c07b7b17e741663d2f1c438.tar.bz2 pdf-over-58db0733866b26411c07b7b17e741663d2f1c438.zip |
add new UserCancelledException
Diffstat (limited to 'pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas')
-rw-r--r-- | pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java | 50 |
1 files changed, 36 insertions, 14 deletions
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) { |