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      /** Constructor. */
72      public AuditLogEntry() {
73          auditEventTime = new DateTime();
74          releasedAttributes = new ArrayList<String>();
75      }
76  
77      /**
78       * Gets the URI of the message profile being used.
79       * 
80       * @return URI of the message profile being used
81       */
82      public String getMessageProfile() {
83          return messageProfile;
84      }
85  
86      /**
87       * Sets the URI of the message profile being used.
88       * 
89       * @param profileURI URI of the message profile being used
90       */
91      public void setMessageProfile(String profileURI) {
92          messageProfile = profileURI;
93      }
94  
95      /**
96       * Gets the authentication method, identified by their URI, used to log into the relying party.
97       * 
98       * @return authentication method, identified by their URI, used to log into the relying party
99       */
100     public String getPrincipalAuthenticationMethod() {
101         return principalAuthenticationMethod;
102     }
103 
104     /**
105      * Sets the authentication method, identified by their URI, used to log into the relying party.
106      * 
107      * @param method authentication method, identified by their URI, used to log into the relying party
108      */
109     public void setPrincipalAuthenticationMethod(String method) {
110         principalAuthenticationMethod = method;
111     }
112 
113     /**
114      * Gets the principal ID of the user.
115      * 
116      * @return principal ID of the user
117      */
118     public String getPrincipalName() {
119         return principalName;
120     }
121 
122     /**
123      * Sets the principal ID of the user.
124      * 
125      * @param id principal ID of the user
126      */
127     public void setPrincipalName(String id) {
128         principalName = id;
129     }
130 
131     /**
132      * Gets the provider (message issuer) ID.
133      * 
134      * @return provider (message issuer) ID
135      */
136     public String getAssertingPartyId() {
137         return assertingPartyId;
138     }
139 
140     /**
141      * Sets the provider (message issuer) ID.
142      * 
143      * @param id provider (message issuer) ID
144      */
145     public void setAssertingPartyId(String id) {
146         assertingPartyId = id;
147     }
148 
149     /**
150      * Gets the list of internal IDs of the attributes that were released.
151      * 
152      * @return internal IDs of the attributes that were released
153      */
154     public List<String> getReleasedAttributes() {
155         return releasedAttributes;
156     }
157 
158     /**
159      * Gets the entity ID of the relying party.
160      * 
161      * @return entity ID of the relying party
162      */
163     public String getRelyingPartyId() {
164         return relyingPartyId;
165     }
166 
167     /**
168      * Sets the entity ID of the relying party.
169      * 
170      * @param entityId entity ID of the relying party
171      */
172     public void setRelyingPartyId(String entityId) {
173         relyingPartyId = entityId;
174     }
175 
176     /**
177      * Gets the URI of the binding used during the request.
178      * 
179      * @return URI of the binding used during the request
180      */
181     public String getRequestBinding() {
182         return requestBinding;
183     }
184 
185     /**
186      * Sets the URI of the binding used during the request.
187      * 
188      * @param bindingURI URI of the binding used during the request
189      */
190     public void setRequestBinding(String bindingURI) {
191         requestBinding = bindingURI;
192     }
193 
194     /**
195      * Gets the unique ID of the request.
196      * 
197      * @return unique ID of the request
198      */
199     public String getRequestId() {
200         return requestId;
201     }
202 
203     /**
204      * Sets the unique ID of the request.
205      * 
206      * @param id unique ID of the request
207      */
208     public void setRequestId(String id) {
209         requestId = id;
210     }
211 
212     /**
213      * Gets the URI of the binding used during the response.
214      * 
215      * @return URI of the binding used during the response
216      */
217     public String getResponseBinding() {
218         return responseBinding;
219     }
220 
221     /**
222      * Sets the URI of the binding used during the response.
223      * 
224      * @param bindingURI URI of the binding used during the response
225      */
226     public void setResponseBinding(String bindingURI) {
227         responseBinding = bindingURI;
228     }
229 
230     /**
231      * Gets the unique ID of the response message.
232      * 
233      * @return unique ID of the response message
234      */
235     public String getResponseId() {
236         return responseId;
237     }
238 
239     /**
240      * Sets the unique ID of the response message.
241      * 
242      * @param id unique ID of the response message
243      */
244     public void setResponseId(String id) {
245         responseId = id;
246     }
247 
248     /**
249      * Gets the timestamp for this audit event.
250      * 
251      * @return timestamp for this audit event
252      */
253     public DateTime getAuditEventTime() {
254         return auditEventTime;
255     }
256     
257     /** {@inheritDoc} */
258     public String toString() {
259         StringBuilder entryString = new StringBuilder();
260 
261         entryString.append(getAuditEventTime().toString(dateFormatter.withZone(DateTimeZone.UTC)));
262         entryString.append("|");
263 
264         if (getRequestBinding() != null) {
265             entryString.append(getRequestBinding());
266         }
267         entryString.append("|");
268 
269         if (getRequestId() != null) {
270             entryString.append(getRequestId());
271         }
272         entryString.append("|");
273 
274         entryString.append(getRelyingPartyId());
275         entryString.append("|");
276 
277         entryString.append(getMessageProfile());
278         entryString.append("|");
279 
280         entryString.append(getAssertingPartyId());
281         entryString.append("|");
282 
283         entryString.append(getResponseBinding());
284         entryString.append("|");
285 
286         entryString.append(getResponseId());
287         entryString.append("|");
288 
289         if (getPrincipalName() != null) {
290             entryString.append(getPrincipalName());
291         }
292         entryString.append("|");
293 
294         if (getPrincipalAuthenticationMethod() != null) {
295             entryString.append(getPrincipalAuthenticationMethod());
296         }
297         entryString.append("|");
298 
299         for (String attribute : getReleasedAttributes()) {
300             entryString.append(attribute);
301             entryString.append(",");
302         }
303         entryString.append("|");
304 
305         return entryString.toString();
306     }
307 }