View Javadoc

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