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 org.openehealth.ipf.commons.audit.handler.AuditExceptionHandler;
20  import org.openehealth.ipf.commons.audit.marshal.SerializationStrategy;
21  import org.openehealth.ipf.commons.audit.marshal.dicom.Current;
22  import org.openehealth.ipf.commons.audit.model.AuditMessage;
23  import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
24  import org.openehealth.ipf.commons.audit.queue.AuditMessageQueue;
25  import org.openehealth.ipf.commons.audit.types.AuditSource;
26  
27  import java.net.InetAddress;
28  import java.util.stream.Stream;
29  
30  /**
31   * AuditContext is the central location where all aspects of serializing and sending out
32   * Audit messages are defined. This includes
33   * <ul>
34   * <li>whether auditing is enabled at all</li>
35   * <li>the transmission protocol (UDP, TLS, ...)</li>
36   * <li>the queue implementation (synchronous, asynchronous, ...</li>
37   * <li>the serialization strategy (e.g. which DICOM audit version shall be used)</li>
38   * <li>global parameters like source ID, enterprise ID</li>
39   * </ul>
40   *
41   * @author Christian Ohr
42   * @since 3.5
43   */
44  public interface AuditContext {
45  
46      /**
47       * @return true if auditing is enabled, false otherwise
48       */
49      boolean isAuditEnabled();
50  
51      void setAuditEnabled(boolean auditEnabled);
52  
53      /**
54       * @return hostname of the audit repository
55       */
56      String getAuditRepositoryHostName();
57  
58      /**
59       * @return address of the audit repository
60       */
61      InetAddress getAuditRepositoryAddress();
62  
63      /**
64       * @return port of the audit repository
65       */
66      int getAuditRepositoryPort();
67  
68      /**
69       * @return sending application
70       */
71      String getSendingApplication();
72  
73  
74      /**
75       * @return the wire protocol to be used
76       */
77      AuditTransmissionProtocol getAuditTransmissionProtocol();
78  
79      /**
80       * @return the queue implementation to be used
81       */
82      AuditMessageQueue getAuditMessageQueue();
83  
84      /**
85       * @return a post-processor for audit messages (defaults to a NO-OP implementation
86       */
87      default AuditMessagePostProcessor getAuditMessagePostProcessor() {
88          return AuditMessagePostProcessor.noOp();
89      }
90  
91      /**
92       * @return the serialization strategy (defaults to the latest relevant DICOM version)
93       */
94      default SerializationStrategy getSerializationStrategy() {
95          return Current.INSTANCE;
96      }
97  
98      /**
99       * Sends out the (potentially post-processed) audit messages as configured in this audit context
100      *
101      * @param messages audit messages to be sent
102      */
103     default void audit(AuditMessage... messages) {
104         getAuditMessageQueue().audit(this, Stream.of(messages)
105                 .map(getAuditMessagePostProcessor())
106                 .toArray(AuditMessage[]::new));
107     }
108 
109     /**
110      * @return Source ID attribute of the audit event
111      */
112     String getAuditSourceId();
113 
114     /**
115      * @return Enterprise site ID attribute of the audit event
116      */
117     String getAuditEnterpriseSiteId();
118 
119     /**
120      * @return type of audit source
121      */
122     AuditSource getAuditSource();
123 
124     /**
125      * @return exception handler
126      */
127     AuditExceptionHandler getAuditExceptionHandler();
128 
129     /**
130      * Determines whether participant object records shall be added to the audit message
131      * that are derived from the response of a request. This specifically applies to
132      * query results. The DICOM audit specification states that this should not be the case,
133      * however, project and legal requirements sometimes mandate that e.g. patient identifiers
134      * being retrieved shall be audited.
135      *
136      * @return true if participant object records shall be added, otherwise false
137      */
138     boolean isIncludeParticipantsFromResponse();
139 
140     static AuditContext noAudit() {
141         return DefaultAuditContext.NO_AUDIT;
142     }
143 }