First set of logout base classes and non-building draft of SP-initiated logout.
[shibboleth/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 #ifndef SHIBSP_LITE
29 # include <saml/binding/MessageDecoder.h>
30 # include <saml/saml2/metadata/Metadata.h>
31 #endif
32 #include <xmltooling/unicode.h>
33
34 namespace shibsp {
35
36     class SHIBSP_API Attribute;
37     class SHIBSP_API ResolutionContext;
38
39 #if defined (_MSC_VER)
40     #pragma warning( push )
41     #pragma warning( disable : 4250 )
42 #endif
43
44     /**
45      * Base class for handlers that create sessions by consuming SSO protocol responses.
46      */
47     class SHIBSP_API AssertionConsumerService : public AbstractHandler, public RemotedHandler 
48     {
49     public:
50         virtual ~AssertionConsumerService();
51
52         std::pair<bool,long> run(SPRequest& request, bool isHandler=true) const;
53         void receive(DDF& in, std::ostream& out);
54
55     protected:
56         /**
57          * Constructor
58          * 
59          * @param e     root of DOM configuration
60          * @param appId ID of application that "owns" the handler
61          * @param log   a logging object to use
62          */
63         AssertionConsumerService(const xercesc::DOMElement* e, const char* appId, log4cpp::Category& log);
64         
65 #ifndef SHIBSP_LITE
66         /**
67          * Implement protocol-specific handling of the incoming decoded message.
68          * 
69          * <p>The result of implementing the protocol should be an exception or
70          * the key to a newly created session.
71          * 
72          * @param application   reference to application receiving message
73          * @param httpRequest   client request that included message
74          * @param policy        the SecurityPolicy in effect, after having evaluated the message
75          * @param settings      policy configuration settings in effect
76          * @param xmlObject     a protocol-specific message object
77          * @return  the key to the newly created session
78          */
79         virtual std::string implementProtocol(
80             const Application& application,
81             const xmltooling::HTTPRequest& httpRequest,
82             opensaml::SecurityPolicy& policy,
83             const PropertySet* settings,
84             const xmltooling::XMLObject& xmlObject
85             ) const=0;
86
87         /**
88          * Attempt SSO-initiated attribute resolution using the supplied information.
89          * 
90          * <p>The caller must free the returned context handle.
91          * 
92          * @param application   reference to application receiving message
93          * @param issuer        source of SSO tokens
94          * @param protocol      SSO protocol used
95          * @param nameid        identifier of principal
96          * @param authncontext_class    method/category of authentication event, if known
97          * @param authncontext_decl specifics of authentication event, if known
98          * @param tokens        available assertions, if any
99          * @param attributes    attributes already extracted, if any
100          */
101         ResolutionContext* resolveAttributes(
102             const Application& application,
103             const opensaml::saml2md::EntityDescriptor* issuer=NULL,
104             const XMLCh* protocol=NULL,
105             const opensaml::saml2::NameID* nameid=NULL,
106             const XMLCh* authncontext_class=NULL,
107             const XMLCh* authncontext_decl=NULL,
108             const std::vector<const opensaml::Assertion*>* tokens=NULL,
109             const std::multimap<std::string,Attribute*>* attributes=NULL
110             ) const;
111 #endif
112         
113         /**
114          * Enforce address checking requirements.
115          * 
116          * @param application   reference to application receiving message
117          * @param httpRequest   client request that initiated session
118          * @param issuedTo      address for which security assertion was issued
119          */
120         void checkAddress(
121             const Application& application, const xmltooling::HTTPRequest& httpRequest, const char* issuedTo
122             ) const;
123         
124     private:
125         std::string processMessage(
126             const Application& application,
127             xmltooling::HTTPRequest& httpRequest,
128             std::string& entityID,
129             std::string& relayState
130             ) const;
131             
132         std::pair<bool,long> sendRedirect(
133             SPRequest& request, const char* key, const char* entityID, const char* relayState
134             ) const;
135         
136         void maintainHistory(SPRequest& request, const char* entityID, const char* cookieProps) const;
137                 
138 #ifndef SHIBSP_LITE
139         opensaml::MessageDecoder* m_decoder;
140         xmltooling::QName m_role;
141 #endif
142     };
143
144 #if defined (_MSC_VER)
145     #pragma warning( pop )
146 #endif
147
148 };
149
150 #endif /* __shibsp_acshandler_h__ */