View Javadoc
1   /*
2    * Copyright 2017 the original author or authors.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package org.openehealth.ipf.commons.audit;
18  
19  import lombok.Getter;
20  import lombok.Setter;
21  import org.openehealth.ipf.commons.audit.codes.AuditSourceType;
22  import org.openehealth.ipf.commons.audit.handler.AuditExceptionHandler;
23  import org.openehealth.ipf.commons.audit.handler.LoggingAuditExceptionHandler;
24  import org.openehealth.ipf.commons.audit.marshal.SerializationStrategy;
25  import org.openehealth.ipf.commons.audit.marshal.dicom.Current;
26  import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
27  import org.openehealth.ipf.commons.audit.protocol.TLSSyslogSenderImpl;
28  import org.openehealth.ipf.commons.audit.protocol.UDPSyslogSenderImpl;
29  import org.openehealth.ipf.commons.audit.protocol.VertxTLSSyslogSenderImpl;
30  import org.openehealth.ipf.commons.audit.queue.AuditMessageQueue;
31  import org.openehealth.ipf.commons.audit.queue.SynchronousAuditMessageQueue;
32  import org.openehealth.ipf.commons.audit.types.AuditSource;
33  import org.openehealth.ipf.commons.audit.utils.AuditUtils;
34  
35  import java.net.InetAddress;
36  import java.net.UnknownHostException;
37  
38  /**
39   * @author Christian Ohr
40   * @since 3.5
41   */
42  public class DefaultAuditContext implements AuditContext {
43  
44      static final AuditContext NO_AUDIT = new DefaultAuditContext();
45  
46      @Getter
47      private String auditRepositoryHostName = "localhost";
48  
49      @Getter
50      private InetAddress auditRepositoryAddress = AuditUtils.localInetAddress().orElse(null);
51  
52      @Getter @Setter
53      private int auditRepositoryPort = 514;
54  
55      @Getter @Setter
56      private boolean auditEnabled = false;
57  
58      @Getter @Setter
59      private AuditTransmissionProtocol auditTransmissionProtocol = new UDPSyslogSenderImpl();
60  
61      @Getter @Setter
62      private AuditMessageQueue auditMessageQueue = new SynchronousAuditMessageQueue();
63  
64      @Getter @Setter
65      private String sendingApplication = "IPF";
66  
67      @Getter @Setter
68      private String auditSourceId = "IPF";
69  
70      @Getter @Setter
71      private String auditEnterpriseSiteId = "IPF";
72  
73      @Getter @Setter
74      private AuditSource auditSource = AuditSourceType.Other;
75  
76      @Getter @Setter
77      private SerializationStrategy serializationStrategy = new Current();
78  
79      @Getter @Setter
80      private AuditMessagePostProcessor auditMessagePostProcessor = AuditMessagePostProcessor.noOp();
81  
82      @Getter @Setter
83      private AuditExceptionHandler auditExceptionHandler = new LoggingAuditExceptionHandler();
84  
85      @Getter @Setter
86      private boolean includeParticipantsFromResponse = false;
87  
88      public void setAuditRepositoryHost(String auditRepositoryHost) throws UnknownHostException {
89          this.auditRepositoryHostName = auditRepositoryHost;
90          this.auditRepositoryAddress = InetAddress.getByName(auditRepositoryHost);
91      }
92  
93      public String getAuditRepositoryTransport() {
94          return auditTransmissionProtocol.getTransportName();
95      }
96  
97      public void setAuditRepositoryTransport(String transport) {
98          switch (transport) {
99              case "UDP": setAuditTransmissionProtocol(new UDPSyslogSenderImpl()); break;
100             case "TLS": setAuditTransmissionProtocol(new TLSSyslogSenderImpl()); break;
101             case "NIO-TLS": setAuditTransmissionProtocol(new VertxTLSSyslogSenderImpl()); break;
102             default: throw new IllegalArgumentException("Unknown transport :" + transport);
103         }
104     }
105 
106 }