Factor out RelayState recovery.
[shibboleth/cpp-sp.git] / shibsp / handler / AssertionConsumerService.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/AssertionConsumerService.h
19  * 
20  * Base class for handlers that create sessions by consuming SSO protocol responses. 
21  */
22
23 #ifndef __shibsp_acshandler_h__
24 #define __shibsp_acshandler_h__
25
26 #include <shibsp/handler/AbstractHandler.h>
27 #include <shibsp/handler/RemotedHandler.h>
28 #include <saml/binding/MessageDecoder.h>
29 #include <saml/saml2/metadata/Metadata.h>
30
31 namespace shibsp {
32
33     class SHIBSP_API ResolutionContext;
34
35 #if defined (_MSC_VER)
36     #pragma warning( push )
37     #pragma warning( disable : 4250 )
38 #endif
39
40     /**
41      * Base class for handlers that create sessions by consuming SSO protocol responses.
42      */
43     class SHIBSP_API AssertionConsumerService : public AbstractHandler, public RemotedHandler 
44     {
45     public:
46         virtual ~AssertionConsumerService();
47
48         std::pair<bool,long> run(SPRequest& request, bool isHandler=true) const;
49         void receive(DDF& in, std::ostream& out);
50
51     protected:
52         AssertionConsumerService(const DOMElement* e, log4cpp::Category& log);
53         
54         /**
55          * Implement protocol-specific handling of the incoming decoded message.
56          * 
57          * <p>The result of implementing the protocol should be an exception or
58          * the key to a newly created session.
59          * 
60          * @param application   reference to application receiving message
61          * @param httpRequest   client request that included message
62          * @param policy        the SecurityPolicy in effect, after having evaluated the message
63          * @param settings      policy configuration settings in effect
64          * @param xmlObject     a protocol-specific message object
65          * @return  the key to the newly created session
66          */
67         virtual std::string implementProtocol(
68             const Application& application,
69             const opensaml::HTTPRequest& httpRequest,
70             opensaml::SecurityPolicy& policy,
71             const PropertySet* settings,
72             const xmltooling::XMLObject& xmlObject
73             ) const=0;
74             
75         /**
76          * Enforce address checking requirements.
77          * 
78          * @param application   reference to application receiving message
79          * @param httpRequest   client request that initiated session
80          * @param issuedTo      address for which security assertion was issued
81          */
82         void checkAddress(
83             const Application& application, const opensaml::HTTPRequest& httpRequest, const char* issuedTo
84             ) const;
85         
86         /**
87          * Attempt SSO-initiated attribute resolution using the supplied information.
88          * 
89          * <p>The caller must free the returned context handle.
90          * 
91          * @param application   reference to application receiving message
92          * @param httpRequest   client request that initiated session
93          * @param issuer        source of SSO tokens
94          * @param nameid        identifier of principal
95          * @param tokens        tokens to resolve, if any
96          */
97         ResolutionContext* resolveAttributes(
98             const Application& application,
99             const opensaml::HTTPRequest& httpRequest,
100             const opensaml::saml2md::EntityDescriptor* issuer,
101             const opensaml::saml2::NameID& nameid,
102             const std::vector<const opensaml::Assertion*>* tokens=NULL
103             ) const;
104         
105     private:
106         std::string processMessage(
107             const Application& application,
108             opensaml::HTTPRequest& httpRequest,
109             std::string& providerId,
110             std::string& relayState
111             ) const;
112             
113         std::pair<bool,long> sendRedirect(
114             SPRequest& request, const char* key, const char* providerId, const char* relayState
115             ) const;
116         
117         void maintainHistory(SPRequest& request, const char* providerId, const char* cookieProps) const;
118                 
119         opensaml::MessageDecoder* m_decoder;
120         xmltooling::auto_ptr_char m_configNS;
121         xmltooling::QName m_role;
122     };
123
124 #if defined (_MSC_VER)
125     #pragma warning( pop )
126 #endif
127
128 };
129
130 #endif /* __shibsp_acshandler_h__ */