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>
38 #include <boost/scoped_ptr.hpp>
40 namespace xmltooling {
41 class XMLTOOL_API Mutex;
46 class SAML_API AuthenticationStatement;
50 class SAML_API Response;
54 class SAML_API AuthnStatement;
55 class SAML_API NameID;
59 class SAML_API AuthnRequest;
60 class SAML_API LogoutRequest;
61 class SAML_API LogoutResponse;
62 class SAML_API StatusResponseType;
66 class SAML_API EntityDescriptor;
71 class SHIBSP_API Application;
72 class SHIBSP_API Attribute;
73 class SHIBSP_API Session;
76 * Interface to a synchronized event/audit logging object.
78 * <p>For backward compatibility, we expose a logging object directly, but
79 * new applications should rely on the Event callback API.
81 class SHIBSP_API TransactionLog : public virtual xmltooling::Lockable
83 MAKE_NONCOPYABLE(TransactionLog);
88 * @param fmt formatting string for events
89 * @param absent string to output when a field is empty
91 TransactionLog(const char* fmt=nullptr, const char* absent=nullptr);
93 virtual ~TransactionLog();
95 xmltooling::Lockable* lock();
98 /** @deprecated Logging object. */
99 xmltooling::logging::Category& log;
102 * Callback interface that outputs an event record to a stream using formatting tokens.
104 class SHIBSP_API Event {
105 MAKE_NONCOPYABLE(Event);
107 /** Function that handles a formatting token. */
108 typedef bool (*handler_fn)(const Event& e, std::ostream&);
110 /** Map of tokens to handlers. */
111 std::map<std::string, handler_fn> m_handlers;
122 * Returns a type string to be used for the log category in the event log.
124 * @return type or category for the event
126 virtual const char* getType() const=0;
129 const std::exception* m_exception;
131 /** Request object associated with event. */
132 const xmltooling::GenericRequest* m_request;
134 /** Application object associated with event. */
135 const Application* m_app;
137 /** Session identifier. */
138 const char* m_sessionID;
140 /** Peer entity associated with event. */
141 const opensaml::saml2md::EntityDescriptor* m_peer;
143 /** Protocol associated with event. */
144 const char* m_protocol;
146 /** Protocol binding associated with event. */
147 const char* m_binding;
149 /** SAML 2.0 NameID. */
150 const opensaml::saml2::NameID* m_nameID;
153 * Outputs an event record to a stream based on the defined formatting string.
155 * @param out stream to use
156 * @param field field to output
157 * @param absent string to output if the field is empty
158 * @return true iff the field was recognized and substituted
160 virtual bool write(std::ostream& out, const char* field, const char* absent) const;
164 * Write a formatted event record to the log.
165 * <p>This method is internally synchronized and the caller does <strong>NOT</strong>
166 * need to explicitly lock and unlock the object.
168 * @param e event to log
170 virtual void write(const Event& e);
173 boost::scoped_ptr<xmltooling::Mutex> m_lock;
174 std::string m_absent;
175 std::vector<std::string> m_formatting;
178 class SHIBSP_API LoginEvent : public TransactionLog::Event
186 virtual ~LoginEvent();
188 const char* getType() const;
190 /** SAML 2.0 AuthnStatement. */
191 const opensaml::saml2::AuthnStatement* m_saml2AuthnStatement;
193 /** SAML 2.0 Response. */
194 const opensaml::saml2p::StatusResponseType* m_saml2Response;
196 /** SAML 1.x AuthnStatement. */
197 const opensaml::saml1::AuthenticationStatement* m_saml1AuthnStatement;
199 /** SAML 1.x Response. */
200 const opensaml::saml1p::Response* m_saml1Response;
202 /** Attributes associated with event. */
203 const std::vector<Attribute*>* m_attributes;
206 class SHIBSP_API LogoutEvent : public TransactionLog::Event
214 virtual ~LogoutEvent();
216 const char* getType() const;
218 /** Result of logout (local, global, partial). */
220 LOGOUT_EVENT_UNKNOWN,
221 LOGOUT_EVENT_INVALID,
227 /** SAML 2.0 Request. */
228 const opensaml::saml2p::LogoutRequest* m_saml2Request;
230 /** SAML 2.0 Response. */
231 const opensaml::saml2p::LogoutResponse* m_saml2Response;
233 /** Primary session associated with event. */
234 const Session* m_session;
236 /** All sessions associated with event. */
237 std::vector<std::string> m_sessions;
240 class SHIBSP_API AuthnRequestEvent : public TransactionLog::Event
248 virtual ~AuthnRequestEvent();
250 const char* getType() const;
252 /** SAML 2.0 Request. */
253 const opensaml::saml2p::AuthnRequest* m_saml2Request;
257 * Registers Event classes into the runtime.
259 void SHIBSP_API registerEvents();
262 #define LOGIN_EVENT "Login"
265 #define LOGOUT_EVENT "Logout"
267 /** AuthnRequest event. */
268 #define AUTHNREQUEST_EVENT "AuthnRequest"
271 #endif /* __shibsp_txlog_h__ */