View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.log;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.joda.time.DateTime;
24  import org.joda.time.DateTimeZone;
25  import org.joda.time.format.DateTimeFormatter;
26  import org.joda.time.format.ISODateTimeFormat;
27  
28  /**
29   * Represents an auditable event in the system.
30   */
31  public class AuditLogEntry {
32  
33      /** Name of the Logger for the shibboleth audit log. */
34      public static final String AUDIT_LOGGER_NAME = "Shibboleth-Audit";
35      
36      /** Formatter used to convert timestamps to strings. */
37      private static DateTimeFormatter dateFormatter = ISODateTimeFormat.basicDateTimeNoMillis();
38  
39      /** UTC IS8601 timestamp of the audit event. */
40      private DateTime auditEventTime;
41  
42      /** Entity ID of the provider (message issuer). */
43      private String assertingPartyId;
44  
45      /** Entity ID of the relying party. */
46      private String relyingPartyId;
47  
48      /** URI of binding used by the relying party. */
49      private String requestBinding;
50  
51      /** URI of binding used to respond to relying party. */
52      private String responseBinding;
53  
54      /** URI of profile in use. */
55      private String messageProfile;
56  
57      /** Unique ID of the request message. */
58      private String requestId;
59  
60      /** Unqiue ID of the response message. */
61      private String responseId;
62  
63      /** Principal ID of the user the request was made about. */
64      private String principalName;
65  
66      /** URIs of the authentication methods currently active for the user. */
67      private String principalAuthenticationMethod;
68  
69      /** Internal ID of the user attributes released. */
70      private List<String> releasedAttributes;
71      
72      /** Value of the SAML name identifier. */
73      private String nameIdValue;
74  
75      /** Constructor. */
76      public AuditLogEntry() {
77          auditEventTime = new DateTime();
78          releasedAttributes = new ArrayList<String>();
79      }
80      
81      /**
82       * Gets the provider (message issuer) ID.
83       * 
84       * @return provider (message issuer) ID
85       */
86      public String getAssertingPartyId() {
87          return assertingPartyId;
88      }
89      
90      /**
91       * Gets the timestamp for this audit event.
92       * 
93       * @return timestamp for this audit event
94       */
95      public DateTime getAuditEventTime() {
96          return auditEventTime;
97      }
98  
99      /**
100      * Gets the URI of the message profile being used.
101      * 
102      * @return URI of the message profile being used
103      */
104     public String getMessageProfile() {
105         return messageProfile;
106     }
107 
108     /**
109      * Gets the value of the SAML name identifier.
110      * @return value of the SAML name identifier
111      */
112     public String getNameIdValue() {
113         return nameIdValue;
114     }
115 
116     /**
117      * Gets the authentication method, identified by their URI, used to log into the relying party.
118      * 
119      * @return authentication method, identified by their URI, used to log into the relying party
120      */
121     public String getPrincipalAuthenticationMethod() {
122         return principalAuthenticationMethod;
123     }
124 
125     /**
126      * Gets the principal ID of the user.
127      * 
128      * @return principal ID of the user
129      */
130     public String getPrincipalName() {
131         return principalName;
132     }
133 
134     /**
135      * Gets the list of internal IDs of the attributes that were released.
136      * 
137      * @return internal IDs of the attributes that were released
138      */
139     public List<String> getReleasedAttributes() {
140         return releasedAttributes;
141     }
142 
143     /**
144      * Gets the entity ID of the relying party.
145      * 
146      * @return entity ID of the relying party
147      */
148     public String getRelyingPartyId() {
149         return relyingPartyId;
150     }
151 
152     /**
153      * Gets the URI of the binding used during the request.
154      * 
155      * @return URI of the binding used during the request
156      */
157     public String getRequestBinding() {
158         return requestBinding;
159     }
160 
161     /**
162      * Gets the unique ID of the request.
163      * 
164      * @return unique ID of the request
165      */
166     public String getRequestId() {
167         return requestId;
168     }
169 
170     /**
171      * Gets the URI of the binding used during the response.
172      * 
173      * @return URI of the binding used during the response
174      */
175     public String getResponseBinding() {
176         return responseBinding;
177     }
178 
179     /**
180      * Gets the unique ID of the response message.
181      * 
182      * @return unique ID of the response message
183      */
184     public String getResponseId() {
185         return responseId;
186     }
187 
188     /**
189      * Sets the provider (message issuer) ID.
190      * 
191      * @param id provider (message issuer) ID
192      */
193     public void setAssertingPartyId(String id) {
194         assertingPartyId = id;
195     }
196 
197     /**
198      * Sets the URI of the message profile being used.
199      * 
200      * @param profileURI URI of the message profile being used
201      */
202     public void setMessageProfile(String profileURI) {
203         messageProfile = profileURI;
204     }
205 
206     /**
207      * Sets the value of the SAML name identifier.
208      * 
209      * @param value value of the SAML name identifier
210      */
211     public void setNameIdValue(String value) {
212         nameIdValue = value;
213     }
214 
215     /**
216      * Sets the authentication method, identified by their URI, used to log into the relying party.
217      * 
218      * @param method authentication method, identified by their URI, used to log into the relying party
219      */
220     public void setPrincipalAuthenticationMethod(String method) {
221         principalAuthenticationMethod = method;
222     }
223 
224     /**
225      * Sets the principal ID of the user.
226      * 
227      * @param id principal ID of the user
228      */
229     public void setPrincipalName(String id) {
230         principalName = id;
231     }
232 
233     /**
234      * Sets the entity ID of the relying party.
235      * 
236      * @param entityId entity ID of the relying party
237      */
238     public void setRelyingPartyId(String entityId) {
239         relyingPartyId = entityId;
240     }
241 
242     /**
243      * Sets the URI of the binding used during the request.
244      * 
245      * @param bindingURI URI of the binding used during the request
246      */
247     public void setRequestBinding(String bindingURI) {
248         requestBinding = bindingURI;
249     }
250 
251     /**
252      * Sets the unique ID of the request.
253      * 
254      * @param id unique ID of the request
255      */
256     public void setRequestId(String id) {
257         requestId = id;
258     }
259 
260     /**
261      * Sets the URI of the binding used during the response.
262      * 
263      * @param bindingURI URI of the binding used during the response
264      */
265     public void setResponseBinding(String bindingURI) {
266         responseBinding = bindingURI;
267     }
268 
269     /**
270      * Sets the unique ID of the response message.
271      * 
272      * @param id unique ID of the response message
273      */
274     public void setResponseId(String id) {
275         responseId = id;
276     }
277     
278     /** {@inheritDoc} */
279     public String toString() {
280         StringBuilder entryString = new StringBuilder();
281 
282         entryString.append(getAuditEventTime().toString(dateFormatter.withZone(DateTimeZone.UTC)));
283         entryString.append("|");
284 
285         if (getRequestBinding() != null) {
286             entryString.append(getRequestBinding());
287         }
288         entryString.append("|");
289 
290         if (getRequestId() != null) {
291             entryString.append(getRequestId());
292         }
293         entryString.append("|");
294 
295         entryString.append(getRelyingPartyId());
296         entryString.append("|");
297 
298         entryString.append(getMessageProfile());
299         entryString.append("|");
300 
301         entryString.append(getAssertingPartyId());
302         entryString.append("|");
303 
304         entryString.append(getResponseBinding());
305         entryString.append("|");
306 
307         entryString.append(getResponseId());
308         entryString.append("|");
309 
310         if (getPrincipalName() != null) {
311             entryString.append(getPrincipalName());
312         }
313         entryString.append("|");
314 
315         if (getPrincipalAuthenticationMethod() != null) {
316             entryString.append(getPrincipalAuthenticationMethod());
317         }
318         entryString.append("|");
319 
320         for (String attribute : getReleasedAttributes()) {
321             entryString.append(attribute);
322             entryString.append(",");
323         }
324         entryString.append("|");
325 
326         return entryString.toString();
327     }
328 }