2 * Copyright 2001-2010 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>
32 #include <xmltooling/logging.h>
36 class SAML_API MessageEncoder;
38 class SAML_API RoleDescriptor;
41 class SAML_API StatusResponseType;
46 namespace xmltooling {
47 class XMLTOOL_API XMLObject;
52 class SHIBSP_API Application;
54 #if defined (_MSC_VER)
55 #pragma warning( push )
56 #pragma warning( disable : 4250 )
60 * Base class for handlers based on a DOMPropertySet.
62 class SHIBSP_API AbstractHandler : public virtual Handler, public DOMPropertySet
68 * @param e DOM element to load as property set.
69 * @param log logging category to use
70 * @param filter optional filter controls what child elements to include as nested PropertySets
71 * @param remapper optional map of property rename rules for legacy property support
74 const xercesc::DOMElement* e,
75 xmltooling::logging::Category& log,
76 xercesc::DOMNodeFilter* filter=nullptr,
77 const std::map<std::string,std::string>* remapper=nullptr
80 void log(SPRequest::SPLogLevel level, const std::string& msg) const;
84 * Examines a protocol response message for errors and raises an annotated exception
85 * if an error is found.
87 * <p>The base class version understands SAML 1.x and SAML 2.0 responses.
89 * @param response a response message of some known protocol
90 * @param role issuer of message
92 virtual void checkError(
93 const xmltooling::XMLObject* response,
94 const opensaml::saml2md::RoleDescriptor* role=nullptr
98 * Prepares Status information in a SAML 2.0 response.
100 * @param response SAML 2.0 response message
101 * @param code SAML status code
102 * @param subcode optional SAML substatus code
103 * @param msg optional message to pass back
106 opensaml::saml2p::StatusResponseType& response, const XMLCh* code, const XMLCh* subcode=nullptr, const char* msg=nullptr
110 * Encodes and sends SAML 2.0 message, optionally signing it in the process.
111 * If the method returns, the message MUST NOT be freed by the caller.
113 * @param encoder the MessageEncoder to use
114 * @param msg the message to send
115 * @param relayState any RelayState to include with the message
116 * @param destination location to send message, if not a backchannel response
117 * @param role recipient of message, if known
118 * @param application the Application sending the message
119 * @param httpResponse channel for sending message
120 * @param signIfPossible true iff signing should be attempted regardless of "signing" property
121 * @return the result of sending the message using the encoder
124 const opensaml::MessageEncoder& encoder,
125 xmltooling::XMLObject* msg,
126 const char* relayState,
127 const char* destination,
128 const opensaml::saml2md::RoleDescriptor* role,
129 const Application& application,
130 xmltooling::HTTPResponse& httpResponse,
131 bool signIfPossible=false
136 * Implements a mechanism to preserve form post data.
138 * @param application the associated Application
139 * @param request incoming HTTP request
140 * @param response outgoing HTTP response
141 * @param relayState relay state information attached to current sequence, if any
143 virtual void preservePostData(
144 const Application& application,
145 const xmltooling::HTTPRequest& request,
146 xmltooling::HTTPResponse& response,
147 const char* relayState
151 * Implements storage service and cookie mechanism to recover PostData.
153 * <p>If a supported mechanism can be identified, the return value will be
154 * the recovered state information.
156 * @param application the associated Application
157 * @param request incoming HTTP request
158 * @param response outgoing HTTP response
159 * @param relayState relay state information attached to current sequence, if any
160 * @return recovered form post data associated with request as a DDF list of string members
162 virtual DDF recoverPostData(
163 const Application& application,
164 const xmltooling::HTTPRequest& request,
165 xmltooling::HTTPResponse& response,
166 const char* relayState
170 * Post a redirect response with post data.
172 * @param application the associated Application
173 * @param response outgoing HTTP response
174 * @param url action url for the form
175 * @param postData list of parameters to load into the form, as DDF string members
177 virtual long sendPostResponse(
178 const Application& application,
179 xmltooling::HTTPResponse& response,
185 * Bitmask of property sources to read from
186 * (request query parameter, request mapper, fixed handler property).
188 enum PropertySourceTypes {
189 HANDLER_PROPERTY_REQUEST = 1,
190 HANDLER_PROPERTY_MAP = 2,
191 HANDLER_PROPERTY_FIXED = 4,
192 HANDLER_PROPERTY_ALL = 255
195 using DOMPropertySet::getBool;
196 using DOMPropertySet::getString;
197 using DOMPropertySet::getUnsignedInt;
198 using DOMPropertySet::getInt;
201 * Returns a boolean-valued property.
203 * @param name property name
204 * @param request reference to incoming request
205 * @param type bitmask of property sources to use
206 * @return a pair consisting of a nullptr indicator and the property value iff the indicator is true
208 std::pair<bool,bool> getBool(const char* name, const SPRequest& request, unsigned int type=HANDLER_PROPERTY_ALL) const;
211 * Returns a string-valued property.
213 * @param name property name
214 * @param request reference to incoming request
215 * @param type bitmask of property sources to use
216 * @return a pair consisting of a nullptr indicator and the property value iff the indicator is true
218 std::pair<bool,const char*> getString(const char* name, const SPRequest& request, unsigned int type=HANDLER_PROPERTY_ALL) const;
221 * Returns an unsigned integer-valued property.
223 * @param name property name
224 * @param request reference to incoming request
225 * @param type bitmask of property sources to use
226 * @return a pair consisting of a nullptr indicator and the property value iff the indicator is true
228 std::pair<bool,unsigned int> getUnsignedInt(const char* name, const SPRequest& request, unsigned int type=HANDLER_PROPERTY_ALL) const;
231 * Returns an integer-valued property.
233 * @param name property name
234 * @param request reference to incoming request
235 * @param type bitmask of property sources to use
236 * @return a pair consisting of a nullptr indicator and the property value iff the indicator is true
238 std::pair<bool,int> getInt(const char* name, const SPRequest& request, unsigned int type=HANDLER_PROPERTY_ALL) const;
240 /** Logging object. */
241 xmltooling::logging::Category& m_log;
243 /** Configuration namespace for custom properties. */
244 xmltooling::auto_ptr_char m_configNS;
247 virtual ~AbstractHandler();
250 std::pair<std::string,const char*> getPostCookieNameProps(const Application& app, const char* relayState) const;
251 DDF getPostData(const Application& application, const xmltooling::HTTPRequest& request) const;
254 #if defined (_MSC_VER)
255 #pragma warning( pop )
260 #endif /* __shibsp_abshandler_h__ */