diff options
author | Thomas <> | 2023-03-23 17:25:56 +0100 |
---|---|---|
committer | Thomas <> | 2023-06-05 16:55:41 +0200 |
commit | 369f5e1eae4da0545145c1b17d6850647287f367 (patch) | |
tree | f3b839c5fdf99d330db73562ae2aaac41de022f6 /modules | |
parent | bebb8669ab6737fe852b0c1bf4b98d4a22573537 (diff) | |
download | National_eIDAS_Gateway-369f5e1eae4da0545145c1b17d6850647287f367.tar.gz National_eIDAS_Gateway-369f5e1eae4da0545145c1b17d6850647287f367.tar.bz2 National_eIDAS_Gateway-369f5e1eae4da0545145c1b17d6850647287f367.zip |
feat(matching): log BM.I specific response headers 'txId' and 'pvp-txId'
Diffstat (limited to 'modules')
3 files changed, 70 insertions, 20 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 20f6d2b1..593a7631 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 @@ -188,7 +188,7 @@ public class AbstractSoapClient { } // add unique TransactionId into SOAP header - handlerList.add(new BmiSoapTransactionHeaderInterceptor()); + handlerList.add(new BmiSoapTransactionHeaderInterceptor(clientType)); // add logging handler to trace messages if required if (enableTraceLogging) { 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 index d1de827b..de18aff5 100644 --- 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 @@ -1,5 +1,7 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.clients; +import java.util.List; +import java.util.Map; import java.util.Set; import javax.xml.namespace.QName; @@ -13,6 +15,9 @@ import javax.xml.ws.handler.soap.SOAPHandler; import javax.xml.ws.handler.soap.SOAPMessageContext; import org.apache.commons.lang3.StringUtils; +import org.apache.cxf.message.Message; + +import com.google.common.collect.Lists; import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils; import lombok.extern.slf4j.Slf4j; @@ -25,15 +30,31 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j public class BmiSoapTransactionHeaderInterceptor implements SOAPHandler<SOAPMessageContext> { + private static final String AUTH_NS = "http://schemas.xmlsoap.org/ws/2002/04/secext"; private static final String AUTH_PREFIX = "wss"; private static final String AUTH_ELEMENT = "Security"; - - + private static final String TRANS_ID_NS = "http://egov.gv.at/pvp1.xsd"; private static final String TRANS_IDPREFIX = "pvp"; private static final String TRANS_ID_ELEMENT = "Client-Request-Id"; + private static final String HEADER_TXID = "txid"; + private static final String HEADER_PVP_TXID = "pvp-txid"; + private static final String HEADER_MSG_NOT_SET = "NOT-set"; + + private String clientName; + + /** + * BM.I specific header interceptor. + * + * @param clientType Name of the SOAP client + */ + public BmiSoapTransactionHeaderInterceptor(String clientType) { + this.clientName = clientType; + + } + @Override public boolean handleMessage(SOAPMessageContext context) { if (((Boolean) context.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue()) { @@ -43,8 +64,15 @@ public class BmiSoapTransactionHeaderInterceptor implements SOAPHandler<SOAPMess } else { log.debug("No unique transactionId. Sending message without Id ..."); - } - } + } + + } else { + final Map<String, List<?>> headers = (Map<String, List<?>>) context.get(Message.PROTOCOL_HEADERS); + log.info("response for SOAP client: {} with {}:{} and {}:{}", clientName, + HEADER_TXID, extractHeaderValue(headers, HEADER_TXID), + HEADER_PVP_TXID, extractHeaderValue(headers, HEADER_PVP_TXID)); + + } return true; @@ -95,4 +123,10 @@ public class BmiSoapTransactionHeaderInterceptor implements SOAPHandler<SOAPMess } } + private String extractHeaderValue(Map<String, List<?>> headers, String headerName) { + List<?> value = headers.getOrDefault(headerName, Lists.newArrayList(HEADER_MSG_NOT_SET)); + return value.isEmpty() ? HEADER_MSG_NOT_SET : value.get(0).toString(); + + } + }
\ No newline at end of file diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java index 10aa020d..bbb245f1 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java @@ -24,8 +24,12 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.http.client.HttpClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpRequest; import org.springframework.http.MediaType; +import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; @@ -126,6 +130,10 @@ public class ErnpRestClient implements IErnpClient { // ERnP person type that indicates mark a person as ZMR entry private static final String ERNP_RESPONSE_OPERATION_ZMR_FORWARD = "PersonUebernehmen"; + private static final String HEADER_TXID = "txid"; + private static final String HEADER_PVP_TXID = "pvp-txid"; + private static final String HEADER_MSG_NOT_SET = "NOT-set"; + @Autowired IConfiguration basicConfig; @Autowired @@ -886,25 +894,33 @@ public class ErnpRestClient implements IErnpClient { final RestTemplate springClient = new RestTemplate(requestFactory); springClient.setErrorHandler(buildErrorHandler()); springClient.getMessageConverters().add(0, buildCustomJacksonObjectMapper()); - // springClient.getInterceptors().add(buildTransactionIdInterceptor()); + springClient.setInterceptors(Collections.singletonList(buildTransactionIdInterceptor())); return springClient; } - // private ClientHttpRequestInterceptor buildTransactionIdInterceptor() { - // return new ClientHttpRequestInterceptor() { - // - // @Override - // public ClientHttpResponse intercept(HttpRequest request, byte[] body, - // ClientHttpRequestExecution execution) - // throws IOException { - // request.getHeaders().add("dfafsafafsaf", - // TransactionIdUtils.getTransactionId()); - // return execution.execute(request, body); - // - // } - // }; - // } + private ClientHttpRequestInterceptor buildTransactionIdInterceptor() { + return new ClientHttpRequestInterceptor() { + + @Override + public ClientHttpResponse intercept(HttpRequest request, byte[] body, + ClientHttpRequestExecution execution) throws IOException { + ClientHttpResponse response = execution.execute(request, body); + + log.info("response for SOAP client: {} with {}:{} and {}:{}", FRIENDLYNAME_HTTP_CLIENT, + HEADER_TXID, extractHeaderValue(response.getHeaders(), HEADER_TXID), + HEADER_PVP_TXID, extractHeaderValue(response.getHeaders(), HEADER_PVP_TXID)); + return response; + + } + + private String extractHeaderValue(HttpHeaders headers, String headerName) { + List<String> value = headers.get(headerName); + return value == null || value.isEmpty() ? HEADER_MSG_NOT_SET : value.get(0); + + } + }; + } private HttpMessageConverter<?> buildCustomJacksonObjectMapper() { final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |