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