e00dc8de893c81f0be619b44d1bb287626890ba1
[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 nameid        identifier of principal
95          * @param authncontext_class    method/category of authentication event, if known
96          * @param authncontext_decl specifics of authentication event, if known
97          * @param tokens        available assertions, if any
98          * @param attributes    attributes already extracted, if any
99          */
100         ResolutionContext* resolveAttributes(
101             const Application& application,
102             const opensaml::saml2md::EntityDescriptor* issuer=NULL,
103             const opensaml::saml2::NameID* nameid=NULL,
104             const char* authncontext_class=NULL,
105             const char* authncontext_decl=NULL,
106             const std::vector<const opensaml::Assertion*>* tokens=NULL,
107             const std::multimap<std::string,Attribute*>* attributes=NULL
108             ) const;
109 #endif
110         
111         /**
112          * Enforce address checking requirements.
113          * 
114          * @param application   reference to application receiving message
115          * @param httpRequest   client request that initiated session
116          * @param issuedTo      address for which security assertion was issued
117          */
118         void checkAddress(
119             const Application& application, const xmltooling::HTTPRequest& httpRequest, const char* issuedTo
120             ) const;
121         
122     private:
123         std::string processMessage(
124             const Application& application,
125             xmltooling::HTTPRequest& httpRequest,
126             std::string& entityID,
127             std::string& relayState
128             ) const;
129             
130         std::pair<bool,long> sendRedirect(
131             SPRequest& request, const char* key, const char* entityID, const char* relayState
132             ) const;
133         
134         void maintainHistory(SPRequest& request, const char* entityID, const char* cookieProps) const;
135                 
136 #ifndef SHIBSP_LITE
137         opensaml::MessageDecoder* m_decoder;
138         xmltooling::QName m_role;
139 #endif
140     };
141
142 #if defined (_MSC_VER)
143     #pragma warning( pop )
144 #endif
145
146 };
147
148 #endif /* __shibsp_acshandler_h__ */