diff options
| author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2026-06-09 15:07:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-09 15:07:54 +0200 |
| commit | 455433ffc936b72483317b74849e4f27ab6003cb (patch) | |
| tree | 134d23bc0aa62c3101270dde726ff36bbb5b8e0c /pdf-as-web/src/main/java/at | |
| parent | ab521a7b02d2f01673ab944bbe76c6426edea646 (diff) | |
| download | pdf-as-4-455433ffc936b72483317b74849e4f27ab6003cb.tar.gz pdf-as-4-455433ffc936b72483317b74849e4f27ab6003cb.tar.bz2 pdf-as-4-455433ffc936b72483317b74849e4f27ab6003cb.zip | |
Clean up `Connector` usages (#90)
* migrate all connector-string uses to Connector enum, and fail early for unsupported connectors
* extra null guards + clean up equals for enums
* unify the parameter checking for jks too
* make empty/null inputs fail earlier
* exception instead of empty return
Diffstat (limited to 'pdf-as-web/src/main/java/at')
6 files changed, 164 insertions, 271 deletions
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 5e7e3bd0..22178921 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 @@ -34,11 +34,7 @@ import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.security.cert.CertificateException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import javax.imageio.ImageIO; import jakarta.servlet.RequestDispatcher; @@ -391,17 +387,14 @@ public class PdfAsHelper { new ByteArrayDataSource(documentToSign.getInputData()), baos); // Get Connector + val connector = coreParams.getConnector(); + val keyIdentifier = coreParams.getKeyIdentifier(); + PdfAsHelper.checkConnectorSupported(connector, keyIdentifier); IPlainSigner signer; - if (coreParams.getConnector().equals(Connector.MOA)) { - String keyIdentifier = coreParams.getKeyIdentifier(); + if (connector == Connector.MOA) { if (keyIdentifier != null) { - if (!WebConfiguration.isMoaEnabled(keyIdentifier)) { - throw new PdfAsWebException("MOA connector [" - + keyIdentifier + "] disabled or not existing."); - } - String url = WebConfiguration.getMoaURL(keyIdentifier); String timeout = WebConfiguration.getMoaTimeout(keyIdentifier); String keyId = WebConfiguration.getMoaKeyID(keyIdentifier); @@ -413,19 +406,12 @@ public class PdfAsHelper { config.setValue(IConfigurationConstants.MOA_SIGN_KEY_ID, keyId); config.setValue(IConfigurationConstants.MOA_SIGN_CERTIFICATE, certificate); - } else { - if (!WebConfiguration.getMOASSEnabled()) { - throw new PdfAsWebException("MOA connector disabled."); - } } signer = new PAdESSigner(new MOAConnector(config)); - } else if (coreParams.getConnector().equals(Connector.JKS)) { - String keyIdentifier = coreParams.getKeyIdentifier(); - - boolean ksEnabled = false; + } else if (connector == Connector.JKS) { String ksFile = null; String ksAlias = null; String ksPass = null; @@ -433,14 +419,12 @@ public class PdfAsHelper { String ksType = null; if (keyIdentifier != null) { - ksEnabled = WebConfiguration.getKeystoreEnabled(keyIdentifier); ksFile = WebConfiguration.getKeystoreFile(keyIdentifier); ksAlias = WebConfiguration.getKeystoreAlias(keyIdentifier); ksPass = WebConfiguration.getKeystorePass(keyIdentifier); ksKeyPass = WebConfiguration.getKeystoreKeyPass(keyIdentifier); ksType = WebConfiguration.getKeystoreType(keyIdentifier); } else { - ksEnabled = WebConfiguration.getKeystoreDefaultEnabled(); ksFile = WebConfiguration.getKeystoreDefaultFile(); ksAlias = WebConfiguration.getKeystoreDefaultAlias(); ksPass = WebConfiguration.getKeystoreDefaultPass(); @@ -448,27 +432,6 @@ public class PdfAsHelper { ksType = WebConfiguration.getKeystoreDefaultType(); } - if (!ksEnabled) { - if (keyIdentifier != null) { - throw new PdfAsWebException("JKS connector [" - + keyIdentifier + "] disabled or not existing."); - } else { - throw new PdfAsWebException( - "DEFAULT JKS connector disabled."); - } - } - - if (ksFile == null || ksAlias == null || ksPass == null - || ksKeyPass == null || ksType == null) { - if (keyIdentifier != null) { - throw new PdfAsWebException("JKS connector [" - + keyIdentifier + "] not correctly configured."); - } else { - throw new PdfAsWebException( - "DEFAULT JKS connector not correctly configured."); - } - } - signer = new PAdESSignerKeystore(ksFile, ksAlias, ksPass, ksKeyPass, ksType); @@ -541,11 +504,11 @@ public class PdfAsHelper { } public static void startSignatureJson(HttpServletRequest request, HttpServletResponse response, - ServletContext context, String connector, PdfasSignRequest pdfAsRequest) throws Exception { + ServletContext context, Connector connector, PdfasSignRequest pdfAsRequest) throws Exception { HttpSession session = request.getSession(); log.info("Starting signature in session: " + session.getId()); - session.setAttribute(PDF_PROCESSING_REQUEST, pdfAsRequest); + session.setAttribute(PDF_PROCESSING_REQUEST, pdfAsRequest); StatusRequest statusRequest = initializeSigningContextForNewDocument(request, connector, pdfAsRequest); session.setAttribute(PDF_STATUS, statusRequest); @@ -553,7 +516,7 @@ public class PdfAsHelper { } public static void startSignature(HttpServletRequest request, HttpServletResponse response, - ServletContext context, String connector, PdfasSignRequest pdfAsRequest) throws Exception { + ServletContext context, Connector connector, PdfasSignRequest pdfAsRequest) throws Exception { HttpSession session = request.getSession(); log.info("Starting signature in session: " + session.getId()); session.setAttribute(PDF_PROCESSING_REQUEST, pdfAsRequest); @@ -566,7 +529,7 @@ public class PdfAsHelper { } - private static StatusRequest.Stage1 initializeSigningContextForNewDocument(HttpServletRequest request, String connector, PdfasSignRequest pdfAsRequest) + private static StatusRequest.Stage1 initializeSigningContextForNewDocument(HttpServletRequest request, Connector connector, PdfasSignRequest pdfAsRequest) throws PdfAsWebException, WriterException, IOException, PdfAsException, PDFASError { HttpSession session = request.getSession(); @@ -643,23 +606,14 @@ public class PdfAsHelper { } - private static IPlainSigner getSignerFromConnector(String connector, Configuration config, HttpSession session) throws PdfAsWebException { - if (connector.equals("bku") || connector.equals("onlinebku") - || connector.equals("mobilebku")) { - BKUSLConnector conn = new BKUSLConnector(config); - session.setAttribute(PDF_SL_CONNECTOR, conn); - return new PAdESSigner(conn); - - - } else if (connector.equals("sl20")) { - SL20Connector conn = new SL20Connector(config); - session.setAttribute(PDF_SL_CONNECTOR, conn); - return new PAdESSigner(conn); - - } else { - throw new PdfAsWebException( - "Invalid connector (bku | onlinebku | mobilebku | moa | jks | sl20)"); - } + private static IPlainSigner getSignerFromConnector(Connector connector, Configuration config, HttpSession session) throws PdfAsWebException { + val slConnector = switch(connector) { + case BKU, ONLINEBKU, MOBILEBKU -> new BKUSLConnector(config); + case SECLAYER20 -> new SL20Connector(config); + default -> throw new PdfAsWebException("Invalid connector (bku | onlinebku | mobilebku | sl20)"); + }; + session.setAttribute(PDF_SL_CONNECTOR, slConnector); + return new PAdESSigner(slConnector); } public static byte[] getCertificate( @@ -769,10 +723,10 @@ public class PdfAsHelper { // IPlainSigner plainSigner = (IPlainSigner) session // .getAttribute(PDF_SIGNER); - String connector = (String) session.getAttribute(PDF_SL_INTERACTIVE); + Connector connector = (Connector) session.getAttribute(PDF_SL_INTERACTIVE); + PdfAsHelper.checkConnectorSupported(connector, null); - if (connector.equals("bku") || connector.equals("onlinebku") - || connector.equals("mobilebku")) { + if (connector == Connector.BKU || connector == Connector.ONLINEBKU || connector == Connector.MOBILEBKU) { BKUSLConnector bkuSLConnector = (BKUSLConnector) session .getAttribute(PDF_SL_CONNECTOR); @@ -809,7 +763,8 @@ public class PdfAsHelper { // IPlainSigner plainSigner = (IPlainSigner) session // .getAttribute(PDF_SIGNER); - String connector = (String) session.getAttribute(PDF_SL_INTERACTIVE); + Connector connector = (Connector) session.getAttribute(PDF_SL_INTERACTIVE); + PdfAsHelper.checkConnectorSupported(connector, null); //load connector ISLConnector slConnector = (ISLConnector) session.getAttribute(PDF_SL_CONNECTOR); @@ -1412,28 +1367,19 @@ public class PdfAsHelper { } String baseURL = publicURL + PDF_USERENTRY_PAGE; - try { - return baseURL + "?" + UIEntryPointServlet.REQUEST_ID_PARAM + "=" - + URLEncoder.encode(storeId, "UTF-8"); - } catch (UnsupportedEncodingException e) { - log.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")) { - return WebConfiguration.getLocalBKUURL(); - } else if (connector.equals("onlinebku")) { - return WebConfiguration.getOnlineBKUURL(); - } else if (connector.equals("mobilebku")) { - return WebConfiguration.getHandyBKUURL(); - } else if (connector.equals("sl20")) { - return WebConfiguration.getSecurityLayer20URL(); - } - return WebConfiguration.getLocalBKUURL(); - } + return baseURL + "?" + UIEntryPointServlet.REQUEST_ID_PARAM + "=" + + URLEncoder.encode(storeId, StandardCharsets.UTF_8); + } + + public static String generateBKUURL(Connector connector) { + return switch (connector) { + case BKU -> WebConfiguration.getLocalBKUURL(); + case ONLINEBKU -> WebConfiguration.getOnlineBKUURL(); + case MOBILEBKU -> WebConfiguration.getHandyBKUURL(); + case SECLAYER20 -> WebConfiguration.getSecurityLayer20URL(); + default -> throw new IllegalStateException("Attempt to get BKU URL for connector: "+connector.name()); + }; + } public static void setFromDataUrl(HttpServletRequest request) { request.setAttribute(REQUEST_FROM_DU, (Boolean) true); @@ -1443,7 +1389,7 @@ public class PdfAsHelper { Object obj = request.getAttribute(REQUEST_FROM_DU); if (obj != null) { if (obj instanceof Boolean) { - return ((Boolean) obj).booleanValue(); + return (Boolean) obj; } } return false; @@ -1642,7 +1588,7 @@ public class PdfAsHelper { log.trace("SL20 response to VDA: " + respContainer); StringWriter writer = new StringWriter(); writer.write(respContainer.toString()); - final byte[] content = writer.toString().getBytes("UTF-8"); + final byte[] content = writer.toString().getBytes(StandardCharsets.UTF_8); response.setStatus(HttpServletResponse.SC_OK); response.setContentLength(content.length); response.setContentType(ContentType.APPLICATION_JSON.toString()); @@ -1656,4 +1602,82 @@ public class PdfAsHelper { } } + private static boolean anyNull(Object... any) { + return (Arrays.stream(any).anyMatch(Objects::isNull)); + } + + public static void checkConnectorSupported(Connector connector, String keyIdentifier) throws PdfAsWebException { + if (connector == null) { + throw new PdfAsWebException("Invalid or unknown connector value"); + } else if (connector == Connector.BKU) { + if (!WebConfiguration.getLocalBKUEnabled()) { + throw new PdfAsWebException("Connector bku is not enabled in configuration"); + } + if (WebConfiguration.getLocalBKUURL() == null) { + throw new PdfAsWebException("Connector bku is not properly configured"); + } + } else if (connector == Connector.ONLINEBKU) { + if (!WebConfiguration.getOnlineBKUEnabled()) { + throw new PdfAsWebException("Connector onlinebku is not enabled in configuration"); + } + if (WebConfiguration.getOnlineBKUURL() == null) { + throw new PdfAsWebException("Connector onlinebku is not properly configured"); + } + } else if (connector == Connector.MOBILEBKU) { + if (!WebConfiguration.getMobileBKUEnabled()) { + throw new PdfAsWebException("Connector mobilebku is not enabled in configuration"); + } + if (WebConfiguration.getHandyBKUURL() == null) { + throw new PdfAsWebException("Connector mobilebku is not properly configured"); + } + } else if (connector == Connector.SECLAYER20) { + if (!WebConfiguration.getSL20Enabled()) { + throw new PdfAsWebException("Connector sl20 is not enabled in configuration"); + } + if (WebConfiguration.getSecurityLayer20URL() == null) { + throw new PdfAsWebException("Connector sl20 is not properly configured"); + } + } else if (connector == Connector.MOA) { + if (keyIdentifier != null) { + if (!WebConfiguration.isMoaEnabled(keyIdentifier)) { + throw new PdfAsWebException("Connector moa[keyId="+keyIdentifier+"] is not enabled in configuration"); + } + } else { + if (!WebConfiguration.getMOASSEnabled()) { + throw new PdfAsWebException("Connector moa[default] is not enabled in configuration"); + } + } + } else if (connector == Connector.JKS) { + if (keyIdentifier != null) { + if (!WebConfiguration.getKeystoreEnabled(keyIdentifier)) { + throw new PdfAsWebException("Connector jks[keyId="+keyIdentifier+"] is not enabled in configuration"); + } + if ( + anyNull( + WebConfiguration.getKeystoreFile(keyIdentifier), + WebConfiguration.getKeystoreAlias(keyIdentifier), + WebConfiguration.getKeystorePass(keyIdentifier), + WebConfiguration.getKeystoreKeyPass(keyIdentifier), + WebConfiguration.getKeystoreType(keyIdentifier))) + { + throw new PdfAsWebException("Connector jks[keyId="+keyIdentifier+"] is not properly configured"); + } + } else { + if (!WebConfiguration.getKeystoreDefaultEnabled()) { + throw new PdfAsWebException("Connector jks[default] is not enabled in configuration"); + } + if ( + anyNull( + WebConfiguration.getKeystoreDefaultFile(), + WebConfiguration.getKeystoreDefaultAlias(), + WebConfiguration.getKeystoreDefaultPass(), + WebConfiguration.getKeystoreDefaultKeyPass(), + WebConfiguration.getKeystoreDefaultType())) + { + throw new PdfAsWebException("Connector jks[default] is not properly configured"); + } + } + } + } + } 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 ede5fdf5..7178e38d 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 java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; @@ -82,8 +83,8 @@ public class PdfAsParameterExtractor { private static final Logger logger = LoggerFactory .getLogger(PdfAsParameterExtractor.class); - public static String getConnector(HttpServletRequest request) { - return (String)request.getAttribute(PARAM_CONNECTOR); + public static Connector getConnector(HttpServletRequest request) { + return Connector.fromString((String)request.getAttribute(PARAM_CONNECTOR)); } public static Map<String,String> getDynamicSignatureBlockParameters(HttpServletRequest request) throws Exception { 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 18754288..3b39ee16 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 @@ -308,16 +308,15 @@ public class ExternSignServlet extends HttpServlet { } // Get Connector - String connector = PdfAsParameterExtractor.getConnector(request); - if (connector == null) { - throw new PdfAsException("No connector specified"); - } + Connector connector = PdfAsParameterExtractor.getConnector(request); + String keyIdentifier = PdfAsParameterExtractor.getKeyIdentifier(request); + PdfAsHelper.checkConnectorSupported(connector, keyIdentifier); String transactionId = PdfAsParameterExtractor.getTransactionId(request); statisticEvent.setFilesize(pdfData.length); statisticEvent.setProfileId(null); - statisticEvent.setDevice(connector); + statisticEvent.setDevice(connector.toString()); String invokeUrl = PdfAsParameterExtractor.getInvokeURL(request); PdfAsHelper.setInvokeURL(request, response, invokeUrl); @@ -361,8 +360,8 @@ public class ExternSignServlet extends HttpServlet { CoreSignParams coreParams = new CoreSignParams(); coreParams.setSignatureBlockParameters(dynamicSignatureBlockArguments); - coreParams.setConnector(Connector.fromString(connector)); - coreParams.setKeyIdentifier(PdfAsParameterExtractor.getKeyIdentifier(request)); + coreParams.setConnector(connector); + coreParams.setKeyIdentifier(keyIdentifier); coreParams.setOverrides(PdfAsParameterExtractor.getOverwriteMap(request)); coreParams.setPreprocessor(PdfAsParameterExtractor.getPreProcessorMap(request)); coreParams.setInvokeErrorUrl(errorUrl); @@ -384,67 +383,18 @@ public class ExternSignServlet extends HttpServlet { //IPlainSigner signer; - if (connector.equals("bku") || connector.equals("onlinebku") || connector.equals("mobilebku") - || connector.equals("sl20")) { + if (Connector.isAsynchronous(connector)) { // start asynchronous signature creation - - if(connector.equals("bku")) { - if(WebConfiguration.getLocalBKUURL() == null) { - throw new PdfAsWebException("Invalid connector bku is not supported"); - } - } - if(connector.equals("mobilebku")) { - if(WebConfiguration.getHandyBKUURL() == null) { - throw new PdfAsWebException("Invalid connector mobilebku is not supported"); - } - } - if(connector.equals("onlinebku")) { - if(WebConfiguration.getOnlineBKUURL() == null) { - throw new PdfAsWebException("Invalid connector bku is not supported"); - } - } - if (connector.equals("sl20")) { - if(WebConfiguration.getSecurityLayer20URL() == null) { - throw new PdfAsWebException("Invalid connector bku is not supported"); - } - } PdfAsHelper.setStatisticEvent(request, response, statisticEvent); - // sign document + // sign document PdfAsHelper.startSignature(request, response, getServletContext(), connector, data); return; - } else if (connector.equals("jks") || connector.equals("moa")) { - // start synchronous siganture creation - - if(connector.equals("jks")) { - - String keyIdentifier = PdfAsParameterExtractor.getKeyIdentifier(request); - - boolean ksEnabled = false; - - if (keyIdentifier != null) { - ksEnabled = WebConfiguration.getKeystoreEnabled(keyIdentifier); - } else { - ksEnabled = WebConfiguration.getKeystoreDefaultEnabled(); - } - - if (!ksEnabled) { - if(keyIdentifier != null) { - throw new PdfAsWebException("JKS connector [" + keyIdentifier + "] disabled or not existing."); - } else { - throw new PdfAsWebException("DEFAULT JKS connector disabled."); - } - } - } - - if(connector.equals("moa")) { - if(!WebConfiguration.getMOASSEnabled()) { - throw new PdfAsWebException("Invalid connector moa is not supported"); - } - } + } else { + // start synchronous signature creation // sign document PdfasSignResponse pdfSignedData = PdfAsHelper.synchronousServerSignature(data); @@ -462,9 +412,6 @@ public class ExternSignServlet extends HttpServlet { PdfAsHelper.gotoProvidePdf(getServletContext(), request, response); return; - } else { - throw new PdfAsWebException("Invalid connector (bku | moa | jks | onlinebku | mobilebku)"); - } } } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java index 343e18f2..a9b282a2 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java @@ -87,7 +87,7 @@ public class JSONAPIServlet extends HttpServlet { String profile = jsonObject.has(JSON_PROFILE) ? jsonObject.getString(JSON_PROFILE) : null; String position = jsonObject.has(JSON_POSITION) ? jsonObject.getString(JSON_POSITION) : null; - String connector = jsonObject.getString(JSON_CONNECTOR); + Connector connector = Connector.fromString(jsonObject.getString(JSON_CONNECTOR)); String input = jsonObject.getString(JSON_INPUT); String requestID = jsonObject.has(JSON_REQUEST_ID) ? jsonObject.getString(JSON_REQUEST_ID) : null; @@ -106,40 +106,14 @@ public class JSONAPIServlet extends HttpServlet { try { - if(connector == null) { - throw new ServletException( - "Invalid connector value!"); - } - - PDFASSignParameters.Connector connectorEnum = null; - - if(PDFASSignParameters.Connector.MOA.equalsName(connector)) { - connectorEnum = PDFASSignParameters.Connector.MOA; - } else if(PDFASSignParameters.Connector.JKS.equalsName(connector)) { - connectorEnum = PDFASSignParameters.Connector.JKS; - } else if(PDFASSignParameters.Connector.BKU.equalsName(connector)) { - connectorEnum = PDFASSignParameters.Connector.BKU; - } else if(PDFASSignParameters.Connector.MOBILEBKU.equalsName(connector)) { - connectorEnum = PDFASSignParameters.Connector.MOBILEBKU; - } else if(PDFASSignParameters.Connector.ONLINEBKU.equalsName(connector)) { - connectorEnum = PDFASSignParameters.Connector.ONLINEBKU; - } else if(PDFASSignParameters.Connector.SECLAYER20.equalsName(connector)) { - connectorEnum = PDFASSignParameters.Connector.SECLAYER20; - } - - if(connectorEnum == null) { - throw new ServletException( - "Invalid connector value!"); - } - - // TODO: check connector is enabled! + PdfAsHelper.checkConnectorSupported(connector, null); statisticEvent.setFilesize(inputDocument.length); statisticEvent.setProfileId(profile); - statisticEvent.setDevice(connector); + statisticEvent.setDevice(connector.toString()); PDFASSignParameters parameters = new PDFASSignParameters(); - parameters.setConnector(connectorEnum); + parameters.setConnector(connector); parameters.setPosition(position); parameters.setProfile(profile); @@ -156,8 +130,8 @@ public class JSONAPIServlet extends HttpServlet { signatureBlockParametersMap.put(values[0], values[1]); } } - }catch(Exception e){ - e.printStackTrace(); + } catch(Exception e) { + logger.warn("Failed to process JSON sbp parameter", e); } @@ -167,7 +141,7 @@ public class JSONAPIServlet extends HttpServlet { CoreSignParams coreParams = new CoreSignParams(); coreParams.setSignatureBlockParameters(signatureBlockParametersMap); - coreParams.setConnector(Connector.fromString(connector)); + coreParams.setConnector(connector); data.setCoreParams(coreParams); DocumentToSign document = new DocumentToSign(); @@ -178,8 +152,7 @@ public class JSONAPIServlet extends HttpServlet { - if (PDFASSignParameters.Connector.MOA.equals(connectorEnum) - || PDFASSignParameters.Connector.JKS.equals(connectorEnum)) { + if (!Connector.isAsynchronous(connector)) { // Plain server based signatures!! @@ -236,36 +209,8 @@ public class JSONAPIServlet extends HttpServlet { // start asynchronous signature creation - if (PDFASSignParameters.Connector.BKU.equals(connectorEnum)) { - if (WebConfiguration.getLocalBKUURL() == null) { - throw new PdfAsWebException( - "Invalid connector bku is not supported"); - } - } - - if (PDFASSignParameters.Connector.ONLINEBKU.equals(connectorEnum)) { - if (WebConfiguration.getOnlineBKUURL() == null) { - throw new PdfAsWebException( - "Invalid connector onlinebku is not supported"); - } - } - - if (PDFASSignParameters.Connector.MOBILEBKU.equals(connectorEnum)) { - if (WebConfiguration.getHandyBKUURL() == null) { - throw new PdfAsWebException( - "Invalid connector mobilebku is not supported"); - } - } - - if (PDFASSignParameters.Connector.SECLAYER20.equals(connectorEnum)) { - if (WebConfiguration.getSecurityLayer20URL() == null) { - throw new PdfAsWebException( - "Invalid connector mobilebku is not supported"); - } - } - - PdfAsHelper.startSignatureJson(request, response, getServletContext(), - connectorEnum.toString(), data); + PdfAsHelper.startSignatureJson(request, response, getServletContext(), + connector, data); JSONStartResponse jsonStartResponse = PdfAsHelper.startJsonProcess(request, response, getServletContext()); 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 index 2842c7e2..9c20e1a1 100644 --- 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 @@ -90,6 +90,7 @@ public class UIEntryPointServlet extends HttpServlet { PdfAsHelper.setStatisticEvent(req, resp, statisticEvent); Connector connector = pdfAsRequest.getCoreParams().getConnector(); + PdfAsHelper.checkConnectorSupported(connector, null); String invokeUrl = pdfAsRequest.getCoreParams().getInvokeUrl(); PdfAsHelper.setInvokeURL(req, resp, invokeUrl); @@ -125,41 +126,10 @@ public class UIEntryPointServlet extends HttpServlet { log.debug("Starting signature creation with: " + connector); // IPlainSigner signer; - if (connector.equals(Connector.BKU) - || connector.equals(Connector.ONLINEBKU) - || connector.equals(Connector.MOBILEBKU) - || connector.equals(Connector.SECLAYER20)) { + if (Connector.isAsynchronous(connector)) { // 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.getOnlineBKUURL() == null) { - throw new PdfAsWebException( - "Invalid connector onlinebku is not supported"); - } - } - - if (connector.equals(Connector.MOBILEBKU)) { - if (WebConfiguration.getHandyBKUURL() == null) { - throw new PdfAsWebException( - "Invalid connector mobilebku is not supported"); - } - } - - if (connector.equals(Connector.SECLAYER20)) { - if (WebConfiguration.getSecurityLayer20URL() == null) { - throw new PdfAsWebException( - "Invalid connector mobilebku is not supported"); - } - } - PdfAsHelper.startSignature(req, resp, getServletContext(), connector.toString(), pdfAsRequest); + PdfAsHelper.startSignature(req, resp, getServletContext(), connector, pdfAsRequest); } else { throw new PdfAsWebException("Invalid connector (" 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 667816e5..83e59706 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 @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import at.gv.egiz.pdfas.lib.api.PdfAs; import at.gv.egiz.pdfas.lib.impl.ErrorExtractor; import jakarta.jws.WebService; import jakarta.xml.ws.WebServiceException; @@ -90,28 +91,31 @@ public class PDFASSigningImpl implements PDFASSigning { log.warn("SOAP Sign Request is null!"); return null; } + if (request.getParameters() == null) { + throw new WebServiceException("SOAP Sign Request parameters are missing"); + } // map request into internal data-structure final PdfasSignRequest internalReq = buildOperationRequest(request); + val connector = internalReq.getCoreParams().getConnector(); + val keyIdentifier = internalReq.getCoreParams().getKeyIdentifier(); + final StatisticEvent statisticEvent = new StatisticEvent(); statisticEvent.setSource(Source.SOAP); statisticEvent.setOperation(Operation.SIGN); statisticEvent.setUserAgent(UserAgentFilter.getUserAgent()); statisticEvent.setProfileId(request.getParameters().getProfile()); - statisticEvent.setDevice(request.getParameters().getConnector().toString()); + if (connector != null) { + statisticEvent.setDevice(connector.toString()); + } statisticEvent.setStartNow(); PDFASSignResponse response = new PDFASSignResponse(); try { - if (request.getParameters().getConnector() == null) { - throw new WebServiceException( - "Invalid connector value!"); - } + PdfAsHelper.checkConnectorSupported(connector, keyIdentifier); - if (request.getParameters().getConnector().equals(Connector.MOA) - || request.getParameters().getConnector() - .equals(Connector.JKS)) { + if (!Connector.isAsynchronous(connector)) { // perform technical signing process final PdfasSignResponse internalResp = PdfAsHelper.synchronousServerSignature(internalReq); @@ -212,24 +216,23 @@ public class PDFASSigningImpl implements PDFASSigning { // map request into internal data-structure final PdfasSignRequest internalReq = buildOperationRequest(request); + val connector = internalReq.getCoreParams().getConnector(); + val keyIdentifier = internalReq.getCoreParams().getKeyIdentifier(); final StatisticEvent statisticEvent = new StatisticEvent(); statisticEvent.setSource(Source.SOAP); statisticEvent.setOperation(Operation.SIGNBULK); statisticEvent.setUserAgent(UserAgentFilter.getUserAgent()); - statisticEvent.setDevice(internalReq.getCoreParams().getConnector().toString()); + if (connector != null) { + statisticEvent.setDevice(connector.toString()); + } statisticEvent.setStartNow(); PdfasSignMultipleResponse response = new PdfasSignMultipleResponse(); try { - if (internalReq.getCoreParams().getConnector() == null) { - throw new WebServiceException( - "Invalid connector value!"); - } + PdfAsHelper.checkConnectorSupported(connector, keyIdentifier); - if (internalReq.getCoreParams().getConnector().equals(Connector.MOA) - || internalReq.getCoreParams().getConnector() - .equals(Connector.JKS)) { + if (!Connector.isAsynchronous(connector)) { // perform technical signing process final PdfasSignResponse internalResp = PdfAsHelper.synchronousServerSignature(internalReq); @@ -372,6 +375,9 @@ public class PDFASSigningImpl implements PDFASSigning { coreParams.setTransactionId(request.getTransactionId()); data.setCoreParams(coreParams); + if (request.getInput() == null || request.getInput().isEmpty()) { + throw new WebServiceException("SignMultipleRequest contains no input documents"); + } request.getInput().forEach(el -> { final DocumentToSign document = new DocumentToSign(); document.setInputData(el.getInputData()); |
