View Javadoc
1   /*
2    * Copyright 2009 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  package org.openehealth.ipf.commons.ihe.ws.cxf.audit;
17  
18  import lombok.Getter;
19  import lombok.Setter;
20  import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
21  import org.openehealth.ipf.commons.audit.utils.AuditUtils;
22  import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset;
23  import org.openehealth.ipf.commons.ihe.ws.cxf.payload.StringPayloadHolder;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import static org.openehealth.ipf.commons.ihe.ws.cxf.payload.StringPayloadHolder.PayloadType.SOAP_BODY;
29  
30  
31  /**
32   * A data structure that contains various ATNA audit information pieces
33   * common for all Web Service-based IHE transactions.
34   * <p>
35   * These pieces are stored and used by corresponding CXF interceptors
36   * and transaction-specific audit strategies.
37   *
38   * @author Dmytro Rud
39   */
40  public class WsAuditDataset extends AuditDataset {
41  
42      private static final long serialVersionUID = 7940196804508126576L;
43  
44      /**
45       * Client user ID (WS-Addressing &lt;Reply-To&gt; header).
46       */
47      @Getter
48      @Setter
49      private String sourceUserId;
50  
51      /**
52       * Server user ID (SOAP endpoint)
53       */
54      @Getter
55      @Setter
56      private String destinationUserId;
57  
58      /**
59       * Request SOAP Body (XML) payload.
60       */
61      @Getter
62      private String requestPayload;
63  
64      /**
65       * IDs and real-world names of human users.
66       */
67      @Getter
68      private final List<HumanUser> humanUsers = new ArrayList<>();
69  
70      /**
71       * Client IP address.
72       */
73      @Getter
74      @Setter
75      private String clientIpAddress;
76  
77      /**
78       * Purposes of use, see ITI TF-2a section 3.20.7.8 and ITI TF-2b section 3.40.4.1.2.3.
79       */
80      @Getter
81      @Setter
82      private PurposeOfUse[] purposesOfUse;
83  
84      /**
85       * Patient ID from XUA token, see ITI TF-2b Section 3.40.4.1.2.2.1.
86       */
87      @Getter
88      @Setter
89      private String xuaPatientId;
90  
91      /**
92       * Local address
93       */
94      @Setter
95      private String localAddress;
96  
97      /**
98       * Remote address
99       */
100     @Setter
101     @Getter
102     private String remoteAddress;
103 
104     @Setter
105     private boolean sourceUserIsRequestor = true;
106 
107     /**
108      * Constructor.
109      *
110      * @param serverSide specifies whether this audit dataset will be used on the
111      *                   server side (<code>true</code>) or on the client side (
112      *                   <code>false</code>)
113      */
114     public WsAuditDataset(boolean serverSide) {
115         super(serverSide);
116     }
117 
118     /**
119      * Sets the request SOAP Body (XML) payload.
120      *
121      * @param requestPayload SOAP Body (XML) payload.
122      */
123     public void setRequestPayload(String requestPayload) {
124         this.requestPayload = requestPayload;
125     }
126 
127     /**
128      * Sets the request SOAP Body (XML) payload.
129      *
130      * @param payloadHolder POJO containing SOAP Body (XML) payload.
131      */
132     public void setRequestPayload(StringPayloadHolder payloadHolder) {
133         this.requestPayload = (payloadHolder != null) ? payloadHolder.get(SOAP_BODY) : null;
134     }
135 
136     /**
137      * @return The machine name or IP address
138      */
139     public String getLocalAddress() {
140         return localAddress != null ? localAddress : AuditUtils.getLocalIPAddress();
141     }
142 
143     @Override
144     public boolean isSourceUserIsRequestor() {
145         return sourceUserIsRequestor && super.isSourceUserIsRequestor();
146     }
147 }