2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file shibsp/TransactionLog.h
24 * Formatted event record logging.
27 #if !defined (__shibsp_txlog_h__) && !defined(SHIBSP_LITE)
28 #define __shibsp_txlog_h__
30 #include <shibsp/base.h>
31 #include <xmltooling/logging.h>
32 #include <xmltooling/Lockable.h>
33 #include <xmltooling/io/GenericRequest.h>
39 namespace xmltooling {
40 class XMLTOOL_API Mutex;
45 class SAML_API AuthenticationStatement;
49 class SAML_API Response;
53 class SAML_API AuthnStatement;
54 class SAML_API NameID;
58 class SAML_API AuthnRequest;
59 class SAML_API LogoutRequest;
60 class SAML_API LogoutResponse;
61 class SAML_API StatusResponseType;
65 class SAML_API EntityDescriptor;
70 class SHIBSP_API Application;
71 class SHIBSP_API Attribute;
72 class SHIBSP_API Session;
75 * Interface to a synchronized event/audit logging object.
77 * <p>For backward compatibility, we expose a logging object directly, but
78 * new applications should rely on the Event callback API.
80 class SHIBSP_API TransactionLog : public virtual xmltooling::Lockable
82 MAKE_NONCOPYABLE(TransactionLog);
87 * @param fmt formatting string for events
88 * @param absent string to output when a field is empty
90 TransactionLog(const char* fmt=nullptr, const char* absent=nullptr);
92 virtual ~TransactionLog();
94 xmltooling::Lockable* lock();
97 /** @deprecated Logging object. */
98 xmltooling::logging::Category& log;
101 * Callback interface that outputs an event record to a stream using formatting tokens.
103 class SHIBSP_API Event {
104 MAKE_NONCOPYABLE(Event);
106 /** Function that handles a formatting token. */
107 typedef bool (*handler_fn)(const Event& e, std::ostream&);
109 /** Map of tokens to handlers. */
110 std::map<std::string, handler_fn> m_handlers;
121 * Returns a type string to be used for the log category in the event log.
123 * @return type or category for the event
125 virtual const char* getType() const=0;
128 const std::exception* m_exception;
130 /** Request object associated with event. */
131 const xmltooling::GenericRequest* m_request;
133 /** Application object associated with event. */
134 const Application* m_app;
136 /** Session identifier. */
137 const char* m_sessionID;
139 /** Peer entity associated with event. */
140 const opensaml::saml2md::EntityDescriptor* m_peer;
142 /** Protocol associated with event. */
143 const char* m_protocol;
145 /** Protocol binding associated with event. */
146 const char* m_binding;
148 /** SAML 2.0 NameID. */
149 const opensaml::saml2::NameID* m_nameID;
152 * Outputs an event record to a stream based on the defined formatting string.
154 * @param out stream to use
155 * @param field field to output
156 * @param absent string to output if the field is empty
157 * @return true iff the field was recognized and substituted
159 virtual bool write(std::ostream& out, const char* field, const char* absent) const;
163 * Write a formatted event record to the log.
164 * <p>This method is internally synchronized and the caller does <strong>NOT</strong>
165 * need to explicitly lock and unlock the object.
167 * @param e event to log
169 virtual void write(const Event& e);
172 xmltooling::Mutex* m_lock;
173 std::string m_absent;
174 std::vector<std::string> m_formatting;
177 class SHIBSP_API LoginEvent : public TransactionLog::Event
185 virtual ~LoginEvent();
187 const char* getType() const;
189 /** SAML 2.0 AuthnStatement. */
190 const opensaml::saml2::AuthnStatement* m_saml2AuthnStatement;
192 /** SAML 2.0 Response. */
193 const opensaml::saml2p::StatusResponseType* m_saml2Response;
195 /** SAML 1.x AuthnStatement. */
196 const opensaml::saml1::AuthenticationStatement* m_saml1AuthnStatement;
198 /** SAML 1.x Response. */
199 const opensaml::saml1p::Response* m_saml1Response;
201 /** Attributes associated with event. */
202 const std::vector<Attribute*>* m_attributes;
205 class SHIBSP_API LogoutEvent : public TransactionLog::Event
213 virtual ~LogoutEvent();
215 const char* getType() const;
217 /** Result of logout (local, global, partial). */
219 LOGOUT_EVENT_UNKNOWN,
220 LOGOUT_EVENT_INVALID,
226 /** SAML 2.0 Request. */
227 const opensaml::saml2p::LogoutRequest* m_saml2Request;
229 /** SAML 2.0 Response. */
230 const opensaml::saml2p::LogoutResponse* m_saml2Response;
232 /** Primary session associated with event. */
233 const Session* m_session;
235 /** All sessions associated with event. */
236 std::vector<std::string> m_sessions;
239 class SHIBSP_API AuthnRequestEvent : public TransactionLog::Event
247 virtual ~AuthnRequestEvent();
249 const char* getType() const;
251 /** SAML 2.0 Request. */
252 const opensaml::saml2p::AuthnRequest* m_saml2Request;
256 * Registers Event classes into the runtime.
258 void SHIBSP_API registerEvents();
261 #define LOGIN_EVENT "Login"
264 #define LOGOUT_EVENT "Logout"
266 /** AuthnRequest event. */
267 #define AUTHNREQUEST_EVENT "AuthnRequest"
270 #endif /* __shibsp_txlog_h__ */