diff options
19 files changed, 374 insertions, 24 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignParameters.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignParameters.java index 4f626e17..ad17a236 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignParameters.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignParameters.java @@ -15,8 +15,26 @@ public class PDFASSignParameters implements Serializable { @XmlType(name="Connector") public enum Connector { - JKS, - MOA + JKS("jks"), + MOA("moa"), + BKU("bku"), + MOBILEBKU("mobilebku"), + ONLINEBKU("onlinebku"); + + + private final String name; + + private Connector(String s) { + name = s; + } + + public boolean equalsName(String otherName){ + return (otherName == null)? false:name.equals(otherName); + } + + public String toString(){ + return name; + } } @@ -24,8 +42,9 @@ public class PDFASSignParameters implements Serializable { String position; - - + String invokeUrl; + String invokeErrorUrl; + String transactionId; String profile; @XmlElement(required = true, nillable = false, name="connector") @@ -53,6 +72,28 @@ public class PDFASSignParameters implements Serializable { this.profile = profile; } + @XmlElement(required = false, nillable = true, name="invoke-url") + public String getInvokeURL() { + return invokeUrl; + } + public void setInvokeURL(String invokeUrl) { + this.invokeUrl = invokeUrl; + } + + @XmlElement(required = false, nillable = true, name="invoke-error-url") + public String getInvokeErrorURL() { + return invokeErrorUrl; + } + public void setInvokeErrorURL(String invokeErrorUrl) { + this.invokeErrorUrl = invokeErrorUrl; + } + @XmlElement(required = false, nillable = true, name="transactionId") + public String getTransactionId() { + return transactionId; + } + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignResponse.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignResponse.java index 1da4fa98..a43272f1 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignResponse.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignResponse.java @@ -16,6 +16,7 @@ public class PDFASSignResponse implements Serializable { String requestID; String error; byte[] signedPDF; + String redirectUrl; @XmlElement(required = true, nillable = false, name="requestID") public String getRequestID() { @@ -40,4 +41,12 @@ public class PDFASSignResponse implements Serializable { public void setError(String error) { this.error = error; } + + @XmlElement(required = false, name="redirectUrl") + public String getRedirectUrl() { + return redirectUrl; + } + public void setRedirectUrl(String redirectUrl) { + this.redirectUrl = redirectUrl; + } } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSigning.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSigning.java index 63049bc5..698a2845 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSigning.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSigning.java @@ -10,9 +10,9 @@ import javax.jws.soap.SOAPBinding.Style; @WebService @SOAPBinding(style = Style.RPC) public interface PDFASSigning { - @WebMethod(operationName = "sign") - @WebResult(name="signedPDF") - public byte[] signPDFDokument(@WebParam(name = "pdfDocument")byte[] inputDocument, @WebParam(name = "parameters")PDFASSignParameters parameters); + //@WebMethod(operationName = "sign") + //@WebResult(name="signedPDF") + //public byte[] signPDFDokument(@WebParam(name = "pdfDocument")byte[] inputDocument, @WebParam(name = "parameters")PDFASSignParameters parameters); @WebMethod(operationName = "signSingle") @WebResult(name="signResponse") diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/StatusRequest.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/StatusRequest.java index 42bd79c6..df397733 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/StatusRequest.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/StatusRequest.java @@ -25,6 +25,8 @@ package at.gv.egiz.pdfas.lib.api; import java.security.cert.CertificateException; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; + /** * Status of a signture process */ @@ -78,5 +80,7 @@ public interface StatusRequest { * @param signatureValue */ public void setSigature(byte[] signatureValue) ; + + public SignParameter getSignParameter(); } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/StatusRequestImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/StatusRequestImpl.java index 86b8325e..49b78659 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/StatusRequestImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/StatusRequestImpl.java @@ -28,6 +28,7 @@ import iaik.x509.X509Certificate; import java.security.cert.CertificateException; import at.gv.egiz.pdfas.lib.api.StatusRequest; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.impl.status.OperationStatus; public class StatusRequestImpl implements StatusRequest { @@ -105,4 +106,10 @@ public class StatusRequestImpl implements StatusRequest { public void setSigature(byte[] signatureValue) { this.encodedSignature = signatureValue; } + + public SignParameter getSignParameter() { + return this.status.getSignParamter(); + } + + } diff --git a/pdf-as-web-client/src/main/java/at/gv/egiz/pdfas/web/client/RemotePDFSigner.java b/pdf-as-web-client/src/main/java/at/gv/egiz/pdfas/web/client/RemotePDFSigner.java index 456a3aaa..7fd6a189 100644 --- a/pdf-as-web-client/src/main/java/at/gv/egiz/pdfas/web/client/RemotePDFSigner.java +++ b/pdf-as-web-client/src/main/java/at/gv/egiz/pdfas/web/client/RemotePDFSigner.java @@ -34,11 +34,6 @@ public class RemotePDFSigner implements PDFASSigning { binding.setMTOMEnabled(useMTOM); } - public byte[] signPDFDokument(byte[] inputDocument, - PDFASSignParameters parameters) { - return proxy.signPDFDokument(inputDocument, parameters); - } - public PDFASSignResponse signPDFDokument(PDFASSignRequest request) { return proxy.signPDFDokument(request); } diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java index 8573b224..32c6dbad 100644 --- a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java @@ -24,7 +24,7 @@ public class SimpleTest { byte[] inputData = IOUtils.readFully(fis, -1, true); PDFASSignParameters signParameters = new PDFASSignParameters(); - signParameters.setConnector(Connector.JKS); + signParameters.setConnector(Connector.BKU); signParameters.setPosition(null); signParameters.setProfile("SIGNATURBLOCK_DE"); @@ -42,8 +42,14 @@ public class SimpleTest { RemotePDFSigner signer = new RemotePDFSigner(endpoint, false); + PDFASSignRequest signrequest = new PDFASSignRequest(); + signrequest.setInputData(inputData); + signrequest.setParameters(signParameters); + signParameters.setTransactionId("MYID ...."); System.out.println("Simple Request:"); - byte[] outputFile = signer.signPDFDokument(inputData, signParameters); + PDFASSignResponse response = signer.signPDFDokument(signrequest); + + System.out.println("User URL: " + response.getRedirectUrl()); /* * System.out.println("Simple Request:"); byte[] outputFile = diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java index 4555d6a1..299c166f 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java @@ -56,6 +56,9 @@ public class WebConfiguration { public static final String WHITELIST_ENABLED = "whitelist.enabled"; public static final String WHITELIST_VALUE_PRE = "whitelist.url."; + public static final String REQUEST_STORE = "request.store"; + public static final String REQUEST_STORE_INMEM = "at.gv.egiz.pdfas.web.store.InMemoryRequestStore"; + private static Properties properties = new Properties(); private static final Logger logger = LoggerFactory @@ -211,4 +214,14 @@ public class WebConfiguration { } return true; } + + public static String getStoreClass() { + String cls = properties.getProperty(REQUEST_STORE); + + if(cls != null) { + return cls; + } + + return REQUEST_STORE_INMEM; + } } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/exception/PdfAsStoreException.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/exception/PdfAsStoreException.java new file mode 100644 index 00000000..f4c70278 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/exception/PdfAsStoreException.java @@ -0,0 +1,17 @@ +package at.gv.egiz.pdfas.web.exception; + +public class PdfAsStoreException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -6704586769888839023L; + + public PdfAsStoreException(String message) { + super(message); + } + + public PdfAsStoreException(String message, Throwable e) { + super(message, e); + } +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java index ee67985b..421edff4 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java @@ -25,6 +25,8 @@ package at.gv.egiz.pdfas.web.helper; import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Iterator; import java.util.List; @@ -57,9 +59,9 @@ import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; import at.gv.egiz.pdfas.sigs.pades.PAdESSigner; import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore; -import at.gv.egiz.pdfas.sigs.pkcs7detached.PKCS7DetachedSigner; import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.exception.PdfAsWebException; +import at.gv.egiz.pdfas.web.servlets.UIEntryPointServlet; import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType; import at.gv.egiz.sl.schema.InfoboxAssocArrayPairType; import at.gv.egiz.sl.schema.InfoboxReadRequestType; @@ -84,6 +86,7 @@ public class PdfAsHelper { private static final String PDF_PROVIDE_PAGE = "/ProvidePDF"; private static final String PDF_PDFDATA_PAGE = "/PDFData"; private static final String PDF_DATAURL_PAGE = "/DataURL"; + private static final String PDF_USERENTRY_PAGE = "/userentry"; private static final String PDF_ERR_URL = "PDF_ERR_URL"; private static final String PDF_FILE_NAME = "PDF_FILE_NAME"; private static final String PDF_INVOKE_URL = "PDF_INVOKE_URL"; @@ -384,7 +387,8 @@ public class PdfAsHelper { } public static void startSignature(HttpServletRequest request, - HttpServletResponse response, ServletContext context, byte[] pdfData) + HttpServletResponse response, ServletContext context, byte[] pdfData, + String connector, String transactionId) throws Exception { // TODO: Protect session so that only one PDF can be signed during one @@ -409,9 +413,10 @@ public class PdfAsHelper { SignParameter signParameter = PdfAsFactory.createSignParameter(config, new ByteArrayDataSource(pdfData)); - // Get Connector - String connector = PdfAsParameterExtractor.getConnector(request); - + logger.info("Setting TransactionID: " + transactionId); + + signParameter.setTransactionId(transactionId); + IPlainSigner signer; if (connector.equals("bku") || connector.equals("onlinebku") || connector.equals("mobilebku")) { @@ -535,7 +540,7 @@ public class PdfAsHelper { logger.debug("Needing Certificate from BKU"); // build SL Request to read certificate InfoboxReadRequestType readCertificateRequest = bkuSLConnector - .createInfoboxReadRequest(); + .createInfoboxReadRequest(statusRequest.getSignParameter()); JAXBElement<InfoboxReadRequestType> readRequest = of .createInfoboxReadRequest(readCertificateRequest); @@ -548,6 +553,14 @@ public class PdfAsHelper { template = template.replace("##XMLRequest##", StringEscapeUtils.escapeHtml4(slRequest)); template = template.replace("##DataURL##", url); + + if(statusRequest.getSignParameter().getTransactionId() != null) { + template = template.replace("##ADDITIONAL##", "<input type=\"hidden\" name=\"TransactionId_\" value=\"" + + StringEscapeUtils.escapeHtml4(statusRequest.getSignParameter().getTransactionId()) + "\">"); + } else { + template = template.replace("##ADDITIONAL##", ""); + } + response.getWriter().write(template); //TODO: set content type of response!! response.setContentType("text/html"); @@ -557,7 +570,8 @@ public class PdfAsHelper { // build SL Request for cms signature RequestPackage pack = bkuSLConnector .createCMSRequest(statusRequest.getSignatureData(), - statusRequest.getSignatureDataByteRange()); + statusRequest.getSignatureDataByteRange(), + statusRequest.getSignParameter()); String slRequest = SLMarschaller .marshalToString(of @@ -775,6 +789,22 @@ public class PdfAsHelper { HttpServletResponse response) { return generateURL(request, response, PDF_PDFDATA_PAGE); } + + public static String generateUserEntryURL(String storeId) { + String publicURL = WebConfiguration.getPublicURL(); + if(publicURL == null) { + logger.error("To use this functionality " + WebConfiguration.PUBLIC_URL + " has to be configured in the web configuration"); + return null; + } + + String baseURL = publicURL + PDF_USERENTRY_PAGE; + try { + return baseURL + "?" + UIEntryPointServlet.REQUEST_ID_PARAM + "=" + URLEncoder.encode(storeId, "UTF-8"); + } catch(UnsupportedEncodingException e) { + logger.warn("Encoding not supported for URL encoding", e); + } + return baseURL + "?" + UIEntryPointServlet.REQUEST_ID_PARAM + "=" + storeId; + } public static String generateBKUURL(String connector) { if (connector.equals("bku")) { diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java index 730fe9ad..126b10ce 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; public class PdfAsParameterExtractor { public static final String PARAM_CONNECTOR = "connector"; + public static final String PARAM_TRANSACTION_ID = "transactionId"; public static final String PARAM_CONNECTOR_DEFAULT = "bku"; @@ -53,6 +54,11 @@ public class PdfAsParameterExtractor { return PARAM_CONNECTOR_DEFAULT; } + public static String getTransactionId(HttpServletRequest request) { + String transactionId = (String)request.getAttribute(PARAM_TRANSACTION_ID); + return transactionId; + } + public static String getInvokeURL(HttpServletRequest request) { return (String)request.getAttribute(PARAM_INVOKE_URL); } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java index 153a69fe..a7d82c3e 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java @@ -238,6 +238,8 @@ public class ExternSignServlet extends HttpServlet { HttpServletResponse response, byte[] pdfData) throws Exception { // Get Connector String connector = PdfAsParameterExtractor.getConnector(request); + + String transactionId = PdfAsParameterExtractor.getTransactionId(request); String invokeUrl = PdfAsParameterExtractor.getInvokeURL(request); PdfAsHelper.setInvokeURL(request, response, invokeUrl); @@ -278,7 +280,7 @@ public class ExternSignServlet extends HttpServlet { } } - PdfAsHelper.startSignature(request, response, getServletContext(), pdfData); + PdfAsHelper.startSignature(request, response, getServletContext(), pdfData, connector, transactionId); } else if (connector.equals("jks") || connector.equals("moa")) { // start synchronous siganture creation diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java new file mode 100644 index 00000000..3aad5abb --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java @@ -0,0 +1,117 @@ +package at.gv.egiz.pdfas.web.servlets; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.http.HttpStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.web.config.WebConfiguration; +import at.gv.egiz.pdfas.web.exception.PdfAsStoreException; +import at.gv.egiz.pdfas.web.exception.PdfAsWebException; +import at.gv.egiz.pdfas.web.helper.DigestHelper; +import at.gv.egiz.pdfas.web.helper.PdfAsHelper; +import at.gv.egiz.pdfas.web.helper.PdfAsParameterExtractor; +import at.gv.egiz.pdfas.web.store.RequestStore; + +public class UIEntryPointServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + public static final String REQUEST_ID_PARAM = "reqId"; + + private static final Logger logger = LoggerFactory + .getLogger(UIEntryPointServlet.class); + + public UIEntryPointServlet() { + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doProcess(req, resp); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doProcess(req, resp); + } + + protected void doProcess(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + try { + String storeId = req.getParameter(REQUEST_ID_PARAM); + + if (storeId == null) { + throw new PdfAsStoreException("Wrong Parameters"); + } + + PDFASSignRequest pdfAsRequest = RequestStore.getInstance() + .fetchStoreEntry(storeId); + + if(pdfAsRequest == null) { + throw new PdfAsStoreException("Invalid " + REQUEST_ID_PARAM + " value"); + } + + Connector connector = pdfAsRequest.getParameters().getConnector(); + + String invokeUrl = pdfAsRequest.getParameters().getInvokeURL(); + PdfAsHelper.setInvokeURL(req, resp, invokeUrl); + + String errorUrl = pdfAsRequest.getParameters().getInvokeErrorURL(); + PdfAsHelper.setErrorURL(req, resp, errorUrl); + + if(pdfAsRequest.getInputData() == null) { + throw new PdfAsException("No Signature data available"); + } + + String pdfDataHash = DigestHelper.getHexEncodedHash(pdfAsRequest.getInputData()); + + PdfAsHelper.setSignatureDataHash(req, pdfDataHash); + logger.debug("Storing signatures data hash: " + pdfDataHash); + + logger.debug("Starting signature creation with: " + connector); + + //IPlainSigner signer; + if (connector.equals(Connector.BKU) || connector.equals(Connector.ONLINEBKU) || connector.equals(Connector.MOBILEBKU)) { + // start asynchronous signature creation + + if(connector.equals(Connector.BKU)) { + if(WebConfiguration.getLocalBKUURL() == null) { + throw new PdfAsWebException("Invalid connector bku is not supported"); + } + } + + if(connector.equals(Connector.ONLINEBKU)) { + if(WebConfiguration.getLocalBKUURL() == null) { + throw new PdfAsWebException("Invalid connector onlinebku is not supported"); + } + } + + if(connector.equals(Connector.MOBILEBKU)) { + if(WebConfiguration.getLocalBKUURL() == null) { + throw new PdfAsWebException("Invalid connector mobilebku is not supported"); + } + } + + PdfAsHelper.startSignature(req, resp, getServletContext(), pdfAsRequest.getInputData(), + connector.toString(), pdfAsRequest.getParameters().getTransactionId()); + } else { + throw new PdfAsWebException("Invalid connector (" + Connector.BKU + " | " + Connector.ONLINEBKU + " | " + Connector.MOBILEBKU + ")"); + } + + + } catch (Throwable e) { + PdfAsHelper.setSessionException(req, resp, e.getMessage(), e); + PdfAsHelper.gotoError(getServletContext(), req, resp); + } + } +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/IRequestStore.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/IRequestStore.java new file mode 100644 index 00000000..6623004b --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/IRequestStore.java @@ -0,0 +1,8 @@ +package at.gv.egiz.pdfas.web.store; + +import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; + +public interface IRequestStore { + public String createNewStoreEntry(PDFASSignRequest request); + public PDFASSignRequest fetchStoreEntry(String id); +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/InMemoryRequestStore.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/InMemoryRequestStore.java new file mode 100644 index 00000000..df9ab676 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/InMemoryRequestStore.java @@ -0,0 +1,31 @@ +package at.gv.egiz.pdfas.web.store; + +import java.util.HashMap; +import java.util.UUID; + +import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; + +public class InMemoryRequestStore implements IRequestStore { + + public InMemoryRequestStore() { + } + + private HashMap<String, PDFASSignRequest> store = new HashMap<String, PDFASSignRequest>(); + + public String createNewStoreEntry(PDFASSignRequest request) { + UUID id = UUID.randomUUID(); + String sid = id.toString(); + this.store.put(sid, request); + return sid; + } + + public PDFASSignRequest fetchStoreEntry(String id) { + if(store.containsKey(id)) { + PDFASSignRequest request = store.get(id); + store.remove(id); + return request; + } + return null; + } + +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/RequestStore.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/RequestStore.java new file mode 100644 index 00000000..a4eba2e6 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/RequestStore.java @@ -0,0 +1,35 @@ +package at.gv.egiz.pdfas.web.store; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.egiz.pdfas.web.config.WebConfiguration; +import at.gv.egiz.pdfas.web.exception.PdfAsStoreException; + +public class RequestStore { + private static IRequestStore instance = null; + + private static final Logger logger = LoggerFactory + .getLogger(RequestStore.class); + + public synchronized static IRequestStore getInstance() throws PdfAsStoreException { + if (instance == null) { + try { + String storeClass = WebConfiguration.getStoreClass(); + logger.info("Using Request Store: " + storeClass); + + Class<?> clazz = Class.forName(storeClass); + Object store = clazz.newInstance(); + if(store instanceof IRequestStore) { + instance = (IRequestStore)store; + } else { + throw new PdfAsStoreException("Failed to instanciate Request Store from " + storeClass); + } + } catch (Throwable e) { + e.printStackTrace(); + throw new PdfAsStoreException("Failed to instanciate Request Store", e); + } + } + return instance; + } +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java index 07ffd7c4..5304f918 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java @@ -16,8 +16,10 @@ import at.gv.egiz.pdfas.api.ws.PDFASSignParameters; import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; import at.gv.egiz.pdfas.api.ws.PDFASSignResponse; import at.gv.egiz.pdfas.api.ws.PDFASSigning; +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; +import at.gv.egiz.pdfas.web.store.RequestStore; @MTOM @WebService(endpointInterface = "at.gv.egiz.pdfas.api.ws.PDFASSigning") @@ -25,7 +27,7 @@ public class PDFASSigningImpl implements PDFASSigning { private static final Logger logger = LoggerFactory .getLogger(PDFASSigningImpl.class); - + public byte[] signPDFDokument(byte[] inputDocument, PDFASSignParameters parameters) { checkSoapSignEnabled(); @@ -50,8 +52,24 @@ public class PDFASSigningImpl implements PDFASSigning { } PDFASSignResponse response = new PDFASSignResponse(); try { - response.setSignedPDF(signPDFDokument(request.getInputData(), + if(request.getParameters().getConnector().equals(Connector.MOA) || + request.getParameters().getConnector().equals(Connector.JKS)) { + // Plain server based signatures!! + response.setSignedPDF(signPDFDokument(request.getInputData(), request.getParameters())); + } else { + // Signatures with user interaction!! + String id = RequestStore.getInstance().createNewStoreEntry(request); + String userEntryURL = PdfAsHelper.generateUserEntryURL(id); + logger.debug("Generated request store: " + id); + logger.debug("Generated UI URL: " + userEntryURL); + + if(userEntryURL == null) { + throw new WebServiceException("Failed to generate User Entry URL"); + } + + response.setRedirectUrl(userEntryURL); + } } catch (Throwable e) { if (e.getCause() != null) { response.setError(e.getCause().getMessage()); diff --git a/pdf-as-web/src/main/resources/template_sl.html b/pdf-as-web/src/main/resources/template_sl.html index e53652e5..b8ea4df7 100644 --- a/pdf-as-web/src/main/resources/template_sl.html +++ b/pdf-as-web/src/main/resources/template_sl.html @@ -50,6 +50,7 @@ div.content { name="Senden"> <input type="hidden" name="XMLRequest" value="##XMLRequest##"> <input type="hidden" name="DataURL" value="##DataURL##"> + ##ADDITIONAL## </form> <span id="spin" style="display:block; width:100px; diff --git a/pdf-as-web/src/main/webapp/WEB-INF/web.xml b/pdf-as-web/src/main/webapp/WEB-INF/web.xml index 85811ff0..8373c195 100644 --- a/pdf-as-web/src/main/webapp/WEB-INF/web.xml +++ b/pdf-as-web/src/main/webapp/WEB-INF/web.xml @@ -88,6 +88,12 @@ <description></description> <servlet-class>at.gv.egiz.pdfas.web.servlets.PDFSignatureCertificateData</servlet-class> </servlet> + <servlet> + <servlet-name>UIEntryPointServlet</servlet-name> + <display-name>UIEntryPointServlet</display-name> + <description></description> + <servlet-class>at.gv.egiz.pdfas.web.servlets.UIEntryPointServlet</servlet-class> + </servlet> <!-- Define mappings that are used by the servlet container to translate a particular request URI (context-relative) to a particular servlet. The @@ -134,6 +140,10 @@ <servlet-name>PDFVerifyCert</servlet-name> <url-pattern>/signCert</url-pattern> </servlet-mapping> + <servlet-mapping> + <servlet-name>UIEntryPointServlet</servlet-name> + <url-pattern>/userentry</url-pattern> + </servlet-mapping> <!-- Define the default session timeout for your application, in minutes. From a servlet or JSP page, you can modify the timeout for a particular session |