aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java324
1 files changed, 190 insertions, 134 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java
index fd47cca..8ee09dc 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java
@@ -20,20 +20,26 @@ package at.knowcenter.wag.egov.egiz.web;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
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.impl.input.TextDataSourceImpl;
+import at.gv.egiz.pdfas.framework.input.DataSource;
+import at.gv.egiz.pdfas.web.CurrentLocalOperation;
+import at.gv.egiz.pdfas.web.SignSessionInformation;
+import at.gv.egiz.pdfas.web.VerifySessionInformation;
+import at.knowcenter.wag.egov.egiz.PdfAS;
+import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+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;
+import at.knowcenter.wag.egov.egiz.pdf.BinarySignatureHolder;
import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
import at.knowcenter.wag.egov.egiz.sig.SignatureData;
import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
@@ -42,8 +48,6 @@ 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.SignSignatureObject;
import at.knowcenter.wag.egov.egiz.sig.signatureobject.SignatureObjectHelper;
-import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
-import at.knowcenter.wag.egov.egiz.web.servlets.SignServlet;
/**
* Contains commonly used helper functions for the local request procedure.
@@ -66,8 +70,6 @@ public abstract class LocalRequestHelper
* The resource of the redirect refresh page jsp.
*/
public static final String REDIRECT_REFRESH_PAGE_JSP = "/jsp/redirect_refresh_page.jsp";
-
- private static Log log = LogFactory.getLog(LocalRequestHelper.class);
/**
* Sets up the local sign procedure.
@@ -79,40 +81,35 @@ public abstract class LocalRequestHelper
* @throws PresentableException
* Forwarded exception.
*/
- public static String processLocalSign(SessionInformation si,
- HttpServletRequest request, HttpServletResponse response) throws IOException, PresentableException
+ public static String processLocalSign(SignSessionInformation si, HttpServletRequest request, HttpServletResponse response) throws IOException, PresentableException
{
String host = request.getServerName(); // "129.27.153.77"
URL loc_ref_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
-
+
LocalConnector c = ConnectorChooser.chooseLocalConnectorForSign(si.connector, si.type, loc_ref_url);
- String sign_request = c.prepareSignRequest(si.iui.signature_data);
+ String sign_request = c.prepareSignRequest(si.si.getSignatureData());
- // TODO local URL
- String local_request_url = "http://127.0.0.1:3495/http-security-layer-request";
- si.requests = new LocalRequest[1];
- si.requests[0] = new LocalRequest(local_request_url, sign_request);
- si.current_operation = 0;
- si.response_properties = new Properties[1];
- si.response_properties[0] = null;
+ String local_request_url = getLocalServiceAddress(si.type, si.connector);
+ si.localRequest = new LocalRequest(local_request_url, sign_request);
+ si.outputAvailable = false;
+ si.response_properties = null;
URL data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/DataURL");
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;
-
-
- // TODO make better
+
+ // TODO old code - remove
//
// LocalConnector local_conn = (LocalConnector)
// ConnectorFactory.createConnector(si.connector);
//
//
- // // FIXME refactor WEB
+ // // refactor WEB
// String document_text = "fixme"; //si.iui.document_text;
// String request_string = local_conn.prepareSignRequest(si.user_name,
// document_text, si.type);
@@ -162,39 +159,45 @@ public abstract class LocalRequestHelper
* Forwarded exception.
* @throws ConnectorFactoryException
* Forwarded exception.
+ * @throws SettingsException
+ * @throws ConnectorException
*/
- public static String processLocalVerify(SessionInformation si,
- List holders_to_verify, HttpServletRequest request,
- HttpServletResponse response) throws SignatureException, NormalizeException, IOException, ConnectorFactoryException
+ public static String processLocalVerify(VerifySessionInformation si, List holders_to_verify, HttpServletRequest request, HttpServletResponse response) throws SignatureException, NormalizeException,
+ IOException, ConnectorFactoryException, SettingsException, ConnectorException
{
- si.requests = new LocalRequest[holders_to_verify.size()];
- si.response_properties = new Properties[si.requests.length];
- si.current_operation = 0;
- si.finished = false;
+ si.currentLocalOperation = new CurrentLocalOperation();
+ si.currentLocalOperation.holders_to_be_verified = holders_to_verify;
+
+ si.currentLocalOperation.requests = new LocalRequest[holders_to_verify.size()];
+ si.currentLocalOperation.response_properties = new Properties[si.currentLocalOperation.requests.length];
+
+ si.currentLocalOperation.current_operation = 0;
+// si.finished = false;
String host = request.getServerName();
URL loc_ref_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
- for (int i = 0; i < si.requests.length; i++)
+ for (int i = 0; i < si.currentLocalOperation.requests.length; i++)
{
SignatureHolder holder = (SignatureHolder) holders_to_verify.get(i);
SignatureObject s = holder.getSignatureObject();
- // TODO This whole processing is unnecessary here because only the mime
- // type is used.
- String text_to_be_verified = holder.getSignedText();
- SignatureData sd = null;
- if (holder.getSignatureObject().isBinary())
- {
- byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
- sd = new SignatureDataImpl(data, "application/pdf");
- }
- else
- {
- sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
- }
+ SignatureData sd = PdfAS.convertSignatureHolderToSignatureData(holder);
+// if (holder.getSignatureObject().isBinary())
+// {
+// BinarySignatureHolder bsh = (BinarySignatureHolder) holder;
+// // byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
+// // TODO what about the length of the PDF? is this correct - already deprecated
+// 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");
+// }
SignSignatureObject so = SignatureObjectHelper.convertSignatureObjectToSignSignatureObject(s);
@@ -202,16 +205,15 @@ public abstract class LocalRequestHelper
String request_string = local_conn.prepareVerifyRequest(sd, so);
LocalRequest local_request = new LocalRequest("not-needed", request_string);
- si.requests[i] = local_request;
- si.response_properties[i] = null;
+ si.currentLocalOperation.requests[i] = local_request;
+ si.currentLocalOperation.response_properties[i] = null;
}
-
- // TODO read from config
- String local_request_url = "http://127.0.0.1:3495/http-security-layer-request";
+
+ String local_request_url = getLocalServiceAddress(si.type, si.connector);
URL data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/DataURL");
String data_url = response.encodeURL(data_URL.toString());
-
+
request.setAttribute("local_request_url", local_request_url);
request.setAttribute("data_url", data_url);
@@ -259,75 +261,78 @@ public abstract class LocalRequestHelper
//
// prepareDispatchToLocalConnectionPage(si.requests[0], request, response);
}
-
- /**
- * Sets up the local verify procedure.
- *
- * @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.
- */
- public static String processLocalVerifyForSingleSignature(SessionInformation si,
- List holders_to_verify, HttpServletRequest request,
- HttpServletResponse response) throws SignatureException, NormalizeException, IOException, ConnectorFactoryException
- {
- si.requests = new LocalRequest[1];
- si.response_properties = new Properties[1];
- si.current_operation = 0;
- si.finished = false;
-
- String host = request.getServerName();
- URL loc_ref_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
- String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
-
- SignatureHolder holder = (SignatureHolder) holders_to_verify.get(0);
-
- SignatureObject s = holder.getSignatureObject();
-
- // TODO This whole processing is unnecessary here because only the mime
- // type is used.
- String text_to_be_verified = holder.getSignedText();
- SignatureData sd = null;
-
- if (holder.getSignatureObject().isBinary())
- {
- byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
- sd = new SignatureDataImpl(data, "application/pdf");
- }
- else
- {
- sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
- }
-
- SignSignatureObject so = SignatureObjectHelper.convertSignatureObjectToSignSignatureObject(s);
-
- LocalConnector local_conn = ConnectorChooser.chooseLocalConnectorForVerify(si.connector, s.getKZ(), so.id, si.type, loc_ref_url);
- String request_string = local_conn.prepareVerifyRequest(sd, so);
-
- LocalRequest local_request = new LocalRequest("not-needed", request_string);
- si.requests[0] = local_request;
- si.response_properties[0] = null;
-
- // TODO read from config
- String local_request_url = "http://127.0.0.1:3495/http-security-layer-request";
-
- URL data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/DataURL");
- 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;
- }
+ // what is this for?
+// /**
+// * Sets up the local verify procedure.
+// *
+// * @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 Forwarded exception.
+// */
+// public static String processLocalVerifyForSingleSignature(VerifySessionInformation si, List holders_to_verify, HttpServletRequest request, HttpServletResponse response) throws SignatureException,
+// NormalizeException, IOException, ConnectorFactoryException, SettingsException
+// {
+// si.requests = new LocalRequest[1];
+// si.response_properties = new Properties[1];
+// si.current_operation = 0;
+// si.finished = false;
+//
+// String host = request.getServerName();
+// URL loc_ref_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
+// String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
+//
+// SignatureHolder holder = (SignatureHolder) holders_to_verify.get(0);
+//
+// SignatureObject s = holder.getSignatureObject();
+//
+// // TODO This whole processing is unnecessary here because only the mime type is used. - already deprecated
+// // String text_to_be_verified = holder.getSignedText();
+// SignatureData sd = null;
+//
+// 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");
+// }
+//
+// SignSignatureObject so = SignatureObjectHelper.convertSignatureObjectToSignSignatureObject(s);
+//
+// LocalConnector local_conn = ConnectorChooser.chooseLocalConnectorForVerify(si.connector, s.getKZ(), so.id, si.type, loc_ref_url);
+// String request_string = local_conn.prepareVerifyRequest(sd, so);
+//
+// LocalRequest local_request = new LocalRequest("not-needed", request_string);
+// si.requests[0] = local_request;
+// si.response_properties[0] = null;
+//
+// // TODO read from config - already deprecated
+// String local_request_url = getLocalServiceAddress(si.type, si.connector);
+//
+// URL data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/DataURL");
+// 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.
@@ -370,9 +375,8 @@ public abstract class LocalRequestHelper
* @throws NormalizeException
* Forwarded exception.
*/
- public static void prepareDispatchToLocalConnectionPage(
- LocalRequest local_request, HttpServletRequest request,
- HttpServletResponse response) throws IOException, SignatureException, NormalizeException
+ public static void prepareDispatchToLocalConnectionPage(LocalRequest local_request, HttpServletRequest request, HttpServletResponse response) throws IOException, SignatureException,
+ NormalizeException
{
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
@@ -403,19 +407,71 @@ public abstract class LocalRequestHelper
output = output.replaceAll(">", "&gt;");
return output;
}
-
+
public static String getLocalServerAddress(HttpServletRequest request, HttpServletResponse response)
{
- String host = request.getServerName();
- URL local_server = null;
- try {
- local_server = new URL(request.getScheme(), host, request.getServerPort(), "/");
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String loc_server = response.encodeURL(local_server.toString());
-
- return loc_server;
+ String host = request.getServerName();
+ URL local_server = null;
+ try
+ {
+ local_server = new URL(request.getScheme(), host, request.getServerPort(), "/");
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ String loc_server = response.encodeURL(local_server.toString());
+
+ return loc_server;
}
+
+ /**
+ * Returns the URL for accessing the local service.
+ * <p>
+ * This information is taken from the profile and if not defined from the
+ * defaults.
+ * </p>
+ * <p>
+ * E.g. http://127.0.0.1:3495/http-security-layer-request
+ * </p>
+ *
+ * @param profile
+ * The profile to take the data from.
+ * @param device
+ * The service device to be accessed. E.g. bku.
+ * @return Returns the URL for accessing the local service.
+ * @throws SettingsException F.e.
+ */
+ public static String getLocalServiceAddress(String profile, String device) throws SettingsException
+ {
+ SettingsReader settings = SettingsReader.getInstance();
+
+ String url = getConnectorValueFromProfile(settings, profile, device + ".sign.url");
+
+ return url; //"http://127.0.0.1:3495/http-security-layer-request";
+ }
+
+ /**
+ * Reads the configuration entry given by the key, first from the given
+ * profile, if not found from the defaults.
+ *
+ * @param settings
+ * The settings.
+ * @param profile
+ * The profile.
+ * @param key
+ * The configuration key.
+ * @return Returns the configuration entry.
+ */
+ public static String getConnectorValueFromProfile(SettingsReader settings,
+ String profile, String key)
+ {
+ String value = settings.getValueFromKey("sig_obj." + profile + "." + key); //$NON-NLS-1$//$NON-NLS-2$
+ if (value == null)
+ {
+ value = settings.getValueFromKey(key);
+ }
+ return value;
+ }
+
}