aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-07-15 18:50:42 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-07-15 18:50:42 +0200
commit8b69a68f80ce64da4bc68f9d03a17113d48a0599 (patch)
tree4ecdb9f7fd82ea0b1eee0be410e56c69438094b9 /pdf-as-web/src/main/java/at/gv/egiz
parent308bb7903ca0a293438bf4039a194ec098645ffd (diff)
downloadpdf-as-4-8b69a68f80ce64da4bc68f9d03a17113d48a0599.tar.gz
pdf-as-4-8b69a68f80ce64da4bc68f9d03a17113d48a0599.tar.bz2
pdf-as-4-8b69a68f80ce64da4bc68f9d03a17113d48a0599.zip
Verify per SOAP Service
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java24
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASVerificationImpl.java125
2 files changed, 149 insertions, 0 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java
index 23335268..017eabb2 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java
@@ -33,6 +33,13 @@ public class PdfAsParameterExtractor {
public static final String PARAM_TRANSACTION_ID = "transactionId";
public static final String PARAM_CONNECTOR_DEFAULT = "bku";
+ public static final String PARAM_FORMAT = "format";
+ public static final String PARAM_HTML = "html";
+ public static final String PARAM_JSON = "json";
+
+ public static final String[] AVAILABLE_FORMATS = new String[] {
+ PARAM_HTML, PARAM_JSON
+ };
public static final String PARAM_INVOKE_URL = "invoke-app-url";
public static final String PARAM_INVOKE_URL_TARGET = "invoke-app-url-target";
@@ -88,6 +95,23 @@ public class PdfAsParameterExtractor {
return (String)request.getAttribute(PARAM_INVOKE_URL_TARGET);
}
+ public static String getFormat(HttpServletRequest request) {
+ String format = (String)request.getAttribute(PARAM_FORMAT);
+
+ String finalFormat = null;
+ for(int i = 0; i < AVAILABLE_FORMATS.length; i++) {
+ if(AVAILABLE_FORMATS[i].equals(format)) {
+ finalFormat = AVAILABLE_FORMATS[i];
+ }
+ }
+
+ if(finalFormat == null) {
+ finalFormat = PARAM_HTML;
+ }
+
+ return finalFormat;
+ }
+
public static String getInvokeErrorURL(HttpServletRequest request) {
String url = (String)request.getAttribute(PARAM_INVOKE_URL_ERROR);
return url;
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASVerificationImpl.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASVerificationImpl.java
new file mode 100644
index 00000000..c6fb8cd7
--- /dev/null
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASVerificationImpl.java
@@ -0,0 +1,125 @@
+package at.gv.egiz.pdfas.web.ws;
+
+import iaik.x509.X509Certificate;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.MTOM;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.egiz.pdfas.api.ws.PDFASVerification;
+import at.gv.egiz.pdfas.api.ws.PDFASVerifyRequest;
+import at.gv.egiz.pdfas.api.ws.PDFASVerifyResponse;
+import at.gv.egiz.pdfas.api.ws.PDFASVerifyResult;
+import at.gv.egiz.pdfas.api.ws.VerificationLevel;
+import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel;
+import at.gv.egiz.pdfas.lib.api.verify.VerifyResult;
+import at.gv.egiz.pdfas.web.config.WebConfiguration;
+import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
+
+@MTOM
+@WebService(endpointInterface = "at.gv.egiz.pdfas.api.ws.PDFASVerification")
+public class PDFASVerificationImpl implements PDFASVerification {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(PDFASVerificationImpl.class);
+
+ public PDFASVerifyResponse verifyPDFDokument(PDFASVerifyRequest request) {
+ checkSoapVerifyEnabled();
+ if (request == null) {
+ logger.warn("SOAP Verify Request is null!");
+ return null;
+ }
+
+ PDFASVerifyResponse response = new PDFASVerifyResponse();
+ response.setVerifyResults(new ArrayList<PDFASVerifyResult>());
+ try {
+ int sigIdx = -1;
+ if (request.getSignatureIndex() != null) {
+ sigIdx = request.getSignatureIndex().intValue();
+ }
+
+ SignatureVerificationLevel lvl = SignatureVerificationLevel.INTEGRITY_ONLY_VERIFICATION;
+
+ if (request.getVerificationLevel().equals(
+ VerificationLevel.INTEGRITY_ONLY)) {
+ lvl = SignatureVerificationLevel.INTEGRITY_ONLY_VERIFICATION;
+ } else if (request.getVerificationLevel().equals(
+ VerificationLevel.FULL_CERT_PATH)) {
+ lvl = SignatureVerificationLevel.FULL_VERIFICATION;
+ }
+
+ List<VerifyResult> results = PdfAsHelper.synchornousVerify(
+ request.getInputData(), sigIdx, lvl);
+
+ for(int i = 0; i < results.size(); i++) {
+ VerifyResult result = results.get(i);
+
+ PDFASVerifyResult webResult = new PDFASVerifyResult();
+
+ X509Certificate cert = (X509Certificate) result
+ .getSignerCertificate();
+
+ int certCode = result.getCertificateCheck().getCode();
+ String certMessage = result.getCertificateCheck().getMessage();
+
+ int valueCode = result.getValueCheckCode().getCode();
+ String valueMessage = result.getValueCheckCode().getMessage();
+
+ Exception e = result.getVerificationException();
+
+ webResult.setRequestID(request.getRequestID());
+ webResult.setSignatureIndex(i);
+ webResult.setProcessed(result.isVerificationDone());
+
+ if (result.isVerificationDone()) {
+ webResult.setSignedBy(cert.getSubjectDN().getName());
+ webResult.setCertificateCode(certCode);
+ webResult.setCertificateMessage(certMessage);
+
+ webResult.setValueCode(valueCode);
+ webResult.setValueMessage(valueMessage);
+ if (e != null) {
+ webResult.setError(e.getMessage());
+ }
+ webResult.setCertificate("signCert?SIGID=" + i);
+ webResult.setSignedData("signData?SIGID=" + i);
+ } else {
+ webResult.setSignedBy("");
+ webResult.setCertificateCode(certCode);
+ webResult.setCertificateMessage(certMessage);
+
+ webResult.setCertificateCode(valueCode);
+ webResult.setCertificateMessage(valueMessage);
+ if (e != null) {
+ webResult.setError(e.getMessage());
+ }
+ webResult.setCertificate("");
+ webResult.setSignedData("");
+ }
+
+ response.getVerifyResults().add(webResult);
+ }
+ } catch (Exception e) {
+ logger.error("Failed to verify PDF", e);
+ if (WebConfiguration.isShowErrorDetails()) {
+ throw new WebServiceException("Generic Error", e);
+ } else {
+ throw new WebServiceException("Server Verification failed.");
+ }
+ }
+ return response;
+ }
+
+ private void checkSoapVerifyEnabled() {
+ if (!WebConfiguration.getSoapVerifyEnabled()) {
+ throw new WebServiceException("Service disabled!");
+ }
+ }
+
+}