From 8807ef07b9b718da0ec567251ac2eadb17cdad43 Mon Sep 17 00:00:00 2001 From: cantor Date: Mon, 14 Jul 2008 22:18:32 +0000 Subject: [PATCH] https://bugs.internet2.edu/jira/browse/SSPCPP-122 git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/branches/REL_2@2840 cb58f699-b61c-0410-a6fe-9272a202ed29 --- schemas/shibboleth-2.0-native-sp-config.xsd | 3 ++- shibsp/Application.cpp | 17 ++++++++++++----- shibsp/Application.h | 3 ++- shibsp/impl/StorageServiceSessionCache.cpp | 22 ++++++++++++++++++---- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/schemas/shibboleth-2.0-native-sp-config.xsd b/schemas/shibboleth-2.0-native-sp-config.xsd index ec8bf41..ea52138 100644 --- a/schemas/shibboleth-2.0-native-sp-config.xsd +++ b/schemas/shibboleth-2.0-native-sp-config.xsd @@ -8,7 +8,7 @@ elementFormDefault="qualified" attributeFormDefault="unqualified" blockDefault="substitution" - version="2.0"> + version="2.1"> @@ -542,6 +542,7 @@ + diff --git a/shibsp/Application.cpp b/shibsp/Application.cpp index 9457bfd..8e41cab 100644 --- a/shibsp/Application.cpp +++ b/shibsp/Application.cpp @@ -1,6 +1,6 @@ /* * Copyright 2001-2007 Internet2 - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,7 @@ /** * Application.cpp - * + * * Interface to a Shibboleth Application instance. */ @@ -42,12 +42,19 @@ Application::~Application() delete m_lock; } -pair Application::getCookieNameProps(const char* prefix) const +pair Application::getCookieNameProps(const char* prefix, time_t* lifetime) const { static const char* defProps="; path=/"; - + + if (lifetime) + *lifetime = 0; const PropertySet* props=getPropertySet("Sessions"); if (props) { + if (lifetime) { + pair lt = props->getUnsignedInt("cookieLifetime"); + if (lt.first) + *lifetime = lt.second; + } pair p=props->getString("cookieProps"); if (!p.first) p.second=defProps; @@ -56,7 +63,7 @@ pair Application::getCookieNameProps(const char* prefix) con return make_pair(string(prefix) + p2.second,p.second); return make_pair(string(prefix) + getHash(),p.second); } - + // Shouldn't happen, but just in case.. return pair(prefix,defProps); } diff --git a/shibsp/Application.h b/shibsp/Application.h index d157b2b..c7352a2 100644 --- a/shibsp/Application.h +++ b/shibsp/Application.h @@ -114,9 +114,10 @@ namespace shibsp { * Returns the name and cookie properties to use for this Application. * * @param prefix a value to prepend to the base cookie name + * @param lifetime if non-null, will be populated with a suggested lifetime for the cookie, or 0 if session-bound * @return a pair containing the cookie name and the string to append to the cookie value */ - virtual std::pair getCookieNameProps(const char* prefix) const; + virtual std::pair getCookieNameProps(const char* prefix, time_t* lifetime=NULL) const; #ifndef SHIBSP_LITE /** diff --git a/shibsp/impl/StorageServiceSessionCache.cpp b/shibsp/impl/StorageServiceSessionCache.cpp index 3219085..900ddfa 100644 --- a/shibsp/impl/StorageServiceSessionCache.cpp +++ b/shibsp/impl/StorageServiceSessionCache.cpp @@ -131,7 +131,7 @@ namespace shibsp { if (response) { pair shib_cookie = application.getCookieNameProps("_shibsession_"); string exp(shib_cookie.second); - exp += "; expires=Mon, 01-Jan-2001 00:00:00 GMT"; + exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT"; response->setCookie(shib_cookie.first.c_str(), exp.c_str()); } } @@ -140,7 +140,7 @@ namespace shibsp { if (response) { pair shib_cookie = application.getCookieNameProps("_shibsession_"); string exp(shib_cookie.second); - exp += "; expires=Mon, 01-Jan-2001 00:00:00 GMT"; + exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT"; response->setCookie(shib_cookie.first.c_str(), exp.c_str()); } throw; @@ -154,7 +154,7 @@ namespace shibsp { if (session_id && *session_id) { if (response) { string exp(shib_cookie.second); - exp += "; expires=Mon, 01-Jan-2001 00:00:00 GMT"; + exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT"; response->setCookie(shib_cookie.first.c_str(), exp.c_str()); } remove(application, session_id); @@ -1065,9 +1065,23 @@ void SSCache::insert( xlog->log.info("}"); } - pair shib_cookie = application.getCookieNameProps("_shibsession_"); + time_t cookieLifetime = 0; + pair shib_cookie = application.getCookieNameProps("_shibsession_", &cookieLifetime); string k(key.get()); k += shib_cookie.second; + + if (cookieLifetime > 0) { + cookieLifetime += now; +#ifndef HAVE_GMTIME_R + ptime=gmtime(&cookieLifetime); +#else + ptime=gmtime_r(&cookieLifetime,&res); +#endif + char cookietimebuf[64]; + strftime(cookietimebuf,64,"; expires=%a, %d %b %Y %H:%M:%S GMT",ptime); + k += cookietimebuf; + } + httpResponse.setCookie(shib_cookie.first.c_str(), k.c_str()); } -- 2.1.4