2 * Copyright 2001-2009 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file shibsp/handler/AbstractHandler.h
20 * Base class for handlers based on a DOMPropertySet.
23 #ifndef __shibsp_abshandler_h__
24 #define __shibsp_abshandler_h__
26 #include <shibsp/handler/Handler.h>
27 #include <shibsp/remoting/ddf.h>
28 #include <shibsp/util/DOMPropertySet.h>
31 # include <saml/binding/MessageEncoder.h>
32 # include <saml/saml2/core/Protocols.h>
34 #include <xmltooling/logging.h>
35 #include <xmltooling/XMLObject.h>
36 #include <xmltooling/io/HTTPRequest.h>
37 #include <xmltooling/io/HTTPResponse.h>
41 class SHIBSP_API Application;
42 class SHIBSP_API SPRequest;
44 #if defined (_MSC_VER)
45 #pragma warning( push )
46 #pragma warning( disable : 4250 )
50 * Base class for handlers based on a DOMPropertySet.
52 class SHIBSP_API AbstractHandler : public virtual Handler, public DOMPropertySet
58 * @param e DOM element to load as property set.
59 * @param log logging category to use
60 * @param filter optional filter controls what child elements to include as nested PropertySets
61 * @param remapper optional map of property rename rules for legacy property support
64 const xercesc::DOMElement* e,
65 xmltooling::logging::Category& log,
66 xercesc::DOMNodeFilter* filter=NULL,
67 const std::map<std::string,std::string>* remapper=NULL
72 * Examines a protocol response message for errors and raises an annotated exception
73 * if an error is found.
75 * <p>The base class version understands SAML 1.x and SAML 2.0 responses.
77 * @param response a response message of some known protocol
78 * @param role issuer of message
80 virtual void checkError(
81 const xmltooling::XMLObject* response,
82 const opensaml::saml2md::RoleDescriptor* role=NULL
86 * Prepares Status information in a SAML 2.0 response.
88 * @param response SAML 2.0 response message
89 * @param code SAML status code
90 * @param subcode optional SAML substatus code
91 * @param msg optional message to pass back
94 opensaml::saml2p::StatusResponseType& response, const XMLCh* code, const XMLCh* subcode=NULL, const char* msg=NULL
98 * Encodes and sends SAML 2.0 message, optionally signing it in the process.
99 * If the method returns, the message MUST NOT be freed by the caller.
101 * @param encoder the MessageEncoder to use
102 * @param msg the message to send
103 * @param relayState any RelayState to include with the message
104 * @param destination location to send message, if not a backchannel response
105 * @param role recipient of message, if known
106 * @param application the Application sending the message
107 * @param httpResponse channel for sending message
108 * @param signIfPossible true iff signing should be attempted regardless of "signing" property
109 * @return the result of sending the message using the encoder
112 const opensaml::MessageEncoder& encoder,
113 xmltooling::XMLObject* msg,
114 const char* relayState,
115 const char* destination,
116 const opensaml::saml2md::RoleDescriptor* role,
117 const Application& application,
118 xmltooling::HTTPResponse& httpResponse,
119 bool signIfPossible=false
124 * Implements various mechanisms to preserve RelayState,
125 * such as cookies or StorageService-backed keys.
127 * <p>If a supported mechanism can be identified, the input parameter will be
128 * replaced with a suitable state key.
130 * @param application the associated Application
131 * @param response outgoing HTTP response
132 * @param relayState RelayState token to supply with message
134 virtual void preserveRelayState(
135 const Application& application, xmltooling::HTTPResponse& response, std::string& relayState
139 * Implements various mechanisms to recover RelayState,
140 * such as cookies or StorageService-backed keys.
142 * <p>If a supported mechanism can be identified, the input parameter will be
143 * replaced with the recovered state information.
145 * @param application the associated Application
146 * @param request incoming HTTP request
147 * @param response outgoing HTTP response
148 * @param relayState RelayState token supplied with message
149 * @param clear true iff the token state should be cleared
151 virtual void recoverRelayState(
152 const Application& application,
153 const xmltooling::HTTPRequest& request,
154 xmltooling::HTTPResponse& response,
155 std::string& relayState,
160 * Implements a mechanism to preserve form post data.
162 * @param application the associated Application
163 * @param request incoming HTTP request
164 * @param response outgoing HTTP response
165 * @param relayState relay state information attached to current sequence, if any
167 virtual void preservePostData(
168 const Application& application,
169 const xmltooling::HTTPRequest& request,
170 xmltooling::HTTPResponse& response,
171 const char* relayState
175 * Implements storage service and cookie mechanism to recover PostData.
177 * <p>If a supported mechanism can be identified, the return value will be
178 * the recovered state information.
180 * @param application the associated Application
181 * @param request incoming HTTP request
182 * @param response outgoing HTTP response
183 * @param relayState relay state information attached to current sequence, if any
184 * @return recovered form post data associated with request as a DDF list of string members
186 virtual DDF recoverPostData(
187 const Application& application,
188 const xmltooling::HTTPRequest& request,
189 xmltooling::HTTPResponse& response,
190 const char* relayState
194 * Post a redirect response with post data.
196 * @param application the associated Application
197 * @param response outgoing HTTP response
198 * @param request incoming HTTP request
199 * @param url action url for the form
200 * @param postData list of parameters to load into the form, as DDF string members
202 virtual long sendPostResponse(
203 const Application& application,
204 xmltooling::HTTPResponse& httpResponse,
209 /** Logging object. */
210 xmltooling::logging::Category& m_log;
212 /** Configuration namespace for custom properties. */
213 xmltooling::auto_ptr_char m_configNS;
216 virtual ~AbstractHandler() {}
219 std::pair<std::string,const char*> getPostCookieNameProps(const Application& app, const char* relayState) const;
220 DDF getPostData(const Application& application, const xmltooling::HTTPRequest& request) const;
223 #if defined (_MSC_VER)
224 #pragma warning( pop )
229 #endif /* __shibsp_abshandler_h__ */