1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.ihe.mllp.core.intercept.consumer;
17
18 import org.apache.camel.Exchange;
19 import org.apache.camel.component.mina2.Mina2Constants;
20 import org.openehealth.ipf.commons.audit.AuditContext;
21 import org.openehealth.ipf.commons.audit.model.AuditMessage;
22 import org.openehealth.ipf.commons.ihe.hl7v2.audit.MllpAuditUtils;
23 import org.openehealth.ipf.platform.camel.ihe.core.InterceptorSupport;
24 import org.openehealth.ipf.platform.camel.ihe.mllp.core.MllpAuthenticationFailure;
25 import org.openehealth.ipf.platform.camel.ihe.mllp.core.MllpTransactionEndpoint;
26
27 import java.net.InetSocketAddress;
28
29 import static java.util.Objects.requireNonNull;
30
31
32
33
34
35 public class ConsumerAuthenticationFailureInterceptor extends InterceptorSupport<MllpTransactionEndpoint<?>> {
36
37 private final AuditContext auditContext;
38
39 public ConsumerAuthenticationFailureInterceptor(AuditContext auditContext) {
40 this.auditContext = requireNonNull(auditContext);
41 }
42
43 @Override
44 public void process(Exchange exchange) throws Exception {
45 try {
46 getWrappedProcessor().process(exchange);
47 } catch (MllpAuthenticationFailure e) {
48 AuditMessage auditMessage =
49 MllpAuditUtils.auditAuthenticationNodeFailure(
50 auditContext, e.getMessage(), getRemoteAddress(exchange));
51 auditContext.audit(auditMessage);
52 throw e;
53 }
54 }
55
56 private String getRemoteAddress(Exchange exchange) {
57 InetSocketAddress address = (InetSocketAddress) exchange.getIn().getHeader(Mina2Constants.MINA_REMOTE_ADDRESS);
58 return address != null ? address.getAddress().getHostAddress() : "unknown";
59 }
60
61 }