Copied over mapping and filtering schemas.
[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 #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         /**
53          * Constructor
54          * 
55          * @param e     root of DOM configuration
56          * @param appId ID of application that "owns" the handler
57          * @param log   a logging object to use
58          */
59         AssertionConsumerService(const xercesc::DOMElement* e, const char* appId, log4cpp::Category& log);
60         
61         /**
62          * Implement protocol-specific handling of the incoming decoded message.
63          * 
64          * <p>The result of implementing the protocol should be an exception or
65          * the key to a newly created session.
66          * 
67          * @param application   reference to application receiving message
68          * @param httpRequest   client request that included message
69          * @param policy        the SecurityPolicy in effect, after having evaluated the message
70          * @param settings      policy configuration settings in effect
71          * @param xmlObject     a protocol-specific message object
72          * @return  the key to the newly created session
73          */
74         virtual std::string implementProtocol(
75             const Application& application,
76             const opensaml::HTTPRequest& httpRequest,
77             opensaml::SecurityPolicy& policy,
78             const PropertySet* settings,
79             const xmltooling::XMLObject& xmlObject
80             ) const=0;
81             
82         /**
83          * Enforce address checking requirements.
84          * 
85          * @param application   reference to application receiving message
86          * @param httpRequest   client request that initiated session
87          * @param issuedTo      address for which security assertion was issued
88          */
89         void checkAddress(
90             const Application& application, const opensaml::HTTPRequest& httpRequest, const char* issuedTo
91             ) const;
92         
93         /**
94          * Attempt SSO-initiated attribute resolution using the supplied information.
95          * 
96          * <p>The caller must free the returned context handle.
97          * 
98          * @param application   reference to application receiving message
99          * @param issuer        source of SSO tokens
100          * @param nameid        identifier of principal
101          * @param tokens        available assertions, if any
102          * @param attributes    attributes already extracted, if any
103          */
104         ResolutionContext* resolveAttributes(
105             const Application& application,
106             const opensaml::saml2md::EntityDescriptor* issuer=NULL,
107             const opensaml::saml2::NameID* nameid=NULL,
108             const std::vector<const opensaml::Assertion*>* tokens=NULL,
109             const std::multimap<std::string,Attribute*>* attributes=NULL
110             ) const;
111         
112     private:
113         std::string processMessage(
114             const Application& application,
115             opensaml::HTTPRequest& httpRequest,
116             std::string& entityID,
117             std::string& relayState
118             ) const;
119             
120         std::pair<bool,long> sendRedirect(
121             SPRequest& request, const char* key, const char* entityID, const char* relayState
122             ) const;
123         
124         void maintainHistory(SPRequest& request, const char* entityID, const char* cookieProps) const;
125                 
126         opensaml::MessageDecoder* m_decoder;
127         xmltooling::auto_ptr_char m_configNS;
128         xmltooling::QName m_role;
129     };
130
131 #if defined (_MSC_VER)
132     #pragma warning( pop )
133 #endif
134
135 };
136
137 #endif /* __shibsp_acshandler_h__ */