From bab89f89456290660afeb320a7bd3444bd79f9bb Mon Sep 17 00:00:00 2001 From: pdanner Date: Mon, 6 Dec 2010 16:55:14 +0000 Subject: Moved to pdf-as-web project git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@675 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../wag/egov/egiz/web/servlets/DataURLServlet.java | 377 ----------- .../egov/egiz/web/servlets/ProvidePDFServlet.java | 119 ---- .../web/servlets/RetrieveSignatureDataServlet.java | 149 ----- .../egov/egiz/web/servlets/SignPreviewServlet.java | 77 --- .../wag/egov/egiz/web/servlets/SignServlet.java | 649 ------------------ .../egov/egiz/web/servlets/UpdateFormServlet.java | 56 -- .../egiz/web/servlets/VerifyPreviewServlet.java | 723 --------------------- .../wag/egov/egiz/web/servlets/VerifyServlet.java | 466 ------------- 8 files changed, 2616 deletions(-) delete mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java delete mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java delete mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java delete mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java delete mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java delete mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java delete mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java delete mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java (limited to 'src') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java deleted file mode 100644 index 621ee6f..0000000 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java +++ /dev/null @@ -1,377 +0,0 @@ -/** - * - */ -package at.knowcenter.wag.egov.egiz.web.servlets; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileItemFactory; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.pdfas.exceptions.framework.SignatorException; -import at.gv.egiz.pdfas.framework.SignatorFactory; -import at.gv.egiz.pdfas.framework.signator.Signator; -import at.gv.egiz.pdfas.web.SignSessionInformation; -import at.gv.egiz.pdfas.web.VerifySessionInformation; -import at.gv.egiz.pdfas.web.helper.SessionHelper; -import at.gv.egiz.pdfas.web.helper.SignServletHelper; -import at.gv.egiz.pdfas.web.helper.SigningTimeHelper; -import at.gv.egiz.pdfas.web.helper.TempDirHelper; -import at.knowcenter.wag.egov.egiz.PdfASID; -import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; -import at.knowcenter.wag.egov.egiz.exceptions.InvalidIDException; -import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; -import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; -import at.knowcenter.wag.egov.egiz.exceptions.SignatorFactoryException; -import at.knowcenter.wag.egov.egiz.exceptions.SignatureException; -import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder; -import at.knowcenter.wag.egov.egiz.sig.SignatureResponse; -import at.knowcenter.wag.egov.egiz.sig.connectors.ConnectorChooser; -import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector; -import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUHelper; -import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUPostConnection; -import at.knowcenter.wag.egov.egiz.sig.signaturelayout.SignatureLayoutHandler; -import at.knowcenter.wag.egov.egiz.sig.signaturelayout.SignatureLayoutHandlerFactory; -import at.knowcenter.wag.egov.egiz.web.FormFields; -import at.knowcenter.wag.egov.egiz.web.LocalRequest; -import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper; -import at.knowcenter.wag.egov.egiz.web.SessionAttributes; - -/** - * @author wprinz - * - */ -public class DataURLServlet extends HttpServlet -{ - - /** - * SVUID. - */ - private static final long serialVersionUID = -5846618335843762752L; - - /** - * The log. - */ - private static Log log = LogFactory.getLog(DataURLServlet.class); - - protected void dispatch(HttpServletRequest request, - HttpServletResponse response, String resource) throws ServletException, IOException - { - dispatch(request, response, resource, getServletContext()); - } - - protected static void dispatch(HttpServletRequest request, - HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException - { - response.setContentType("text/html"); - response.setCharacterEncoding("UTF-8"); - - RequestDispatcher disp = context.getRequestDispatcher(resource); - disp.forward(request, response); - } - - protected void dispatchToResults(List results, HttpServletRequest request, - HttpServletResponse response, String backToListURL) throws ServletException, IOException - { - request.setAttribute("results", results); - request.setAttribute("btlurl", backToListURL); - dispatch(request, response, "/jsp/results.jsp"); - } - - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - this.doPost(req, resp); - } - - private static void temporaryRedirect(String redirectURL, HttpServletResponse response) throws IOException { - String encodedRedirect = response.encodeRedirectURL(redirectURL); - response.addHeader("Location", encodedRedirect); - response.setContentType("text/xml"); - response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT); - String nop = ""; - PrintWriter pw = response.getWriter(); - response.setCharacterEncoding("UTF-8"); - response.setContentLength(nop.getBytes("UTF-8").length); - log.debug("Redirecting via NullOperationRequest to " + encodedRedirect + "."); - pw.println(nop); - pw.flush(); - pw.close(); - } - -/** - * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, - * javax.servlet.http.HttpServletResponse) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - log.debug("Data URL is accessed."); //$NON-NLS-1$ - - try - { - Object sessionObject = SessionHelper.getSession(request); - - // obsolete since EncodingFilter is set in web.xml - checkRequestCharacterEncoding(request); - - if (sessionObject instanceof SignSessionInformation) - { - SignSessionInformation si = (SignSessionInformation)sessionObject; - processSign(request, response, si); - } - else - { - VerifySessionInformation si = (VerifySessionInformation) sessionObject; - processVerify(request, response, si); - } - - } - catch (PresentableException e) - { - log.error(e.getMessage(), e); - SignServlet.prepareDispatchToErrorPage(e, request); - dispatch(request, response, "/jsp/error.jsp"); - } - - log.debug("DataURL access finished."); //$NON-NLS-1$ - } - - protected void checkRequestCharacterEncoding(HttpServletRequest request) throws UnsupportedEncodingException - { - if (request.getCharacterEncoding() == null || request.getCharacterEncoding().length() <= 0) //$NON-NLS-1$ - { - log.info("The BKU didn't set a character encoding for the request."); //$NON-NLS-1$ - - log.info("Manually setting character encoding to UTF-8"); //$NON-NLS-1$ - request.setCharacterEncoding("UTF-8"); //$NON-NLS-1$ - } - } - - protected boolean isNullResponse(String xml_response) - { - return xml_response != null && xml_response.indexOf("NullOperationResponse") != -1; - } - - private static String retrieveXMLResponse(HttpServletRequest request) throws ServletException { - log.debug("Trying to fetch XMLResponse..."); - String xml_response = null; - if (ServletFileUpload.isMultipartContent(request)) { - log.debug("Response is multipart."); - FileItemFactory factory = new DiskFileItemFactory(); - ServletFileUpload upload = new ServletFileUpload(factory); - try { - List items = upload.parseRequest(request); - Iterator iter = items.iterator(); - while (iter.hasNext()) { - FileItem item = (FileItem) iter.next(); - if (item.isFormField() && "XMLResponse".equals(item.getFieldName())) { - log.debug("XMLResponse part found."); - xml_response = item.getString(); - break; - } - } - } catch (FileUploadException e) { - throw new ServletException(e); - } - } else { - xml_response = request.getParameter("XMLResponse"); - } - log.debug("XMLResponse = " + xml_response); - return xml_response; - } - - protected void processSign(HttpServletRequest request, HttpServletResponse response, SignSessionInformation si) throws ServletException, IOException, ConnectorException, SignatorException, SignatorFactoryException, SignatureException - { - log.trace("processSign"); - - String xml_response = retrieveXMLResponse(request); - Properties response_properties = BKUHelper.getBKUProperties(request); - - String bkuIdentifier = BKUHelper.getBKUIdentifier(response_properties); - log.debug("BKU identifier: \"" + bkuIdentifier + "\""); - - try { - SignatureLayoutHandlerFactory.verifyBKUSupport(bkuIdentifier); - } catch (SettingsException e) { - throw new ConnectorException(e.getErrorCode(), e.getMessage()); - } - - if (isNullResponse(xml_response)) - { - log.debug("Received a NullOperationResponse -> answering with the first request."); //$NON-NLS-1$ - - assert si.outputAvailable == false; - assert si.response_properties == null; - - log.debug("There are still requests to be performed -> answering with request."); //$NON-NLS-1$ - - LocalRequest local_request = si.localRequest; - - String request_string = local_request.getRequestString(); - - log.debug("request = " + request_string); - response.setContentType("text/xml"); - response.setCharacterEncoding("UTF-8"); - response.getWriter().println(request_string); - } - else if (xml_response != null) - { - log.debug("Received a normal response -> storing the response."); //$NON-NLS-1$ - - response_properties.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xml_response); - - si.response_properties = response_properties; - - log.debug("All requests have been processed -> processing the responses."); //$NON-NLS-1$ - - // Sign - - if (!si.outputAvailable) - { - LocalConnector c = ConnectorChooser.chooseLocalConnectorForSign(si.connector, si.type, "loc ref content not needed here"); //$NON-NLS-1$ - - si.si.setSignSignatureObject(c.analyzeSignResponse(si.response_properties)); - - // workaround for invalid signing time - SigningTimeHelper.checkSigningTimeAgainstHostTime(si.si); - - PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode); - Signator signator = SignatorFactory.createSignator(algorithm); - - si.output = TempDirHelper.createTempDataSink(si.filename + "_signed.pdf"); - - signator.finishSign(si.si, si.output); - - si.outputAvailable = true; - } - - if (si.output.getMimeType().equals("text/xml") && si.outputAvailable) - { - // For "detached" signatures, the return value (data sink) is the response xml, - // but when passed through the BKU it is interpreted as another request - // which will generate a return code 1501 - // Then PDF-AS would answer with the response as well generating - // another 1501 and so forth. - // Therefor return it as TXT. - response.setContentType("text/plain"); - response.setCharacterEncoding("UTF-8"); - response.getWriter().println("Das detached XML kann nicht direkt durch die BKU geschliffen werden, weil diese es als Request interpretieren würde. Daher das XML als Text:"); - response.getWriter().println(si.si.getSignSignatureObject().response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY)); - } - else - { - // tzefferer: If PDF-AS has been called by an external web-application, we do not - // redirect to download.jsp but return the sign-response immediately - if (si.exappinf != null) { - log.debug("Entering external application interface mode. Skipping redirection to download page."); - SignServletHelper.returnSignResponse(si, request, response); - - // Not needed due to redirection of returnSignResponse. - // Just to clarify that there must not be any code after returnSignResponse. - return; - } else { - log.debug("Preparing download page."); - HttpSession session = request.getSession(true); - log.debug("Putting signed document into session (" + session.getId() + ")."); - session.setAttribute(SessionAttributes.SIGNED_PDF_DOCUMENT, si); - String downloadURL = response.encodeRedirectURL(LocalRequestHelper.getLocalContextAddress(request, response) + "/ProvidePDF"); - log.debug("Creating download URL \"" + downloadURL + "\"."); - session.setAttribute(SessionAttributes.DOWNLOAD_URL_FOR_SIGNED_PDF_DOCUMENT, downloadURL); - temporaryRedirect(response.encodeRedirectURL(LocalRequestHelper.getLocalContextAddress(request, response) + "/jsp/download.jsp") , response); - - // Not needed due to temporaryRedirect. - // Just to clarify that there must not be any code after temporaryRedirect. - return; - } - - // do not insert any code within this else block ! - } - } else { - log.debug("No XMLResponse found. Do nothing."); - } - } - - protected void processVerify(HttpServletRequest request, HttpServletResponse response, VerifySessionInformation si) throws ServletException, IOException, ConnectorException, InvalidIDException - { - log.trace("processVerify"); - - String xml_response = request.getParameter("XMLResponse"); //$NON-NLS-1$ - log.debug("xml_response = " + xml_response); //$NON-NLS-1$ - - if (isNullResponse(xml_response)) - { - log.debug("Received a NullOperationResponse -> answering with the first request."); //$NON-NLS-1$ - - assert si.currentLocalOperation.current_operation == 0; - } - else - { - log.debug("Recieved a normal response -> storing the response."); //$NON-NLS-1$ - - Properties response_properties = new Properties(); - response_properties.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xml_response); - - si.currentLocalOperation.finishCurrentOperation(response_properties); - } - - if (!si.currentLocalOperation.isFinished()) - { - log.debug("There are still requests to be performed -> answering with request #" + si.currentLocalOperation.current_operation); //$NON-NLS-1$ - - LocalRequest local_request = si.currentLocalOperation.getCurrentLocalRequest(); - - String request_string = local_request.getRequestString(); - - response.setContentType("text/xml"); - response.setCharacterEncoding("UTF-8"); - response.getWriter().println(request_string); - } - else - { - log.debug("All requests have been processed -> processing the responses."); //$NON-NLS-1$ - - - List results = new ArrayList(); - - for (int i = 0; i < si.currentLocalOperation.response_properties.length; i++) - { - SignatureHolder sh = (SignatureHolder) si.currentLocalOperation.holders_to_be_verified.get(i); - - PdfASID sig_kz = sh.getSignatureObject().getKZ(); - String sig_id = sh.getSignatureObject().getSignationIds(); - - LocalConnector c = ConnectorChooser.chooseLocalConnectorForVerify(si.connector, sig_kz, sig_id, si.type, "loc ref content not needed here"); //$NON-NLS-1$ - - SignatureResponse sig_resp = c.analyzeVerifyResponse(si.currentLocalOperation.response_properties[i]); - results.add(sig_resp); - } - - si.currentLocalOperation = null; - - URL btlURL = new URL(LocalRequestHelper.getLocalContextAddress(request, response) + "/jsp/verifylist.jsp"); - String backToListURL = response.encodeURL(btlURL.toString()); - - dispatchToResults(results, request, response, backToListURL); - } - - } -} diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java deleted file mode 100644 index 715b5be..0000000 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java +++ /dev/null @@ -1,119 +0,0 @@ -package at.knowcenter.wag.egov.egiz.web.servlets; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.pdfas.web.SignSessionInformation; -import at.gv.egiz.pdfas.web.helper.SignServletHelper; -import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; -import at.knowcenter.wag.egov.egiz.web.FormFields; -import at.knowcenter.wag.egov.egiz.web.PDFContainer; -import at.knowcenter.wag.egov.egiz.web.SessionAttributes; - -public class ProvidePDFServlet extends HttpServlet { - - /** - * SVUID. - */ - private static final long serialVersionUID = 1L; - - /** - * The log. - */ - private static Log log = LogFactory.getLog(ProvidePDFServlet.class); - - public static Set signedDocuments = Collections.synchronizedSet(new HashSet()); - - public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - String pdfIdString = request.getParameter(FormFields.FIELD_PDF_ID); - HttpSession session = request.getSession(); - - if (pdfIdString == null) { - log.debug("No " + FormFields.FIELD_PDF_ID + " provided. Trying to retrieve PDF from session (" + session.getId() + ")."); - SignSessionInformation si = (SignSessionInformation) session.getAttribute(SessionAttributes.SIGNED_PDF_DOCUMENT); - if (si == null) { - log.warn("Unable to find signed pdf in session (" + session.getId() + ")."); - SignServlet.prepareDispatchToErrorPage(new PresentableException(600, "Das signierte Dokument konnte nicht gefunden werden."), request); - response.setContentType("text/html"); - response.setCharacterEncoding("UTF-8"); - RequestDispatcher disp = super.getServletContext().getRequestDispatcher("/jsp/error.jsp"); - disp.forward(request, response); - return; - } else { - log.debug("Signed pdf found."); - // do NOT remove signed pdf document from session since IE9 loads this page/servlet twice...) - // Popup-Blocker, Link-Prefetching, IE 9 SmartScreen-Filter...??? - // session.removeAttribute(SessionAttributes.SIGNED_PDF_DOCUMENT); - log.debug("Returning signed pdf to browser."); - SignServletHelper.returnSignResponse(si, request, response); - log.debug("Removing free text (if any) from session."); - session.removeAttribute(UpdateFormServlet.UPLOADFORM_FREETEXT_KEY); - return; - } - } else { - long pdfId = Long.parseLong(pdfIdString); - - byte[] pdf = null; - - synchronized (signedDocuments) { - Iterator it = signedDocuments.iterator(); - - while (it.hasNext() && pdf == null) { - PDFContainer current = (PDFContainer) it.next(); - if (current.id == pdfId) { - pdf = current.pdf; - signedDocuments.remove(current); - } - } - } - - if (pdf != null) { - try { - - SignServletHelper.disableBrowserCacheForResponse(response); - response.setContentType("application/pdf"); - response.setContentLength(pdf.length); - - InputStream is = new ByteArrayInputStream(pdf); - final int bufferSize = 1024; - byte[] buffer = new byte[bufferSize]; - int len = -1; - while ((len = is.read(buffer)) != -1) { - response.getOutputStream().write(buffer, 0, len); - } - response.getOutputStream().flush(); - log.debug("File sent. Invalidating session."); - session.invalidate(); - } catch (IOException e) { - log.error("IO excepton while providing pdf document: " + e.getMessage(), e); - } - } else { - log.error("Unable to find signed pdf (id=" + pdfId + ") in session (" + session.getId() + ")."); - return; - } - - } - - } - - public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - doPost(request, response); - } - -} diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java deleted file mode 100644 index 1b32db8..0000000 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * - */ -package at.knowcenter.wag.egov.egiz.web.servlets; - -import java.io.IOException; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.pdfas.exceptions.web.SessionExpiredException; -import at.gv.egiz.pdfas.utils.StreamUtils; -import at.gv.egiz.pdfas.web.SignSessionInformation; -import at.gv.egiz.pdfas.web.VerifySessionInformation; -import at.gv.egiz.pdfas.web.helper.SessionHelper; -import at.knowcenter.wag.egov.egiz.PdfAS; -import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder; -import at.knowcenter.wag.egov.egiz.sig.SignatureData; - -/** - * Retrieves the Signature Data from the session and returns it. - * - * @author wprinz - */ -public class RetrieveSignatureDataServlet extends HttpServlet -{ - - /** - * SVUID. - */ - private static final long serialVersionUID = -5387006236836240538L; - - /** - * The log. - */ - private static Log log = LogFactory.getLog(RetrieveSignatureDataServlet.class); - - protected void dispatch(HttpServletRequest request, - HttpServletResponse response, String resource) throws ServletException, IOException - { - dispatch(request, response, resource, getServletContext()); - } - - protected static void dispatch(HttpServletRequest request, - HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException - { - response.setContentType("text/html"); - response.setCharacterEncoding("UTF-8"); - - RequestDispatcher disp = context.getRequestDispatcher(resource); - disp.forward(request, response); - } - -/** - * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, - * javax.servlet.http.HttpServletResponse) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - if (log.isDebugEnabled()) { - log.debug("Request for receiving signature data."); //$NON-NLS-1$ - log.debug("Requested session id is = " + request.getRequestedSessionId()); - } - - try - { - Object sessionObject = SessionHelper.getSession(request); - - if (sessionObject instanceof SignSessionInformation) - { - SignSessionInformation si = (SignSessionInformation) sessionObject; - processSign(request, response, si); - } - else - { - VerifySessionInformation si = (VerifySessionInformation) sessionObject; - processVerify(request, response, si); - } - } - catch (SessionExpiredException e) - { - log.error(e.getMessage(), e); - SignServlet.prepareDispatchToErrorPage(e, request); - dispatch(request, response, "/jsp/error.jsp"); - } - } - - protected void processSign(HttpServletRequest request, HttpServletResponse response, SignSessionInformation si) throws ServletException, IOException - { - writeSignatureData(si.si.getSignatureData(), response); - } - - protected void processVerify(HttpServletRequest request, HttpServletResponse response, VerifySessionInformation si) throws ServletException, IOException - { - SignatureData sd = null; - - SignatureHolder holder = null; - - if (si.currentLocalOperation != null) - { - holder = si.currentLocalOperation.getCurrentSignatureHolder(); - } - else - { - holder = si.moa_holder; - } - - log.debug("holder = " + holder.toString()); - - sd = PdfAS.convertSignatureHolderToSignatureData(holder); -// if (holder.getSignatureObject().isBinary()) -// { -// BinarySignatureHolder bsh = (BinarySignatureHolder) holder; -// // byte[] data = CodingHelper.decodeBase64(text_to_be_verified); -// sd = new SignatureDataImpl(bsh.getSignedPdf(), "application/pdf"); -// } -// else -// { -// String text_to_be_verified = holder.getSignedText(); -// DataSource ds = new TextDataSourceImpl(text_to_be_verified); -// sd = new SignatureDataImpl(ds, "text/plain", "UTF-8"); -// } - - log.debug("sd = " + sd.toString() + ", " + sd.getDataSource().getClass().getName() + ", " + sd.getDataSource().getLength() + ", " + sd.getMimeType() + ", " + sd.getCharacterEncoding()); - - writeSignatureData(sd, response); - } - - protected void writeSignatureData(SignatureData sd, HttpServletResponse response) throws IOException - { - log.trace("Writing " + sd.getMimeType() + " data:"); //$NON-NLS-1$ //$NON-NLS-2$ - - response.setContentType(sd.getMimeType()); - response.setCharacterEncoding(sd.getCharacterEncoding()); - // [tknall] content length must be set, otherwise ITS BKU for Mac rejects the request. - response.setContentLength(sd.getDataSource().getLength()); - StreamUtils.writeInputStreamToOutputStream(sd.getDataSource().createInputStream(), response.getOutputStream()); - // response.getOutputStream().write(sd.getData()); - - log.trace("Writing SignatureData finished."); //$NON-NLS-1$ - } -} diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java deleted file mode 100644 index fa6b734..0000000 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (c) 2006 by Know-Center, Graz, Austria - * - * This software is the confidential and proprietary information of Know-Center, - * Graz, Austria. You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Know-Center. - * - * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF - * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR - * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY - * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. - * - * $Id: SignPreview.java,v 1.2 2006/10/11 07:39:13 wprinz Exp $ - */ -package at.knowcenter.wag.egov.egiz.web.servlets; - -import java.io.IOException; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.pdfas.web.SignSessionInformation; -import at.gv.egiz.pdfas.web.helper.SessionHelper; -import at.gv.egiz.pdfas.web.helper.SignServletHelper; -import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; - -/** - * @author wprinz - */ -public class SignPreviewServlet extends HttpServlet -{ - - protected static Log logger = LogFactory.getLog(SignPreviewServlet.class); - - /** - * SVUID. - */ - private static final long serialVersionUID = -8818532511322299998L; - - protected void dispatch(HttpServletRequest request, - HttpServletResponse response, String resource) throws ServletException, IOException - { - response.setContentType("text/html"); - response.setCharacterEncoding("UTF-8"); - - RequestDispatcher disp = getServletContext().getRequestDispatcher(resource); - disp.forward(request, response); - } - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - try - { - Object sessionObject = SessionHelper.getSession(request); - - SignSessionInformation si = (SignSessionInformation) sessionObject; - - SignServletHelper.finishSign(si, request, response, getServletContext()); - } - catch (PresentableException e) - { - logger.error(e.getMessage(), e); - - SignServlet.prepareDispatchToErrorPage(e, request); - dispatch(request, response, "/jsp/error.jsp"); - } - } -} diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java deleted file mode 100644 index 982e872..0000000 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java +++ /dev/null @@ -1,649 +0,0 @@ -/** - * Copyright (c) 2006 by Know-Center, Graz, Austria - * - * This software is the confidential and proprietary information of Know-Center, - * Graz, Austria. You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Know-Center. - * - * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF - * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR - * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY - * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. - * - * $Id: Sign.java,v 1.7 2006/10/11 07:39:13 wprinz Exp $ - */ -package at.knowcenter.wag.egov.egiz.web.servlets; - -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.util.Iterator; -import java.util.List; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.lowagie.text.DocumentException; - -import at.gv.egiz.pdfas.exceptions.ErrorCode; -import at.gv.egiz.pdfas.exceptions.ErrorCodeHelper; -import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException; -import at.gv.egiz.pdfas.framework.input.PdfDataSource; -import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl; -import at.gv.egiz.pdfas.itext.IText; -import at.gv.egiz.pdfas.utils.ConfigUtils; -import at.gv.egiz.pdfas.utils.PDFASUtils; -import at.gv.egiz.pdfas.utils.WebUtils; -import at.gv.egiz.pdfas.web.SignSessionInformation; -import at.gv.egiz.pdfas.web.helper.SignServletHelper; -import at.gv.egiz.pdfas.web.helper.TempDirHelper; -import at.knowcenter.wag.egov.egiz.PdfAS; -import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; -import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException; -import at.knowcenter.wag.egov.egiz.exceptions.PlaceholderException; -import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; -import at.knowcenter.wag.egov.egiz.pdf.TablePos; -import at.knowcenter.wag.egov.egiz.web.ExternAppInformation; -import at.knowcenter.wag.egov.egiz.web.FormFields; -import at.knowcenter.wag.egov.egiz.web.SessionAttributes; - -/** - * This method is the sign servlet for the pdf-as web application. It takes get - * and post requests fill out jsp templates and give the user feedback about the - * results of the sign process - * - * @author wlackner - * @author wprinz - */ -public class SignServlet extends HttpServlet -{ - - /** - * SVUID. - */ - private static final long serialVersionUID = -4156938216903740438L; - - /** - * The log. - */ - private static Log log = LogFactory.getLog(SignServlet.class); - private static Log statLog = LogFactory.getLog("statistic"); - - protected void dispatch(HttpServletRequest request, HttpServletResponse response, String resource) throws ServletException, IOException - { - dispatch(request, response, resource, getServletContext()); - } - - protected static void dispatch(HttpServletRequest request, HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException - { - response.setContentType("text/html"); - response.setCharacterEncoding("UTF-8"); - - RequestDispatcher disp = context.getRequestDispatcher(resource); - disp.forward(request, response); - } - - // The sign servlet is used for processing the upload only. - // Authentication is deactivated. if required - make an own servlet. - // /** - // * @author modified by tknall - // */ - // public void doGet(HttpServletRequest request, HttpServletResponse response) - // throws ServletException, IOException - // { - // String authenticate = request.getHeader(AUTH); - // if (authenticate != null) - // { - // logger_.info("authenticate:" + authenticate); - // if (authenticate.indexOf(AUTH_BASIC) == 0) - // { - // authenticate = authenticate.substring(AUTH_BASIC.length() + 1); - // logger_.info("authenticate:" + authenticate); - // authenticate = new String(CodingHelper.decodeBase64(authenticate), - // "UTF-8"); - // logger_.info("authenticate:" + authenticate); - // - // String[] auth_value = authenticate.split(":"); - // String user_name = auth_value[0]; - // String user_password = auth_value[1]; - // logger_.info("username:" + user_name); - // // start modification tknall - // // logger_.info("password:" + user_password); - // logger_.info("password:XXXXXXXXXXXX"); - // // stop modification tknall - // - // HttpSession session = request.getSession(); - // session.setAttribute(SessionAttributes.ATTRIBUTE_USER_NAME, user_name); - // session.setAttribute(SessionAttributes.ATTRIBUTE_USER_PASSWORD, - // user_password); - // - // dispatch(request, response, "/jsp/signupload.jsp"); - // return; - // } - // // start modification tknall - // } else { - // String user_name = ""; - // String user_password = ""; - // logger_.info("authenticate:User has not been authenticated!"); - // logger_.info("username: UNKNOWN"); - // logger_.info("password: XXXXXXXXXXXX"); - // HttpSession session = request.getSession(); - // session.setAttribute("uname", user_name); - // session.setAttribute("upass", user_password); - // dispatch(request, response, "/jsp/signupload.jsp"); - // } - - // request.setAttribute("error", "Falsche Authentifikation"); - // request.setAttribute("cause", "Passwort oder Benutzername ist falsch"); - // dispatch(request, response, "/jsp/error.jsp"); - // // stop modification tknall - // } - - /** - * Processes the sign upload. - * - * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, - * javax.servlet.http.HttpServletResponse) - */ - public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - UploadedData ud = null; - ExternAppInformation exappinf = null; - TablePos pos = null; - - // for performance measurement - long startTime = 0; - if (statLog.isInfoEnabled()) { - startTime = System.currentTimeMillis(); - } - - - - // check if pdf-as has been called by external webapp - if (request.getParameter(FormFields.FIELD_PDF_URL) != null) - { - - String preview = (String) request.getParameter(FormFields.FIELD_PREVIEW); - String sig_type = (String) request.getParameter(FormFields.FIELD_SIGNATURE_TYPE); - String sig_app = (String) request.getParameter(FormFields.FIELD_CONNECTOR); - String sig_mode = (String) request.getParameter(FormFields.FIELD_MODE); - String filename = (String) request.getParameter(FormFields.FIELD_FILENAME); - String pdf_url = (String) request.getParameter(FormFields.FIELD_PDF_URL); - String pdf_id = (String) request.getParameter(FormFields.FIELD_PDF_ID); - String pdf_length = (String) request.getParameter(FormFields.FIELD_FILE_LENGTH); - String invoke_url = (String) request.getParameter(FormFields.FIELD_INVOKE_APP_URL); - String invoke_error_url = (String) request.getParameter(FormFields.FIELD_INVOKE_APP_ERROR_URL); - String session_id = (String) request.getParameter(FormFields.FIELD_SESSION_ID); - String sig_pos_y = (String) request.getParameter(FormFields.FIELD_SIGPOS_Y); - String sig_pos_p = (String) request.getParameter(FormFields.FIELD_SIGPOS_P); - - // added by tknall - if (sig_pos_y != null && sig_pos_p != null) { - try - { - pos = new TablePos("y:" + sig_pos_y + ";p:" + sig_pos_p); - } - catch (PDFDocumentException e) - { - log.warn("Unable to create signature position object: " + e.getMessage(), e); - } - } else { - log.debug("No signature position provided."); - } - - // fixed by tknall: if we already have parameters "&" must be used instead of "?" - String paramSeparator = (pdf_url.indexOf("?") != -1) ? "&" : "?"; - String query = pdf_url + paramSeparator + FormFields.FIELD_PDF_ID + "=" + pdf_id; - - // wprinz: rem: this allocation is useless - // byte[] extern_pdf = new byte[Integer.parseInt(pdf_length)]; - URL source_url = new URL(query); - InputStream is = source_url.openStream(); - - // extern_pdf = toByteArray(is); - - // set UploadedData object... - UploadedData ud_extern = new UploadedData(); - - ud_extern.file_name = filename; - ud_extern.pdfDataSource = TempDirHelper.placePdfIntoTempDir(is, filename); - // ud_extern.pdf = extern_pdf; -// ud_extern.preview = preview.equalsIgnoreCase("true") ? true : false; - ud_extern.preview = "true".equalsIgnoreCase(preview); - ud_extern.sig_app = sig_app; - ud_extern.sig_mode = sig_mode; - ud_extern.sig_type = sig_type; - - ud = ud_extern; - - exappinf = new ExternAppInformation(invoke_url, pdf_id, session_id, invoke_error_url); - } - else - { - - try - { - - // tzefferer: modified - // UploadedData ud = retrieveUploadedDataFromRequest(request); - UploadedData ud_form = retrieveUploadedDataFromRequest(request); - ud = ud_form; - // end modify - - } - catch (Exception e) - { - log.error(e); - request.setAttribute("error", "signservlet.error"); - request.setAttribute("cause", "signservlet.cause"); - request.setAttribute("resourcebundle", Boolean.TRUE); - dispatch(request, response, "/jsp/error.jsp"); - return; - } - } - try - { - - ud.pdfDataSource = PdfAS.applyStrictMode(ud.pdfDataSource); - - SignSessionInformation si = new SignSessionInformation(); // SessionTable.generateSessionInformationObject(); - si.connector = ud.sig_app; - si.application = "sign"; - si.mode = ud.sig_mode; - si.pdfDataSource = ud.pdfDataSource; - si.type = ud.sig_type; - si.filename = formatFileName(ud.file_name); - si.download_inline = ud.download_inline; - - // added tzefferer: - si.exappinf = exappinf; - si.pos = pos; - // end add - - HttpSession session = request.getSession(); - log.info("Putting signature data into session " + session.getId()); - session.setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si); - - // String user_name = (String) - // request.getSession().getAttribute(SessionAttributes.ATTRIBUTE_USER_NAME); - // String user_password = (String) - // request.getSession().getAttribute(SessionAttributes.ATTRIBUTE_USER_PASSWORD); - // si.user_name = user_name; - // si.user_password = user_password; - - SignServletHelper.prepareSign(si); - - if (ud.preview) - { - String submit_url = response.encodeURL(request.getContextPath() + "/SignPreview"); -// String signature_data_url = response.encodeURL(WebUtils.addJSessionID(request.getContextPath() + "/RetrieveSignatureData", request)); - String signature_data_url = response.encodeURL(WebUtils.buildRetrieveSignatureDataURL(request, response)); - - request.setAttribute("submit_url", submit_url); - request.setAttribute("signature_data_url", signature_data_url); - - dispatch(request, response, "/jsp/signpreview.jsp"); - - return; - } - - SignServletHelper.finishSign(si, request, response, getServletContext()); - - // for performance measurement - if (statLog.isInfoEnabled()) { - long endTime = System.currentTimeMillis(); -// String toReport = "SIGN;" + si.mode + ";" + si.filename + ";"+ fileSize + ";" + - String toReport = "SIGN;" + si.mode + ";" + si.connector + ";" + si.pdfDataSource.getLength() + ";" + (endTime - startTime); - - statLog.info(toReport); - } - } - catch (PresentableException e) - { - log.error(e.getMessage(), e); - prepareDispatchToErrorPage(e, request); - dispatch(request, response, "/jsp/error.jsp"); - } catch (Exception e) { - log.error(e.getMessage(), e); - PresentableException pe = new PresentableException(ErrorCode.UNKNOWN_ERROR, e); - prepareDispatchToErrorPage(pe, request); - dispatch(request, response, "/jsp/error.jsp"); - } - } - - // tzefferer:added - public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - doPost(request, response); - } - // end add - - protected UploadedData retrieveUploadedDataFromRequest(HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException - { - DiskFileItemFactory fif = new DiskFileItemFactory(); - fif.setRepository(SettingsReader.getTemporaryDirectory()); - ServletFileUpload sfu = new ServletFileUpload(fif); - - List items = sfu.parseRequest(request); - - FileItem preview_fi = null; - FileItem sig_type_fi = null; - FileItem sig_app_fi = null; - FileItem mode_fi = null; - FileItem file_upload_fi = null; - FileItem download_fi = null; - FileItem freeText = null; - FileItem pdfa = null; - - Iterator it = items.iterator(); - HttpSession session = request.getSession(); - while (it.hasNext()) - { - FileItem item = (FileItem) it.next(); - log.debug("item = " + item.getFieldName()); //$NON-NLS-1$ - - if (log.isDebugEnabled()) - { - if (item.isFormField()) - { - String item_string = item.getString("UTF-8"); //$NON-NLS-1$ - log.debug(" form field string = " + item_string); //$NON-NLS-1$ - } - else - { - log.debug(" filename = " + item.getName()); //$NON-NLS-1$ - log.debug(" filesize = " + item.getSize()); //$NON-NLS-1$ - } - } - - if (item.getFieldName().equals(FormFields.FIELD_PREVIEW)) - { - preview_fi = item; - continue; - } - - if (item.getFieldName().equals(FormFields.FIELD_SIGNATURE_TYPE)) - { - sig_type_fi = item; - session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_TYPE_KEY, sig_type_fi.getString("UTF-8")); - continue; - } - - if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR)) - { - sig_app_fi = item; - session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_DEVICE_KEY, sig_app_fi.getString("UTF-8")); - continue; - } - - if (item.getFieldName().equals(FormFields.FIELD_MODE)) - { - mode_fi = item; - session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_MODE_KEY, mode_fi.getString("UTF-8")); - continue; - } - - if (item.getFieldName().equals(FormFields.FIELD_UPLOAD)) - { - file_upload_fi = item; - continue; - } - - if (item.getFieldName().equals(FormFields.FIELD_DOWNLOAD)) - { - download_fi = item; - continue; - } - - if (FormFields.FIELD_PDFA_ENABLED.equals(item.getFieldName())) { - pdfa = item; - session.setAttribute(UpdateFormServlet.UPLOADFORM_PDFA_KEY, pdfa.getString("UTF-8")); - continue; - } - - if (FormFields.FIELD_FREETEXT.equals(item.getFieldName())) { - freeText = item; - String value = freeText.getString("UTF-8"); - if (value != null) { - session.setAttribute(UpdateFormServlet.UPLOADFORM_FREETEXT_KEY, value); - } - continue; - } - - if (FormFields.FIELD_SOURCE.equals(item.getFieldName())) { - session.setAttribute(UpdateFormServlet.UPLOADFORM_SOURCE_KEY, item.getString("UTF-8")); - continue; - } - - throw new ServletException("Unrecognized POST data."); //$NON-NLS-1$ - - } - - if (preview_fi == null || sig_type_fi == null || sig_app_fi == null || (file_upload_fi == null && freeText== null) || download_fi == null) - { - throw new ServletException("Insufficient data provided in request"); //$NON-NLS-1$ - } - - String mode = mode_fi.getString("UTF-8"); //$NON-NLS-1$ - if (!mode.equals(FormFields.VALUE_MODE_BINARY) && !mode.equals(FormFields.VALUE_MODE_TEXTUAL) && !mode.equals(FormFields.VALUE_MODE_DETACHED)) - { - throw new ServletException("The mode '" + mode + "' is unrecognized."); //$NON-NLS-1$ //$NON-NLS-2$ - } - - String preview_str = preview_fi.getString("UTF-8"); //$NON-NLS-1$ - boolean preview = false; - if (preview_str.equals("true")) //$NON-NLS-1$ - { - preview = true; - } - - boolean download_inline = true; - if (download_fi.getString("UTF-8").equals(FormFields.VALUE_DOWNLOAD_ATTACHMENT)) //$NON-NLS-1$ - { - download_inline = false; - } - - String sig_type = sig_type_fi.getString("UTF-8"); //$NON-NLS-1$ - String sig_app = sig_app_fi.getString("UTF-8"); //$NON-NLS-1$ - - PdfDataSource pdfDataSource; - String doc_file_name; - // distinguish between file and freetext - if (file_upload_fi != null) { - log.debug("Processing file."); - doc_file_name = TempDirHelper.extractFileNameSuffix(file_upload_fi.getName()); - log.debug("file content type =" + file_upload_fi.getContentType()); //$NON-NLS-1$ - - String extension = VerifyServlet.extractExtension(doc_file_name); - if (extension != null && !extension.equals("pdf")) //$NON-NLS-1$ - { - throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$ - } - - if (file_upload_fi.getSize() <= 0) - { - throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$ - } - - try - { - pdfDataSource = TempDirHelper.placePdfIntoTempDir(file_upload_fi.getInputStream(), doc_file_name); - } - catch (IOException e) - { - throw new PDFDocumentException(201, "Couldn't store the file in the temp dir.", e); - } - } else { - log.debug("Processing free text."); - try { - boolean pdfaEnabled = pdfa != null && "true".equalsIgnoreCase(pdfa.getString()); - byte[] freeTextPDF = IText.createPDF(freeText.getString("UTF-8"), pdfaEnabled); - - pdfDataSource = new ByteArrayPdfDataSourceImpl(freeTextPDF); - doc_file_name = IText.DEFAULT_FILENAME; - } catch (DocumentException e) { - throw new PDFDocumentException(201, "Unable to create PDF document.", e); - } catch (IOException e) { - throw new PDFDocumentException(201, "Unable to create PDF document.", e); - } - - } - // byte[] pdf = file_upload_fi.get(); - - UploadedData ud = new UploadedData(); - - ud.preview = preview; - ud.download_inline = download_inline; - ud.sig_type = sig_type; - ud.sig_app = sig_app; - ud.sig_mode = mode; - ud.file_name = doc_file_name; - ud.pdfDataSource = pdfDataSource; - - return ud; - } - - - - - - public static void prepareDispatchToErrorPage(PresentableException pe, HttpServletRequest request) - { - request.setAttribute("PresentableException", pe); -// if (pe instanceof ErrorCodeException) -// { - request.setAttribute("error", "Fehler " + pe.getErrorCode()); - - String cause = ErrorCodeHelper.getMessageForErrorCode(pe.getErrorCode()); - - if (pe instanceof ExternalErrorException) - { - ExternalErrorException eee = (ExternalErrorException) pe; - cause = eee.getExternalErrorCode() + ": " + eee.getExternalErrorMessage(); - } - request.setAttribute("cause", cause); - - if (pe.getErrorCode() == ErrorCode.PLACEHOLDER_EXCEPTION) - { - PlaceholderException phe = null; - if (pe instanceof PlaceholderException) - { - phe = (PlaceholderException) pe; - } - else - { - phe = (PlaceholderException) pe.getCause(); - } - - request.setAttribute("cause", "Der Platzhalter des Feldes " + phe.getField() + " ist um " + phe.getMissing() + " Bytes zu kurz. " + cause); - } -// } -// else -// { -// request.setAttribute("error", "PresentableException"); -// request.setAttribute("cause", pe.toString()); -// } - } - - public void dispatchToPreview(String document_text, String connector, String mode, String signature_type, String submit_url, HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException - { - request.setAttribute("document_text", document_text); - request.setAttribute("connector", connector); - request.setAttribute("mode", mode); - request.setAttribute("signature_type", signature_type); - request.setAttribute("submit_url", submit_url); - - dispatch(request, response, "/jsp/signpreview.jsp"); - } - - /** - * Formats the file name so that it is suitable for content disposition. - * - * @param file_name - * The file name. - * @return Returns the formatted file name. - */ - public static String formatFileName(String file_name) - { - File file = new File(file_name); - String file_name_only = file.getName(); - // the file_name contains \\ ==> remove them so Internet Explorer works - // correctly. - return file_name_only; - } - - - - - - // tzefferer: added - public static byte[] toByteArray(InputStream inputStream) throws IOException - { - - if (inputStream == null) - { - return null; - } - - ByteArrayOutputStream out = new ByteArrayOutputStream(8192); - int n; - byte[] buffer = new byte[2048]; - BufferedInputStream bufIn = new BufferedInputStream(inputStream); - try - { - while ((n = bufIn.read(buffer)) != -1) - { - out.write(buffer, 0, n); - } - } - finally - { - if (bufIn != null) - { - bufIn.close(); - } - } - return out.toByteArray(); - } - - // end add - - protected static class UploadedData - { - protected boolean preview = false; - - protected boolean download_inline = false; - - protected String sig_type = null; - - protected String sig_app = null; - - protected String sig_mode = null; - - protected String file_name = null; - - protected PdfDataSource pdfDataSource = null; - // protected byte[] pdf = null; - } -} \ No newline at end of file diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java deleted file mode 100644 index f0d3d3d..0000000 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java +++ /dev/null @@ -1,56 +0,0 @@ -package at.knowcenter.wag.egov.egiz.web.servlets; - -import java.io.IOException; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import at.knowcenter.wag.egov.egiz.web.FormFields; - -public class UpdateFormServlet extends HttpServlet { - - private static final long serialVersionUID = 1L; - - public static final String UPLOADFORM_SIGNATURE_TYPE_KEY = "signupload.jsp:signatureType"; - public static final String UPLOADFORM_SIGNATURE_MODE_KEY = "signupload.jsp:signatureMode"; - public static final String UPLOADFORM_SIGNATURE_DEVICE_KEY = "signupload.jsp:signatureKey"; - public static final String UPLOADFORM_PDFA_KEY = "signupload.jsp:pdfaKey"; - public static final String UPLOADFORM_SOURCE_KEY = "signupload.jsp:sourceKey"; - public static final String UPLOADFORM_FREETEXT_KEY = "signupload.jsp:freeTextKey"; - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - this.doPost(request, response); - } - - public static void updateSession(HttpServletRequest request) { - String mode = request.getParameter(FormFields.FIELD_MODE); - String device = request.getParameter(FormFields.FIELD_CONNECTOR); - String type = request.getParameter(FormFields.FIELD_SIGNATURE_TYPE); - String pdfa = request.getParameter(FormFields.FIELD_PDFA_ENABLED); - String source = request.getParameter(FormFields.FIELD_SOURCE); - String freeText = request.getParameter(FormFields.FIELD_FREETEXT); - - HttpSession session = request.getSession(); - session.setAttribute(UPLOADFORM_SIGNATURE_DEVICE_KEY, device); - session.setAttribute(UPLOADFORM_SIGNATURE_MODE_KEY, mode); - session.setAttribute(UPLOADFORM_SIGNATURE_TYPE_KEY, type); - session.setAttribute(UPLOADFORM_PDFA_KEY, pdfa); - session.setAttribute(UPLOADFORM_SOURCE_KEY, source); - if (freeText != null) { - session.setAttribute(UPLOADFORM_FREETEXT_KEY, freeText); - } - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - updateSession(request); - - RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/signupload.jsp"); - dispatcher.forward(request, response); -// response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/jsp/signupload.jsp")); - } - -} diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java deleted file mode 100644 index 11f9db4..0000000 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java +++ /dev/null @@ -1,723 +0,0 @@ -/** - * Copyright (c) 2006 by Know-Center, Graz, Austria - * - * This software is the confidential and proprietary information of Know-Center, - * Graz, Austria. You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Know-Center. - * - * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF - * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR - * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY - * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. - * - * $Id: VerifyPreview.java,v 1.4 2006/10/11 07:39:13 wprinz Exp $ - */ -package at.knowcenter.wag.egov.egiz.web.servlets; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.pdfas.framework.input.TextDataSource; -import at.gv.egiz.pdfas.utils.StreamUtils; -import at.gv.egiz.pdfas.utils.WebUtils; -import at.gv.egiz.pdfas.web.VerifySessionInformation; -import at.gv.egiz.pdfas.web.helper.SessionHelper; -import at.gv.egiz.pdfas.web.helper.TempDirHelper; -import at.knowcenter.wag.egov.egiz.PdfAS; -import at.knowcenter.wag.egov.egiz.PdfASID; -import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; -import at.knowcenter.wag.egov.egiz.exceptions.InvalidIDException; -import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; -import at.knowcenter.wag.egov.egiz.exceptions.SignatureException; -import at.knowcenter.wag.egov.egiz.pdf.BinarySignatureHolder; -import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder; -import at.knowcenter.wag.egov.egiz.pdf.TextualSignatureHolder; -import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory; -import at.knowcenter.wag.egov.egiz.sig.SignatureEntry; -import at.knowcenter.wag.egov.egiz.sig.SignatureObject; -import at.knowcenter.wag.egov.egiz.sig.SignatureTypes; -import at.knowcenter.wag.egov.egiz.web.FormFields; -import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper; - -/** - * @author wprinz - */ -public class VerifyPreviewServlet extends HttpServlet -{ - /** - * SVUID. - */ - private static final long serialVersionUID = 6954343542890239109L; - - /** - * The logger. - */ - private static final Log logger_ = LogFactory.getLog(VerifyPreviewServlet.class); - - protected void dispatch(HttpServletRequest request, - HttpServletResponse response, String resource) throws ServletException, IOException - { - response.setContentType("text/html"); - response.setCharacterEncoding("UTF-8"); - - RequestDispatcher disp = getServletContext().getRequestDispatcher(resource); - disp.forward(request, response); - } - - protected void dispatchToPreview(HttpServletRequest request, HttpServletResponse response, int verify_which)throws ServletException, IOException - { - request.setAttribute(FormFields.FIELD_VERIFY_WHICH, new Integer(verify_which)); - request.setAttribute("btlurl", formBackToListURL(request, response)); - dispatch(request, response, "/jsp/verifypreview.jsp"); - - } - - protected void dispatchToDataOk(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException - { - request.setAttribute("btlurl", formBackToListURL(request, response)); - dispatch(request, response, "/jsp/dataok.jsp"); - } - - protected String formBackToListURL(HttpServletRequest request, HttpServletResponse response) throws MalformedURLException - { - URL btlURL = new URL(LocalRequestHelper.getLocalContextAddress(request, response) + "/jsp/verifylist.jsp"); - String backToListURL = response.encodeURL(btlURL.toString()); - - return backToListURL; - } - - protected static String generateNamePrefix(int num) - { - return SIG_INPUT_PREFIX + num + "_"; - } - - // public static void formatPreview(List signature_holders, String connector, - // HttpServletRequest request, HttpServletResponse response) throws - // ServletException, IOException - // { - // response.setContentType("text/html"); - // response.setCharacterEncoding("UTF-8"); - // - // PrintWriter writer = response.getWriter(); - // - // writer.println(""); - // writer.println(""); - // writer.println(""); - // writer.println(""); - // writer.println("PDF-AS Amtssignaturen Vorschau"); - // writer.println(""); - // - // writer.println(""); - // - // writer.println(""); - // - // writer.println(""); - // writer.println("
"); - // - // writer.println("

PDF-AS Amtssignaturen

"); - // - // writer.println("
"); - // writer.println("
Vorschau: Dokument Prüfen
"); - // writer.println("
"); - // writer.println("
"); - // - // // writer.println(""); - // writer.println(""); - // - // // if (mode.equals(FormFields.VALUE_MODE_TEXTUAL)) - // // { - // // String raw_document_text = ((SignatureHolder) - // // signature_holders.get(0)).signed_text; - // // writer.println(""); - // // writer.println("
"); - // // } - // - // if (signature_holders.size() == 1) - // { - // writer.println("
Rekonstruktion der Signaturmarke:
"); - // } - // else - // { - // writer.println("
Rekonstruktion der Signaturmarken:
"); - // } - // - // // this special
is only needed because internet explorer doesn't - // // format the width of the - // // tables right when the div is not given. - // // probably this is because the table then tries to calculate the relative - // // width from the surrounding form object. - // writer.println("
"); - // int num = 0; - // Iterator it = signature_holders.iterator(); - // while (it.hasNext()) - // { - // SignatureHolder signature_holder = (SignatureHolder) it.next(); - // - // String name_prefix = generateNamePrefix(num); - // - // String input_key = name_prefix + FormFields.FIELD_RAW_DOCUMENT_TEXT; - // if (signature_holder.signature_object.isBinary()) - // { - // writer.println(""); - // } - // else - // { - // writer.println("
"); - // writer.println(""); - // writer.println("
"); - // } - // - // String html = renderRequiredKeys(signature_holder.signature_object, - // name_prefix, false); - // writer.println(html); - // - // writer.println(""); - // - // num++; - // } - // writer.println("
"); - // - // writer.println("");// + - // // FormFields.VALUE_VERIFY_WHICH_ALL - // // + - // // "\" - // // />"); - // writer.println(""); - // - // writer.println("
"); - // writer.println(""); - // writer.println("
"); - // - // writer.println("zurück"); - // - // writer.println("
"); - // writer.println(""); - // - // writer.println(""); - // - // } - - public static String renderRequiredKeysJavaScript( - SignatureObject signature_object, String name_prefix) - { - StringWriter sw = new StringWriter(); - PrintWriter writer = new PrintWriter(sw); - - String[] rkeys = SignatureTypes.REQUIRED_SIG_KEYS; - - for (int key_idx = 0; key_idx < rkeys.length; key_idx++) - { - String key = rkeys[key_idx]; - SignatureEntry entry = signature_object.getSigEntry(key); - String value = entry.getValue(); - if (SignatureTypes.SIG_ID.equals(key) && value == null) - { - continue; - } - if (SignatureTypes.SIG_KZ.equals(key) && value == null) - { - continue; - } - - value = value.replaceAll("\\s", " "); - value = value.replaceAll("\\\"", "\\\""); - - String input_key = name_prefix + key; - - writer.println(" document.submitform." + input_key + ".value = \"" + value + "\";"); - } - - return sw.toString(); - } - - public static String renderRequiredKeys(SignatureObject signature_object, - String name_prefix, boolean write_value) - { - StringWriter sw = new StringWriter(); - PrintWriter writer = new PrintWriter(sw); - - writer.println(""); - - String[] rkeys = SignatureTypes.REQUIRED_SIG_KEYS; - - for (int key_idx = 0; key_idx < rkeys.length; key_idx++) - { - String key = rkeys[key_idx]; - SignatureEntry entry = signature_object.getSigEntry(key); - String caption = entry.getCaption(); - String value = entry.getValue(); - if (SignatureTypes.SIG_ID.equals(key) && value == null) - { - continue; - } - if (SignatureTypes.SIG_KZ.equals(key) && value == null) - { - continue; - } - - writer.println(" "); - writer.println(" "); - writer.println(" "); - writer.println(" "); - } - writer.println("
" + caption + ":"); - - value = value.replaceAll("\\s", " "); - value = value.replaceAll("\\\"", "\\\""); - - String input_key = name_prefix + key; - writer.println(" "); - - writer.println("
"); - - return sw.toString(); - } - - public static String renderRequiredKeysText(SignatureObject signature_object) - { - StringWriter sw = new StringWriter(); - PrintWriter writer = new PrintWriter(sw); - - writer.println(""); - - // just render useful information - // FIXME: NPE in case SignatureTypes.SIG_NAME is not used (in case of friendly signer name) - // Problem: SignatureTypes.SIG_NAME is defined as Signer-RFC2253Name, but there is not certain - // key for friendly name (e.g. SIG_SUBJECT or SIG_FOO), therefore we do not know which key contains - // the friendly signer name - - // workaround: include "SIG_SUBJECT" since it is usually used - String[] rkeys = { SignatureTypes.SIG_NAME, "SIG_SUBJECT", SignatureTypes.SIG_DATE, SignatureTypes.SIG_ISSUER, SignatureTypes.SIG_NUMBER}; // SignatureTypes.REQUIRED_SIG_KEYS; - - for (int key_idx = 0; key_idx < rkeys.length; key_idx++) - { - String key = rkeys[key_idx]; - SignatureEntry entry = signature_object.getSigEntry(key); - if (entry == null) { - continue; - } - String caption = entry.getCaption(); - String value = entry.getValue(); - if (caption == null || value == null) { - continue; - } - -// if (SignatureTypes.SIG_KZ.equals(key) && value == null) -// { -// continue; -// } - - writer.println(" "); - writer.println(" "); - writer.println(" "); - writer.println(" "); - } - writer.println("
" + caption + ":"); - - value = value.replaceAll("\\s", " "); - value = value.replaceAll("\\\"", "\\\""); - - writer.println(" " + value); - - writer.println("
"); - - return sw.toString(); - } - - protected void dispatchToResults(List results, HttpServletRequest request, - HttpServletResponse response, boolean backbutton, String backToListURL) throws ServletException, IOException - { - request.setAttribute("results", results); - request.setAttribute("backbutton", backbutton ? "true" : "false"); - request.setAttribute("btlurl", backToListURL); - dispatch(request, response, "/jsp/results.jsp"); - } - - // public static void formatVerifyResults(List results, - // HttpServletResponse response) throws IOException, SettingNotFoundException - // { - // response.setContentType("text/html"); - // response.setCharacterEncoding("UTF-8"); - // - // PrintWriter writer = response.getWriter(); - // - // writer.println(""); - // writer.println(""); - // writer.println(""); - // writer.println(""); - // writer.println("PDF-AS Amtssignaturen Resultat"); - // writer.println(""); - // writer.println(""); - // - // writer.println(""); - // writer.println("
"); - // - // writer.println("

PDF-AS Amtssignaturen

"); - // - // writer.println("
"); - // writer.println("
Resultat
"); - // writer.println("
"); - // - // Iterator it = results.iterator(); - // while (it.hasNext()) - // { - // SignatureResponse result = (SignatureResponse) it.next(); - // formatSignatureResponse(result, writer); - // - // if (it.hasNext()) - // { - // writer.println("
"); - // } - // } - // - // writer.println("
"); - // writer.println("
"); - // - // writer.println("zurück"); - // - // writer.println("
"); - // writer.println(""); - // - // writer.println(""); - // - // } - // - // public static void formatSignatureResponse(SignatureResponse result, - // PrintWriter writer) throws SettingNotFoundException - // { - // writer.println("
Zertifikat"); - // writer.println(""); - // writer.println(" "); - // writer.println(" "); - // writer.println(" "); - // List public_properties = result.getPublicProperties(); - // Iterator it = public_properties.iterator(); - // while (it.hasNext()) - // { - // String public_property = (String) it.next(); - // writer.println(" "); - // } - // - // writer.println(" "); - // - // writer.println("
Signator:" + - // result.getX509SubjectName() + "
Aussteller:" + - // result.getX509IssuerName() + "
Seriennummer:" + - // result.getX509SerialNumber() + "
Eigenschaft:" + - // public_property + "
Zertifikat:" + result.getCertificateCheckInfo() - // + "
"); - // writer.println("
"); - // writer.println("
Signatur-Check"); - // writer.println("
" + result.getSignatureCheckInfo() + "
"); - // writer.println("
"); - // writer.println("
Manifest-Check"); - // writer.println("
" + - // result.getSignatureManifestCheckInfo() + "
"); - // writer.println("
"); - // } - - /** - * Form field name prefix for signature table names - */ - public static final String SIG_INPUT_PREFIX = "sig_inp_"; - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - try - { - Object sessionObject = SessionHelper.getSession(request); - - VerifySessionInformation si = (VerifySessionInformation)sessionObject; - - - int verify_which = -1; - boolean preview = false; - - { - String str_verify_which = request.getParameter(FormFields.FIELD_VERIFY_WHICH); - logger_.debug("verify_which = " + str_verify_which); - if (str_verify_which.equals(FormFields.VALUE_VERIFY_WHICH_ALL)) - { - verify_which = -1; - } - else - { - verify_which = Integer.parseInt(str_verify_which); - } - logger_.debug("verify_which = " + verify_which); - } - - { - String preview_string = request.getParameter(FormFields.FIELD_PREVIEW); - if (preview_string.equals("true")) - { - preview = true; - } - } - - List holders_to_verify = si.signature_holders; - - if (verify_which >= 0) - { - if (verify_which >= si.signature_holders.size()) - { - throw new SignatureException(312, "The selected signature to be verified doesn't exist."); - } - - SignatureHolder holder = (SignatureHolder) si.signature_holders.get(verify_which); -// si.current_operation = verify_which; - holders_to_verify = new ArrayList(); - holders_to_verify.add(holder); - - if (preview == true) - { - if (holder instanceof BinarySignatureHolder) - { - BinarySignatureHolder binary_holder = (BinarySignatureHolder) holder; - response.setContentType("application/pdf"); - StreamUtils.writeInputStreamToOutputStream(binary_holder.getSignedPdf().createInputStream(), response.getOutputStream()); -// response.getOutputStream().write(binary_holder.getSignedPdf(), 0, binary_holder.getSignedPdfLength()); - } - else - // if (holder.getSignatureObject().isTextual()) - { - // formatPreview(holders_to_verify, si.connector, request, - // response); -// request.setAttribute(FormFields.FIELD_VERIFY_WHICH, new Integer(verify_which)); - - dispatchToPreview(request, response, verify_which); - } - - return; - } - - } - - if (ConnectorFactory.isConnectorLocal(si.connector)) - { - // what is this for? si.signature_holders must not be modified after extraction - // TODO this seems to be buggy bug fixing - remove -// List temp_holder = new ArrayList(si.signature_holders); -// -// si.copy_of_signature_holders = temp_holder; -// si.signature_holders = holders_to_verify; - - String dispatch_to = LocalRequestHelper.processLocalVerify(si, holders_to_verify, request, response); - dispatch(request, response, dispatch_to); - - return; - } - - String host = request.getServerName(); -// URL loc_ref_URL = new URL(WebUtils.addJSessionID(LocalRequestHelper.getLocalContextAddress(request, response) + "/RetrieveSignatureData", request)); - URL loc_ref_URL = new URL(WebUtils.buildRetrieveSignatureDataURL(request, response)); - String loc_ref_url = response.encodeURL(loc_ref_URL.toString()); - - List results = PdfAS.verifySignatureHoldersWeb(holders_to_verify, si, loc_ref_url); - boolean backbutton = true; - if (verify_which >= 0) - { - backbutton = false; - } - URL btlURL = new URL(LocalRequestHelper.getLocalContextAddress(request, response) + "/jsp/verifylist.jsp"); - String backToListURL = response.encodeURL(btlURL.toString()); - dispatchToResults(results, request, response, backbutton, backToListURL); - - } - catch (PresentableException e) - { - logger_.error(e.getMessage(), e); - SignServlet.prepareDispatchToErrorPage(e, request); - dispatch(request, response, "/jsp/error.jsp"); - } - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - DiskFileItemFactory fif = new DiskFileItemFactory(); - fif.setRepository(SettingsReader.getTemporaryDirectory()); - ServletFileUpload sfu = new ServletFileUpload(fif); - - try - { - Object sessionObject = SessionHelper.getSession(request); - - VerifySessionInformation si = (VerifySessionInformation)sessionObject; - - - String text_to_be_verified = null; - SignatureObject signature_object = new SignatureObject(); - - String default_type = SettingsReader.getInstance().getValueFromKey(SignatureTypes.DEFAULT_TYPE); - signature_object.setSigType(default_type); - signature_object.initByType(); - - int verify_which = -1; - boolean verify = false; - - List items = sfu.parseRequest(request); - - Iterator it = items.iterator(); - while (it.hasNext()) - { - FileItem item = (FileItem) it.next(); - logger_.debug("item = " + item.getFieldName()); - - if (item.getFieldName().equals(FormFields.FIELD_RAW_DOCUMENT_TEXT)) - { - String raw_document_text = item.getString("UTF-8"); - text_to_be_verified = PdfAS.normalizeText(raw_document_text); - continue; - } - - if (item.getFieldName().equals(FormFields.FIELD_VERIFY_WHICH)) - { - String which_str = item.getString("UTF-8"); - verify_which = Integer.parseInt(which_str); - continue; - } - - if (item.getFieldName().equals("verify")) - { - if (item.getString("UTF-8").equals("true")) - { - verify = true; - } - continue; - } - - String key = item.getFieldName(); - String value = item.getString("UTF-8"); - - signature_object.setSigValue(key, value); - logger_.debug("sig_obj_number" + key + " = " + value); - } - - SignatureHolder old_holder = (SignatureHolder) si.signature_holders.get(verify_which); - TempDirHelper.deleteDataSourceIfFileBased(old_holder.getDataSource()); - - TextDataSource tds = TempDirHelper.placeTextIntoTempDir(text_to_be_verified, "_previewholder.utf8.txt"); - SignatureHolder new_holder = new TextualSignatureHolder(tds, signature_object); - - si.signature_holders.set(verify_which, new_holder); - - if (verify == false) - { - dispatchToDataOk(request, response); - return; - } - - List holders_to_verify = si.signature_holders; - - if (verify_which >= 0) - { - if (verify_which >= si.signature_holders.size()) - { - throw new SignatureException(312, "The selected signature to be verified doesn't exist."); - } - - SignatureHolder holder = (SignatureHolder) si.signature_holders.get(verify_which); - holders_to_verify = new ArrayList(); - holders_to_verify.add(holder); - } - - if (ConnectorFactory.isConnectorLocal(si.connector)) - { - String dispatch_to = LocalRequestHelper.processLocalVerify(si, holders_to_verify, request, response); - dispatch(request, response, dispatch_to); - return; - } - - String host = request.getServerName(); -// URL loc_ref_URL = new URL(WebUtils.addJSessionID(LocalRequestHelper.getLocalContextAddress(request, response) + "/RetrieveSignatureData", request)); - URL loc_ref_URL = new URL(WebUtils.buildRetrieveSignatureDataURL(request, response)); - String loc_ref_url = response.encodeURL(loc_ref_URL.toString()); - - List results = PdfAS.verifySignatureHoldersWeb(holders_to_verify, si, loc_ref_url); - - URL btlURL = new URL(LocalRequestHelper.getLocalContextAddress(request, response) + "/jsp/verifylist.jsp"); - String backToListURL = response.encodeURL(btlURL.toString()); - dispatchToResults(results, request, response, true, backToListURL); - } - catch (FileUploadException e) - { - request.setAttribute("error", "verifypreviewservlet.error"); - request.setAttribute("cause", "verifypreviewservlet.cause"); - request.setAttribute("resourcebundle", Boolean.TRUE); - dispatch(request, response, "/jsp/error.jsp"); - } - catch (PresentableException e) - { - logger_.error(e.getMessage(), e); - SignServlet.prepareDispatchToErrorPage(e, request); - dispatch(request, response, "/jsp/error.jsp"); - } - } -} diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java deleted file mode 100644 index 71324fe..0000000 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java +++ /dev/null @@ -1,466 +0,0 @@ -/* - * Copyright (c) 2006 by Know-Center, Graz, Austria - * - * This software is the confidential and proprietary information of Know-Center, - * Graz, Austria. You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Know-Center. - * - * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF - * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR - * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY - * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. - * - * $Id: Verify.java,v 1.7 2006/10/11 07:39:13 wprinz Exp $ - */ -package at.knowcenter.wag.egov.egiz.web.servlets; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.pdfas.exceptions.ErrorCode; -import at.gv.egiz.pdfas.framework.DataSourceHolder; -import at.gv.egiz.pdfas.framework.config.SettingsHelper; -import at.gv.egiz.pdfas.framework.input.DataSource; -import at.gv.egiz.pdfas.framework.input.ExtractionStage; -import at.gv.egiz.pdfas.framework.input.PdfDataSource; -import at.gv.egiz.pdfas.framework.input.TextDataSource; -import at.gv.egiz.pdfas.framework.vfilter.VerificationFilterParameters; -import at.gv.egiz.pdfas.utils.WebUtils; -import at.gv.egiz.pdfas.web.VerifySessionInformation; -import at.gv.egiz.pdfas.web.helper.TempDirHelper; -import at.knowcenter.wag.egov.egiz.PdfAS; -import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; -import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException; -import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; -import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException; -import at.knowcenter.wag.egov.egiz.pdf.NoSignatureHolder; -import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder; -import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory; -import at.knowcenter.wag.egov.egiz.sig.SignatureResponse; -import at.knowcenter.wag.egov.egiz.web.FormFields; -import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper; -import at.knowcenter.wag.egov.egiz.web.SessionAttributes; - -/** - * This method is the verify servlet for the pdf-as web application. It takes - * get and post requests fill out jsp templates and give the user feedback about - * the results of the verify process. - * - * @author wlackner - * @author wprinz - */ -public class VerifyServlet extends HttpServlet -{ - - /** - * SVUID. - */ - private static final long serialVersionUID = 309198792358636766L; - - /** - * The log. - */ - private static Log log = LogFactory.getLog(SignServlet.class); - - protected void dispatch(HttpServletRequest request, HttpServletResponse response, String resource) throws ServletException, IOException - { - response.setContentType("text/html"); //$NON-NLS-1$ - response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$ - - RequestDispatcher disp = getServletContext().getRequestDispatcher(resource); - disp.forward(request, response); - } - - protected void dispatchToResults(List results, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - request.setAttribute("results", results); //$NON-NLS-1$ - dispatch(request, response, "/jsp/results.jsp"); //$NON-NLS-1$ - } - - /** - * Processes the verify upload. - * - * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, - * javax.servlet.http.HttpServletResponse) - */ - public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - // for performance measurement - long startTime = 0; - long fileSize = 0; - if (log.isInfoEnabled()) { - startTime = System.currentTimeMillis(); - } - try - { - UploadedData ud = retrieveUploadedDataFromRequest(request); - - VerifySessionInformation si = new VerifySessionInformation(); - si.connector = ud.sig_app; - si.application = "verify"; - si.mode = null; - si.inputDataSource = ud.dataSource; - si.type = null; -// si.user_name = null; -// si.user_password = null; - - // List signature_holders = extractSignatureHoldersFromFile(ud.file_name, - // ud.file_data); - List signature_holders = extractSignatureHolders(new DataSourceHolder(ud.dataSource)); - - TempDirHelper.storeTextSignatureHoldersIfApplicable(signature_holders, "_textholder.utf8.txt"); - - si.signature_holders = signature_holders; - - request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si); - - if (ud.preview) - { - dispatch(request, response, "/jsp/verifylist.jsp"); - // VerifyPreview.formatPreview(signature_holders, connector, request, - // response); - } - else - { - if (ConnectorFactory.isConnectorLocal(si.connector)) - { - String dispatch_to = LocalRequestHelper.processLocalVerify(si, si.signature_holders, request, response); - - dispatch(request, response, dispatch_to); - return; - } - - String host = request.getServerName(); - // TODO still required for old communication with MOA-SS/SP -// URL loc_ref_URL = new URL(WebUtils.addJSessionID(LocalRequestHelper.getLocalContextAddress(request, response) + "/RetrieveSignatureData", request)); - URL loc_ref_URL = new URL(WebUtils.buildRetrieveSignatureDataURL(request, response)); - String loc_ref_url = response.encodeURL(loc_ref_URL.toString()); - - List results = PdfAS.verifySignatureHoldersWeb(signature_holders, si, loc_ref_url); - dispatchToResults(results, request, response); - - // for performance measurement - if (log.isInfoEnabled()) { - long endTime = System.currentTimeMillis(); - String toReport = "VERIFY;"+ ud.file_name + ";"+ 0 + ";" + (endTime - startTime) + ";" + debugVerifyResults(results); - log.info(toReport); - } - - } - - } - catch (FileUploadException e) - { - request.setAttribute("error", "Fehler beim Upload der Daten"); - request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten."); - dispatch(request, response, "/jsp/error_verify.jsp"); - } - catch (PresentableException e) - { - log.error(e.getMessage(), e); - SignServlet.prepareDispatchToErrorPage(e, request); - dispatch(request, response, "/jsp/error_verify.jsp"); - } - - } - - protected UploadedData retrieveUploadedDataFromRequest(HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException - { - DiskFileItemFactory fif = new DiskFileItemFactory(); - fif.setRepository(SettingsReader.getTemporaryDirectory()); - ServletFileUpload sfu = new ServletFileUpload(fif); - - List items = sfu.parseRequest(request); - - FileItem upload_fi = null; - FileItem connector_fi = null; - // FileItem mode_fi = null; - FileItem preview_fi = null; - - String characterEncoding = request.getCharacterEncoding(); - log.debug("request character encoding = " + characterEncoding); - - { - Iterator it = items.iterator(); - while (it.hasNext()) - { - FileItem item = (FileItem) it.next(); - log.debug("item = " + item.getFieldName()); //$NON-NLS-1$ - - if (item.isFormField()) - { - String item_string = item.getString("UTF-8"); //$NON-NLS-1$ - log.debug(" form field string = " + item_string); //$NON-NLS-1$ - } - else - { - log.debug(" filename = " + item.getName()); //$NON-NLS-1$ - log.debug(" filesize = " + item.getSize()); //$NON-NLS-1$ - } - - if (item.getFieldName().equals(FormFields.FIELD_UPLOAD)) - { - upload_fi = item; - continue; - } - - if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR)) - { - connector_fi = item; - continue; - } - - // if (item.getFieldName().equals(FormFields.FIELD_MODE)) - // { - // mode_fi = item; - // continue; - // } - - if (item.getFieldName().equals(FormFields.FIELD_PREVIEW)) - { - preview_fi = item; - continue; - } - - throw new ServletException("unrecognized POST data."); //$NON-NLS-1$ - } - } - - if (upload_fi == null || connector_fi == null || /* mode_fi == null || */preview_fi == null) - { - throw new ServletException("Unsufficient data provided in request."); //$NON-NLS-1$ - } - - String connector = connector_fi.getString("UTF-8"); //$NON-NLS-1$ - - // String mode = mode_fi.getString("UTF-8"); - // if (!mode.equals(FormFields.VALUE_MODE_BINARY) && - // !mode.equals(FormFields.VALUE_MODE_TEXTUAL)) - // { - // throw new ServletException("The mode '" + mode + "' is unrecognized."); - // } - - String preview_str = preview_fi.getString("UTF-8"); //$NON-NLS-1$ - if (!preview_str.equals(FormFields.VALUE_TRUE) && !preview_str.equals(FormFields.VALUE_FALSE)) - { - throw new ServletException("The preview '" + preview_str + "' is unrecognized."); //$NON-NLS-1$//$NON-NLS-2$ - } - boolean preview = false; - if (preview_str.equals(FormFields.VALUE_TRUE)) - { - preview = true; - } - - // process the request - DataSource dataSource = convertUploadToDataSource(upload_fi); - - UploadedData ud = new UploadedData(); - ud.preview = preview; - ud.sig_app = connector; - ud.file_name = upload_fi.getName(); - ud.dataSource = dataSource; - // ud.file_data = document_bytes; - - return ud; - } - - protected DataSource convertUploadToDataSource(FileItem upload_fi) throws PDFDocumentException - { - log.debug("file content type =" + upload_fi.getContentType()); //$NON-NLS-1$ - log.debug("file size = " + upload_fi.getSize()); //$NON-NLS-1$ - if (upload_fi.getSize() <= 0) - { - throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$ - } - - - // TR: do not check MIME-type of incoming file - might vary depending on the browser used - if ((upload_fi.getContentType() != null ) && ((upload_fi.getContentType().startsWith("application/pdf") || upload_fi.getContentType().startsWith("application/x-download") ))) - { - try - { - String fileNameSuffix = TempDirHelper.extractFileNameSuffix(upload_fi.getName()); - PdfDataSource pdfDataSource = TempDirHelper.placePdfIntoTempDir(upload_fi.getInputStream(), fileNameSuffix); - return pdfDataSource; - } - catch (IOException e) - { - throw new PDFDocumentException(201, "The document could not be placed in the temp dir.", e); //$NON-NLS-1$ - } - // byte[] document_bytes = upload_fi.get(); - } - - try - { - String fileNameSuffix = TempDirHelper.extractFileNameSuffix(upload_fi.getName()); - String text = new String(upload_fi.get(), "UTF-8"); //$NON-NLS-1$ - TextDataSource textDataSource = TempDirHelper.placeTextIntoTempDir(text, fileNameSuffix); - return textDataSource; - } - catch (IOException e) - { - throw new PDFDocumentException(201, e); - } - } - - protected List extractSignatureHolders(DataSourceHolder dataSource) throws PresentableException - { - VerificationFilterParameters parameters = SettingsHelper.readVerificationFilterParametersFromSettings(); - - ExtractionStage es = new ExtractionStage(); - List signature_holders = es.extractSignatureHolders(dataSource, parameters); - - // filter out NoSignatureHolders that are possibly present due to the direct call method extractSignatureHolders() - List filtered_signature_holders = new ArrayList(); - Iterator it = signature_holders.iterator(); - while(it.hasNext()) { - SignatureHolder current = (SignatureHolder) it.next(); - if(!(current instanceof NoSignatureHolder)) { - filtered_signature_holders.add(current); - } - } - - if (filtered_signature_holders.size() == 0) - { - throw new PDFDocumentException(ErrorCode.DOCUMENT_NOT_SIGNED, "PDF document not signed."); //$NON-NLS-1$ - } - - return filtered_signature_holders; - } - - // TODO obsolete method - remove - // protected List extractSignatureHoldersFromFile(String file_name, byte[] - // data) throws UnsupportedEncodingException, PresentableException - // { - // VerificationFilterParameters parameters = new - // VerificationFilterParametersImpl(false, false, true); - // ExtractionStage es = new ExtractionStage(); - // // VerificationFilter vf = new VerificationFilter(); - // List signature_holders = null; - // - // String extension = extractExtension(file_name); - // - // String raw_text = null; - // if (file_name == null || (extension != null && extension.equals("txt"))) - // //$NON-NLS-1$ - // { - // raw_text = new String(data, "UTF-8"); //$NON-NLS-1$ - // - // signature_holders = es.extractSignatureHolders(new - // TextDataSourceImpl(raw_text), parameters); - // // signature_holders = vf.extractSignaturesFromPlainText(raw_text); - // } - // else - // { - // signature_holders = es.extractSignatureHolders(new - // ByteArrayPdfDataSourceImpl(data), parameters); - // - // // signature_holders = vf.extractSignaturesFromPdf(data); - // } - // - // if (signature_holders.size() == 0) - // { - // throw new PDFDocumentException(206, "PDF document not signed."); - // //$NON-NLS-1$ - // } - // - // return signature_holders; - // } - - /** - * Extracts the extension from a file name string. - * - *

- * The extension of a file name is whatever text follows the last '.'. - *

- * - * @param file_name - * The file name. - * @return Returns the extension. If the file name ends with the '.', then an - * empty string is returned. If the file name doesn't contain any '.' - * or file_name is null, null is returned. - */ - public static String extractExtension(String file_name) - { - if (file_name == null) - { - return null; - } - - int dot_index = file_name.lastIndexOf('.'); - if (dot_index < 0) - { - return null; - } - return file_name.substring(dot_index + 1); - } - - protected static class UploadedData - { - protected boolean preview = false; - - protected String sig_app = null; - - protected String file_name = null; - - protected DataSource dataSource = null; - // protected byte[] file_data = null; - } - - /** - * Formats the verification results for debugging. Returns 0 if no error occurs or the sum of all error-codes. - * - * @param results - * - * @param writer - * The output sink to write the formatted text to. - * @throws SettingNotFoundException - * Forwarded exception. - */ - protected static int debugVerifyResults(List results) throws SettingNotFoundException - { - int toreturn = 0; - Iterator it = results.iterator(); - while (it.hasNext()) - { - SignatureResponse result = (SignatureResponse) it.next(); - - toreturn += Integer.valueOf(result.getSignatureCheckCode()).intValue(); - } - return toreturn; - } - - public boolean isPDF(byte[] data) { - final byte[] PDF_MAGIC_NUMBER = { (byte) 0x25, (byte) 0x50, (byte) - 0x44, (byte) 0x46 }; // %PDF - if (data == null || data.length < PDF_MAGIC_NUMBER.length) { - return false; - } - byte[] documentHeader = new byte[PDF_MAGIC_NUMBER.length]; - System.arraycopy(data, 0, documentHeader, 0, documentHeader.length); - return Arrays.equals(documentHeader, PDF_MAGIC_NUMBER); - } - - -} \ No newline at end of file -- cgit v1.2.3