2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * CookieSessionInitiator.cpp
24 * Cookie-based IdP discovery.
28 #include "Application.h"
29 #include "exceptions.h"
30 #include "handler/AbstractHandler.h"
31 #include "handler/SessionInitiator.h"
34 # include <saml/util/CommonDomainCookie.h>
36 # include "lite/CommonDomainCookie.h"
39 #include <xmltooling/XMLToolingConfig.h>
40 #include <xmltooling/util/URLEncoder.h>
42 using namespace shibsp;
43 using namespace opensaml;
44 using namespace xmltooling;
49 #if defined (_MSC_VER)
50 #pragma warning( push )
51 #pragma warning( disable : 4250 )
54 class SHIBSP_DLLLOCAL CookieSessionInitiator : public SessionInitiator, public AbstractHandler
57 CookieSessionInitiator(const DOMElement* e, const char* appId)
58 : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT ".SessionInitiator.Cookie")),
59 m_followMultiple(getBool("followMultiple").second) {
60 m_supportedOptions.insert("isPassive");
62 virtual ~CookieSessionInitiator() {}
64 pair<bool,long> run(SPRequest& request, string& entityID, bool isHandler=true) const;
67 bool m_followMultiple;
70 #if defined (_MSC_VER)
71 #pragma warning( pop )
74 SessionInitiator* SHIBSP_DLLLOCAL CookieSessionInitiatorFactory(const pair<const DOMElement*,const char*>& p)
76 return new CookieSessionInitiator(p.first, p.second);
81 pair<bool,long> CookieSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
83 // The IdP CANNOT be specified for us to run.
84 if (!entityID.empty() || !checkCompatibility(request, isHandler))
85 return make_pair(false,0L);
87 // If there's no entityID yet, we can check for cookie processing.
88 CommonDomainCookie cdc(request.getCookie(CommonDomainCookie::CDCName));
89 if ((m_followMultiple && cdc.get().size() > 0) || (!m_followMultiple && cdc.get().size() == 1)) {
90 entityID = cdc.get().back();
91 m_log.info("set entityID (%s) from IdP history cookie", entityID.c_str());
94 return make_pair(false,0L);