6c4182cf3393cb26e7eee0a82a60950b0cf72599
[shibboleth/sp.git] / shibsp / handler / impl / SessionInitiator.cpp
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  * SessionInitiator.cpp
19  * 
20  * Pluggable runtime functionality that handles initiating sessions.
21  */
22
23 #include "internal.h"
24 #include "SPRequest.h"
25 #include "handler/SessionInitiator.h"
26
27 using namespace shibsp;
28 using namespace xmltooling;
29 using namespace std;
30
31 namespace shibsp {
32     SHIBSP_DLLLOCAL PluginManager<SessionInitiator,pair<const DOMElement*,const char*>>::Factory ChainingSessionInitiatorFactory;
33     SHIBSP_DLLLOCAL PluginManager<SessionInitiator,pair<const DOMElement*,const char*>>::Factory Shib1SessionInitiatorFactory;
34     SHIBSP_DLLLOCAL PluginManager<SessionInitiator,pair<const DOMElement*,const char*>>::Factory WAYFSessionInitiatorFactory;
35     SHIBSP_DLLLOCAL PluginManager<SessionInitiator,pair<const DOMElement*,const char*>>::Factory SAMLDSSessionInitiatorFactory;
36 };
37
38 void SHIBSP_API shibsp::registerSessionInitiators()
39 {
40     SPConfig& conf=SPConfig::getConfig();
41     conf.SessionInitiatorManager.registerFactory(CHAINING_SESSION_INITIATOR, ChainingSessionInitiatorFactory);
42     conf.SessionInitiatorManager.registerFactory(SHIB1_SESSION_INITIATOR, Shib1SessionInitiatorFactory);
43     conf.SessionInitiatorManager.registerFactory(WAYF_SESSION_INITIATOR, WAYFSessionInitiatorFactory);
44     conf.SessionInitiatorManager.registerFactory(SAMLDS_SESSION_INITIATOR, SAMLDSSessionInitiatorFactory);
45 }
46
47 pair<bool,long> SessionInitiator::run(SPRequest& request, bool isHandler) const
48 {
49     const char* entityID=NULL;
50     pair<bool,const char*> param = getString("entityIDParam");
51
52     if (isHandler) {
53         entityID=request.getParameter(param.first ? param.second : "entityID");
54         if (!param.first && (!entityID || !*entityID))
55             entityID=request.getParameter("providerId");
56     }
57     if (!entityID || !*entityID)
58         entityID=getString("entityID").second;
59
60     return run(request, entityID, isHandler);
61 }