diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-07-15 18:49:39 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-07-15 18:49:39 +0200 |
commit | 308bb7903ca0a293438bf4039a194ec098645ffd (patch) | |
tree | 08cf1e7d2ac37a48d50dfd212717251f58c80df9 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets | |
parent | 7194ad1f6a22507867f471fd6c8a37c6596d4b8a (diff) | |
download | pdf-as-4-308bb7903ca0a293438bf4039a194ec098645ffd.tar.gz pdf-as-4-308bb7903ca0a293438bf4039a194ec098645ffd.tar.bz2 pdf-as-4-308bb7903ca0a293438bf4039a194ec098645ffd.zip |
added JSON capabilities to Verify Servlet
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets')
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java | 97 |
1 files changed, 16 insertions, 81 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java index e9d1f246..09af4357 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java @@ -23,11 +23,8 @@ ******************************************************************************/ package at.gv.egiz.pdfas.web.servlets; -import iaik.x509.X509Certificate; - import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.util.List; import javax.servlet.ServletException; @@ -42,11 +39,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +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.exception.PdfAsWebException; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; import at.gv.egiz.pdfas.web.helper.PdfAsParameterExtractor; import at.gv.egiz.pdfas.web.helper.RemotePDFFetcher; +import at.gv.egiz.pdfas.web.helper.VerifyEncoder; +import at.gv.egiz.pdfas.web.helper.VerifyResultEncoder; /** * Servlet implementation class VerifyServlet @@ -243,11 +243,18 @@ public class VerifyServlet extends HttpServlet { protected void doVerify(HttpServletRequest request, HttpServletResponse response, byte[] pdfData) throws Exception { + SignatureVerificationLevel lvl = PdfAsParameterExtractor + .getVerificationLevel(request); + PdfAsHelper.setVerificationLevel(request, lvl); + + String format = PdfAsParameterExtractor.getFormat(request); + logger.debug("doVerify"); logger.info("Starting verification of pdf dokument"); - List<VerifyResult> results = PdfAsHelper.synchornousVerify(request, - response, pdfData); + logger.debug("Format: " + format); + + List<VerifyResult> results = PdfAsHelper.synchornousVerify(pdfData, -1, lvl); PdfAsHelper.setVerificationResult(request, results); @@ -256,85 +263,13 @@ public class VerifyServlet extends HttpServlet { // Or create a JSON response with the verification results for automated // processing - StringBuilder sb = new StringBuilder(); - - sb.append("<html><head><title></title></head><body>"); - sb.append("<h3>Verification Results for: " + PdfAsHelper.getPDFFileName(request) + "</h3>"); - sb.append("<table style=\"width:100%\" border='1' >"); + VerifyResultEncoder encoder = VerifyEncoder.getEncoder(format); - sb.append("<tr>"); - - sb.append("<th>Signature</th>"); - sb.append("<th>Processed</th>"); - sb.append("<th>Signed By</th>"); - sb.append("<th>Cert Code</th>"); - sb.append("<th>Cert Message</th>"); - sb.append("<th>Value Code</th>"); - sb.append("<th>Value Message</th>"); - sb.append("<th>Error</th>"); - sb.append("<th>Certificate</th>"); - sb.append("<th>Certificate</th>"); - sb.append("<th>Signed Data</th>"); - - sb.append("</tr>"); - - for (int i = 0; i < results.size(); i++) { - VerifyResult result = results.get(i); - sb.append("<tr>"); - - sb.append("<td>" + i + "</td>"); - - if (result.isVerificationDone()) { - sb.append("<td>YES</td>"); - int certCode = result.getCertificateCheck().getCode(); - String certMessage = result.getCertificateCheck().getMessage(); - - int valueCode = result.getValueCheckCode().getCode(); - String valueMessage = result.getValueCheckCode().getMessage(); - - Exception e = result.getVerificationException(); - - X509Certificate cert = (X509Certificate)result.getSignerCertificate(); - - sb.append("<td>" + cert.getSubjectDN().getName() + "</td>"); - sb.append("<td>" + certCode + "</td>"); - sb.append("<td>" + certMessage + "</td>"); - sb.append("<td>" + valueCode + "</td>"); - sb.append("<td>" + valueMessage + "</td>"); - if(e != null) { - sb.append("<td>" + e.getMessage() + "</td>"); - } else { - sb.append("<td>-</td>"); - } - if(result.isQualifiedCertificate()) { - sb.append("<td><a href=\"signCert?SIGID=" + i + "\">here</a> (QC)</td>"); - } else { - sb.append("<td><a href=\"signCert?SIGID=" + i + "\">here</a></td>"); - } - sb.append("<td><a href=\"signData?SIGID=" + i + "\">here</a></td>"); - - } else { - sb.append("<td>NO</td>"); - sb.append("<td>-</td>"); - sb.append("<td>-</td>"); - sb.append("<td>-</td>"); - sb.append("<td>-</td>"); - sb.append("<td>-</td>"); - sb.append("<td>-</td>"); - sb.append("<td>-</td>"); - sb.append("<td>-</td>"); - } - - - sb.append("</tr>"); + if(encoder == null) { + encoder = VerifyEncoder.getEncoder(PdfAsParameterExtractor.PARAM_HTML); } - sb.append("</table>"); - sb.append("</body></html>"); - response.setContentType("text/html"); - OutputStream os = response.getOutputStream(); - os.write(sb.toString().getBytes()); - os.close(); + encoder.produce(request, response, results); } } |