2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * CookieSessionInitiator.cpp
20 * Cookie-based IdP discovery.
24 #include "Application.h"
25 #include "exceptions.h"
26 #include "SPRequest.h"
27 #include "handler/AbstractHandler.h"
28 #include "handler/SessionInitiator.h"
31 # include <saml/util/CommonDomainCookie.h>
33 # include "lite/CommonDomainCookie.h"
36 #include <xmltooling/XMLToolingConfig.h>
37 #include <xmltooling/util/URLEncoder.h>
39 using namespace shibsp;
40 using namespace opensaml;
41 using namespace xmltooling;
46 #if defined (_MSC_VER)
47 #pragma warning( push )
48 #pragma warning( disable : 4250 )
51 class SHIBSP_DLLLOCAL CookieSessionInitiator : public SessionInitiator, public AbstractHandler
54 CookieSessionInitiator(const DOMElement* e, const char* appId)
55 : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".SessionInitiator.Cookie")), m_followMultiple(getBool("followMultiple").second) {
57 virtual ~CookieSessionInitiator() {}
59 pair<bool,long> run(SPRequest& request, string& entityID, bool isHandler=true) const;
62 bool m_followMultiple;
65 #if defined (_MSC_VER)
66 #pragma warning( pop )
69 SessionInitiator* SHIBSP_DLLLOCAL CookieSessionInitiatorFactory(const pair<const DOMElement*,const char*>& p)
71 return new CookieSessionInitiator(p.first, p.second);
76 pair<bool,long> CookieSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
78 // The IdP CANNOT be specified for us to run.
79 if (!entityID.empty())
80 return make_pair(false,0L);
82 // If there's no entityID yet, we can check for cookie processing.
83 CommonDomainCookie cdc(request.getCookie(CommonDomainCookie::CDCName));
84 if ((m_followMultiple && cdc.get().size() > 0) || (!m_followMultiple && cdc.get().size() == 1)) {
85 entityID = cdc.get().back();
86 m_log.info("set entityID (%s) from IdP history cookie", entityID.c_str());
89 return make_pair(false,0L);