3fda7f8986f285c51573b2ed84dedb7fa7e6459d
[shibboleth/sp.git] / shibsp / handler / AbstractHandler.h
1 /*
2  *  Copyright 2001-2007 Internet2
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 /**
18  * @file shibsp/handler/AbstractHandler.h
19  * 
20  * Base class for handlers based on a DOMPropertySet. 
21  */
22
23 #ifndef __shibsp_abshandler_h__
24 #define __shibsp_abshandler_h__
25
26 #include <shibsp/handler/Handler.h>
27 #include <shibsp/util/DOMPropertySet.h>
28
29 #include <log4cpp/Category.hh>
30
31 #include <xmltooling/XMLObject.h>
32 #include <xmltooling/io/HTTPRequest.h>
33 #include <xmltooling/io/HTTPResponse.h>
34
35 namespace shibsp {
36
37     class SHIBSP_API Application;
38     class SHIBSP_API SPRequest;
39
40 #if defined (_MSC_VER)
41     #pragma warning( push )
42     #pragma warning( disable : 4250 )
43 #endif
44
45     /**
46      * Base class for handlers based on a DOMPropertySet.
47      */
48     class SHIBSP_API AbstractHandler : public virtual Handler, public DOMPropertySet
49     {
50     protected:
51         /**
52          * Constructor
53          * 
54          * @param e         DOM element to load as property set. 
55          * @param filter    optional filter controls what child elements to include as nested PropertySets
56          * @param remapper  optional map of property rename rules for legacy property support
57          */
58         AbstractHandler(
59             const xercesc::DOMElement* e,
60             log4cpp::Category& log,
61             xercesc::DOMNodeFilter* filter=NULL,
62             const std::map<std::string,std::string>* remapper=NULL
63             );
64
65 #ifndef SHIBSP_LITE
66         /**
67          * Examines a protocol response message for errors and raises an annotated exception
68          * if an error is found.
69          * 
70          * <p>The base class version understands SAML 1.x and SAML 2.0 responses.
71          * 
72          * @param response      a response message of some known protocol
73          */
74         virtual void checkError(const xmltooling::XMLObject* response) const;
75 #endif
76
77         /**
78          * Implements various mechanisms to preserve RelayState,
79          * such as cookies or StorageService-backed keys.
80          * 
81          * <p>If a supported mechanism can be identified, the input parameter will be
82          * replaced with a suitable state key.
83          * 
84          * @param application   the associated Application
85          * @param response      outgoing HTTP response
86          * @param relayState    RelayState token to supply with message
87          */
88         virtual void preserveRelayState(const Application& application, xmltooling::HTTPResponse& response, std::string& relayState) const;
89
90         /**
91          * Implements various mechanisms to recover RelayState,
92          * such as cookies or StorageService-backed keys.
93          * 
94          * <p>If a supported mechanism can be identified, the input parameter will be
95          * replaced with the recovered state information.
96          * 
97          * @param application   the associated Application
98          * @param request       incoming HTTP request
99          * @param relayState    RelayState token supplied with message
100          * @param clear         true iff the token state should be cleared
101          */
102         virtual void recoverRelayState(
103             const Application& application, xmltooling::HTTPRequest& request, std::string& relayState, bool clear=true
104             ) const;
105         
106         /** Logging object. */
107         log4cpp::Category& m_log;
108         
109     public:
110         virtual ~AbstractHandler() {}
111     };
112
113 #if defined (_MSC_VER)
114     #pragma warning( pop )
115 #endif
116
117 };
118
119 #endif /* __shibsp_abshandler_h__ */