aboutsummaryrefslogtreecommitdiff
path: root/modules/authmodule-eIDAS-v2
diff options
context:
space:
mode:
authorThomas <>2022-05-17 18:29:49 +0200
committerThomas <>2022-05-17 18:29:49 +0200
commitea38c3b1f06263db2c03d4ee5e7b8750380009fe (patch)
tree9ee94048d73b01881d9a8fbdce313c0afb2d413c /modules/authmodule-eIDAS-v2
parentded6dab5d1a53e10dc643aa56a819234ee086f72 (diff)
downloadNational_eIDAS_Gateway-ea38c3b1f06263db2c03d4ee5e7b8750380009fe.tar.gz
National_eIDAS_Gateway-ea38c3b1f06263db2c03d4ee5e7b8750380009fe.tar.bz2
National_eIDAS_Gateway-ea38c3b1f06263db2c03d4ee5e7b8750380009fe.zip
feat(register): inject unique transactionId as SOAP header for ZMR and SZR communication
Diffstat (limited to 'modules/authmodule-eIDAS-v2')
-rw-r--r--modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/AbstractSoapClient.java7
-rw-r--r--modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/BmiSoapTransactionHeaderInterceptor.java87
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java3
3 files changed, 95 insertions, 2 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/AbstractSoapClient.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/AbstractSoapClient.java
index a039881c..20f6d2b1 100644
--- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/AbstractSoapClient.java
+++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/AbstractSoapClient.java
@@ -183,17 +183,20 @@ public class AbstractSoapClient {
log.trace("Adding JAX-WS request/response trace handler to client: " + clientType);
List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
if (handlerList == null) {
- handlerList = new ArrayList<>();
- bindingProvider.getBinding().setHandlerChain(handlerList);
+ handlerList = new ArrayList<>();
}
+ // add unique TransactionId into SOAP header
+ handlerList.add(new BmiSoapTransactionHeaderInterceptor());
+
// add logging handler to trace messages if required
if (enableTraceLogging) {
final LoggingHandler loggingHandler = new LoggingHandler();
handlerList.add(loggingHandler);
}
+
bindingProvider.getBinding().setHandlerChain(handlerList);
}
}
diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/BmiSoapTransactionHeaderInterceptor.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/BmiSoapTransactionHeaderInterceptor.java
new file mode 100644
index 00000000..86568796
--- /dev/null
+++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/BmiSoapTransactionHeaderInterceptor.java
@@ -0,0 +1,87 @@
+package at.asitplus.eidas.specific.modules.auth.eidas.v2.clients;
+
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.apache.commons.lang3.StringUtils;
+
+import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils;
+import lombok.extern.slf4j.Slf4j;
+
+
+/**
+ * Intercepter to set unique transactionId into Apache CXF clients.
+ * @author tlenz
+ *
+ */
+@Slf4j
+public class BmiSoapTransactionHeaderInterceptor implements SOAPHandler<SOAPMessageContext> {
+ private static final String ELEMENT = "Client-Request-Id";
+
+ @Override
+ public boolean handleMessage(SOAPMessageContext context) {
+ if (((Boolean) context.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue()) {
+ if (StringUtils.isNotEmpty(TransactionIdUtils.getTransactionId())) {
+ injectTransactionId(context);
+
+ } else {
+ log.debug("No unique transactionId. Sending message without Id ...");
+
+ }
+ }
+
+ return true;
+
+ }
+
+ @Override
+ public boolean handleFault(SOAPMessageContext context) {
+ return true;
+
+ }
+
+ @Override
+ public void close(MessageContext context) {
+
+ }
+
+ @Override
+ public Set<QName> getHeaders() {
+ return null;
+
+ }
+
+ private void injectTransactionId(SOAPMessageContext context) {
+ try {
+ SOAPMessage message = context.getMessage();
+ SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
+ SOAPFactory soapFactory = SOAPFactory.newInstance();
+
+ // create header element
+ SOAPElement transactionIdElm = soapFactory.createElement(ELEMENT);
+ transactionIdElm.setTextContent(TransactionIdUtils.getTransactionId());
+
+ // inject header
+ SOAPHeader header = envelope.getHeader();
+ if (header == null) {
+ header = envelope.addHeader();
+
+ }
+ header.addChildElement(transactionIdElm);
+
+ } catch (Exception e) {
+ log.warn("Can NOT inject TransactionId into SOAP message. Sending message without Id ...", e);
+
+ }
+ }
+
+}
diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java
index cada6f40..cb9df7e5 100644
--- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java
+++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java
@@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.List;
+import java.util.UUID;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
@@ -29,6 +30,7 @@ import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonSuchenRequest;
import at.gv.e_government.reference.namespace.persondata.de._20040201.NatuerlichePersonTyp;
import at.gv.e_government.reference.namespace.persondata.de._20040201.PersonenNameTyp;
import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
@@ -199,6 +201,7 @@ public class ZmrClientProductionTest {
@Test
public void updateZmrEntryTestIdentity() throws EidasSAuthenticationException {
+ TransactionIdUtils.setTransactionId(UUID.randomUUID().toString());
final String personalIdentifier = "7cEYSvKZasdfsafsaf4CDVzNT4E7cjkU4Vq";
final String cc = "EE";