diff options
author | rpiazzi <rpiazzi@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2011-09-23 14:46:50 +0000 |
---|---|---|
committer | rpiazzi <rpiazzi@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2011-09-23 14:46:50 +0000 |
commit | 8c30c02e8bb1dcecff3da0c3b1b10f6ecea804fd (patch) | |
tree | d54940c7a2b655c7a918115538b5d4c97d8d283b /pdf-as-web/src/main/java/at/gv/egiz | |
parent | 2a17e86bc15f024291f0a1cdb536db4cac07316a (diff) | |
download | pdf-as-3-8c30c02e8bb1dcecff3da0c3b1b10f6ecea804fd.tar.gz pdf-as-3-8c30c02e8bb1dcecff3da0c3b1b10f6ecea804fd.tar.bz2 pdf-as-3-8c30c02e8bb1dcecff3da0c3b1b10f6ecea804fd.zip |
Added mobile-bku and mobile-test-bku as possible signature devices
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@803 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz')
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/LocalRequestHelper.java | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/LocalRequestHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/LocalRequestHelper.java new file mode 100644 index 0000000..2edaba5 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/LocalRequestHelper.java @@ -0,0 +1,251 @@ +/**
+ * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
+ * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
+ * joint initiative of the Federal Chancellery Austria and Graz University of
+ * Technology.
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://www.osor.eu/eupl/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text
+ * file for details on the various modules and licenses.
+ * The "NOTICE" text file is part of the distribution. Any derivative works
+ * that you distribute must include a readable copy of the "NOTICE" text file.
+ *
+ * $Id: LocalRequestHelper.java,v 1.6 2006/10/31 08:22:04 wprinz Exp $
+ */
+package at.gv.egiz.pdfas.web.helper;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+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.api.commons.Constants;
+import at.gv.egiz.pdfas.api.commons.SignatureInformation;
+import at.gv.egiz.pdfas.api.internal.PdfAsInternal;
+import at.gv.egiz.pdfas.web.CurrentLocalOperation;
+import at.gv.egiz.pdfas.web.LocalRequest;
+import at.gv.egiz.pdfas.web.session.SignSessionInformation;
+import at.gv.egiz.pdfas.web.session.VerifySessionInformation;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorFactoryException;
+import at.knowcenter.wag.egov.egiz.exceptions.NormalizeException;
+import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
+import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
+
+/**
+ * Contains commonly used helper functions for the local request procedure.
+ *
+ * @author wprinz
+ */
+public abstract class LocalRequestHelper
+{
+
+ /**
+ * The logger.
+ */
+ protected static Log logger = LogFactory.getLog(LocalRequestHelper.class);
+
+ /**
+ * The resource of the null request page jsp.
+ */
+ public static final String NULL_REQUEST_PAGE_JSP = "/jsp/null_request_page.jsp";
+
+ /**
+ * The resource of the local connection page jsp.
+ */
+ public static final String LOCAL_CONNECTION_PAGE_JSP = "/jsp/local_connection_page.jsp";
+
+ /**
+ * The resource of the redirect refresh page jsp.
+ */
+ public static final String REDIRECT_REFRESH_PAGE_JSP = "/jsp/redirect_refresh_page.jsp";
+
+ /**
+ * Sets up the local sign procedure.
+ *
+ * @param response
+ * The HttpServletResponse the local request page is written to.
+ * @throws IOException
+ * Forwarded exception.
+ * @throws PresentableException
+ * Forwarded exception.
+ */
+ public static String processLocalSign(PdfAsInternal pdfAsInternal, SignSessionInformation si, HttpServletRequest request, HttpServletResponse response) throws IOException, PresentableException
+ {
+ String host = request.getServerName();
+ URL loc_ref_URL = new URL(WebUtils.buildRetrieveSignatureDataURL(request, response));
+ String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
+
+ String sign_request = pdfAsInternal.prepareLocalSignRequest(si.signParameters, false, loc_ref_url, si.sdi);
+
+ String local_request_url = pdfAsInternal.getLocalServiceAddress(si.type, si.connector);
+ si.localRequest = new LocalRequest(local_request_url, sign_request);
+ si.outputAvailable = false;
+
+ URL data_URL = new URL(request.getScheme(), host, request.getServerPort(), WebUtils.addJSessionID(request.getContextPath() + "/DataURL", request));
+
+ String data_url = response.encodeURL(data_URL.toString());
+ logger.debug("data_url = " + data_url);
+
+ request.setAttribute("local_request_url", local_request_url);
+ request.setAttribute("data_url", data_url);
+
+ return NULL_REQUEST_PAGE_JSP;
+ }
+
+ /**
+ * Sets up the local verify procedure.
+ * @param list
+ *
+ * @param response
+ * The HttpServletResponse the local request page is written to.
+ * @return Returns the JSP location where the calling servlet should dispatch
+ * to.
+ * @throws SignatureException
+ * Forwarded exception.
+ * @throws NormalizeException
+ * Forwarded exception.
+ * @throws IOException
+ * Forwarded exception.
+ * @throws ConnectorFactoryException
+ * Forwarded exception.
+ * @throws SettingsException
+ * @throws ConnectorException
+ */
+ public static String processLocalVerify(PdfAsInternal pdfAsInternal, VerifySessionInformation si, List signaturesToBeverified, HttpServletRequest request, HttpServletResponse response) throws SignatureException, NormalizeException,
+ IOException, ConnectorFactoryException, SettingsException, ConnectorException
+ {
+ si.currentLocalOperation = new CurrentLocalOperation();
+ si.currentLocalOperation.signaturesToBeverified = signaturesToBeverified; // SignatureInformation
+
+ si.currentLocalOperation.requests = new LocalRequest[signaturesToBeverified.size()];
+ si.currentLocalOperation.response_xmls = new String[si.currentLocalOperation.requests.length];
+
+ si.currentLocalOperation.current_operation = 0;
+
+ String host = request.getServerName();
+ URL loc_ref_URL = new URL(WebUtils.buildRetrieveSignatureDataURL(request, response));
+ String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
+
+ for (int i = 0; i < si.currentLocalOperation.requests.length; i++)
+ {
+ SignatureInformation sigInfo = (SignatureInformation) signaturesToBeverified.get(i);
+ String request_string = pdfAsInternal.prepareLocalVerifyRequest(sigInfo, si.connector, si.type, loc_ref_url);
+
+ LocalRequest local_request = new LocalRequest("not-needed", request_string);
+ si.currentLocalOperation.requests[i] = local_request;
+ si.currentLocalOperation.response_xmls[i] = null;
+ }
+
+ String local_request_url = pdfAsInternal.getLocalServiceAddress(si.type, si.connector);
+
+ URL data_URL = new URL(request.getScheme(), host, request.getServerPort(), WebUtils.addJSessionID(request.getContextPath() + "/DataURL", request));
+ String data_url = response.encodeURL(data_URL.toString());
+
+ request.setAttribute("local_request_url", local_request_url);
+ request.setAttribute("data_url", data_url);
+
+ return NULL_REQUEST_PAGE_JSP;
+
+ }
+
+ /**
+ * Formats the OK response from the web application back to the local BKU.
+ *
+ * <p>
+ * As stated in the BKU tutorial, this response must be plain text "<ok/>".
+ * Otherwise BKU will assume a failure.
+ * </p>
+ *
+ * @param response
+ * The HttpServletResponse to answer to.
+ * @throws IOException
+ * Forwarded exception.
+ */
+ protected static void formatBKUOkResponse(HttpServletResponse response) throws IOException
+ {
+ response.setContentType("text/plain");
+ response.setCharacterEncoding("ISO-8859-1");
+
+ response.getWriter().println("<ok/>");
+ }
+
+ public static String makeStringHTMLReady(String input)
+ {
+ String output = input;
+
+ output = output.replaceAll("&", "&");
+ output = output.replaceAll("\"", """);
+ output = output.replaceAll("<", "<");
+ output = output.replaceAll(">", ">");
+ return output;
+ }
+
+ public static String getLocalServerAddress(HttpServletRequest request, HttpServletResponse response)
+ {
+ String host = request.getServerName();
+ URL local_server = null;
+ try
+ {
+ String scheme = request.getScheme();
+ int port = request.getServerPort();
+ if ("http".equalsIgnoreCase(scheme) && port == 80) {
+ local_server = new URL(scheme, host, "/");
+ } else if ("https".equalsIgnoreCase(scheme) && port == 443) {
+ local_server = new URL(scheme, host, "/");
+ } else {
+ local_server = new URL(scheme, host, port, "/");
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ logger.error(e.getMessage(), e);
+ }
+ String loc_server = response.encodeURL(local_server.toString());
+
+ return loc_server;
+ }
+
+ public static String getLocalContextAddress(HttpServletRequest request, HttpServletResponse response) {
+ String serverURL = getLocalServerAddress(request, response);
+ String context = request.getContextPath();
+ if (serverURL.endsWith("/") && context.startsWith("/")) {
+ context = context.substring(1);
+ }
+ return serverURL + context;
+ }
+
+/**
+ * Tells, if the given connector is local.
+ *
+ * @param connector_identifier
+ * The connector.
+ * @return Returns true, if the given connector is local, false otherwise.
+ * @throws ConnectorFactoryException
+ * F.e.
+ */
+ public static boolean isConnectorLocal(String connector_identifier) throws ConnectorFactoryException
+ {
+ //rpiazzi added signature devices mobile and mobiletest
+ return connector_identifier.equals(Constants.SIGNATURE_DEVICE_BKU) || connector_identifier.equals(Constants.SIGNATURE_DEVICE_A1) || connector_identifier.equals(Constants.SIGNATURE_DEVICE_MOC) || connector_identifier.equals(Constants.SIGNATURE_DEVICE_MOBILE) || connector_identifier.equals(Constants.SIGNATURE_DEVICE_MOBILETEST);
+ }
+
+}
|