Factor out LogoutInitiator class, simpler API to get ACS by binding.
[shibboleth/sp.git] / shibsp / handler / SessionInitiator.h
1 /*
2  *  Copyright 2001-2010 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/SessionInitiator.h
19  * 
20  * Pluggable runtime functionality that handles initiating sessions.
21  */
22
23 #ifndef __shibsp_sesinitiator_h__
24 #define __shibsp_sesinitiator_h__
25
26 #include <shibsp/handler/Handler.h>
27
28 #include <map>
29 #include <set>
30 #include <string>
31
32 namespace shibsp {
33
34     /**
35      * Pluggable runtime functionality that handles initiating sessions.
36      *
37      * <p>By default, SessionInitiators look for an entityID on the incoming request
38      * and pass control to the specialized run method.
39      */
40     class SHIBSP_API SessionInitiator : public virtual Handler
41     {
42         friend void SHIBSP_API registerSessionInitiators();
43     protected:
44         /** Property remapper for configuration compatibility. */
45         static std::map<std::string,std::string> m_remapper;
46
47         /** Set of optional settings supported by handler. */
48         std::set<std::string> m_supportedOptions;
49
50         SessionInitiator();
51
52         /**
53          * Examines the request and applicable settings to determine whether
54          * the handler is able to support the request.
55          * <p>If the handler is within a chain, the method will return false,
56          * otherwise an exception will be raised.
57          *
58          * @param request   SP request context
59          * @param isHandler true iff executing in the context of a direct handler invocation
60          * @return  true iff the request appears to be compatible
61          */
62         bool checkCompatibility(SPRequest& request, bool isHandler) const;
63
64     public:
65         virtual ~SessionInitiator();
66
67         /**
68          * Indicates the set of optional settings supported by the handler.
69          *
70          * @return  a set of the optional settings supported
71          */
72         virtual const std::set<std::string>& getSupportedOptions() const;
73
74         /**
75          * Executes an incoming request.
76          * 
77          * <p>SessionInitiators can be run either directly by incoming web requests
78          * or indirectly/implicitly during other SP processing.
79          * 
80          * @param request   SP request context
81          * @param entityID  the name of an IdP to request a session from, if known
82          * @param isHandler true iff executing in the context of a direct handler invocation
83          * @return  a pair containing a "request completed" indicator and a server-specific response code
84          */
85         virtual std::pair<bool,long> run(SPRequest& request, std::string& entityID, bool isHandler=true) const=0;
86
87         std::pair<bool,long> run(SPRequest& request, bool isHandler=true) const;
88
89 #ifndef SHIBSP_LITE
90         const char* getType() const;
91 #endif
92     };
93     
94     /** Registers SessionInitiator implementations. */
95     void SHIBSP_API registerSessionInitiators();
96
97     /** SessionInitiator that iterates through a set of protocol-specific versions. */
98     #define CHAINING_SESSION_INITIATOR "Chaining"
99
100     /** SessionInitiator that supports SAML 2.0 AuthnRequests. */
101     #define SAML2_SESSION_INITIATOR "SAML2"
102
103     /** SessionInitiator that supports SAML Discovery Service protocol. */
104     #define SAMLDS_SESSION_INITIATOR "SAMLDS"
105
106     /** SessionInitiator that supports Shibboleth V1 AuthnRequest redirects. */
107     #define SHIB1_SESSION_INITIATOR "Shib1"
108
109     /** SessionInitiator that supports Shibboleth V1 WAYF redirects when no IdP is supplied. */
110     #define WAYF_SESSION_INITIATOR "WAYF"
111     
112     /** SessionInitiator that attempts a sequence of transforms of an input until an entityID is found. */
113     #define TRANSFORM_SESSION_INITIATOR "Transform"
114
115     /** SessionInitiator that uses HTML form submission from the user. */
116     #define FORM_SESSION_INITIATOR "Form"
117
118     /** SessionInitiator that reads the CDC. */
119     #define COOKIE_SESSION_INITIATOR "Cookie"
120 };
121
122 #endif /* __shibsp_sesinitiator_h__ */