Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-sp.git] / shibsp / handler / impl / LocalLogoutInitiator.cpp
index e048f0b..5768ac4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2009 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
 #include "Application.h"
 #include "ServiceProvider.h"
 #include "SessionCache.h"
+#include "SPRequest.h"
 #include "handler/AbstractHandler.h"
 #include "handler/LogoutHandler.h"
 
@@ -47,6 +48,12 @@ namespace shibsp {
         void setParent(const PropertySet* parent);
         pair<bool,long> run(SPRequest& request, bool isHandler=true) const;
 
+#ifndef SHIBSP_LITE
+        const char* getType() const {
+            return "LogoutInitiator";
+        }
+#endif
+
     private:
         string m_appId;
     };
@@ -62,7 +69,7 @@ namespace shibsp {
 };
 
 LocalLogoutInitiator::LocalLogoutInitiator(const DOMElement* e, const char* appId)
-    : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".LogoutInitiator")), m_appId(appId)
+    : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".LogoutInitiator.Local")), m_appId(appId)
 {
     pair<bool,const char*> loc = getString("Location");
     if (loc.first) {
@@ -91,18 +98,21 @@ pair<bool,long> LocalLogoutInitiator::run(SPRequest& request, bool isHandler) co
     if (ret.first)
         return ret;
 
-    // Get session ID from cookie.
-    pair<string,const char*> shib_cookie = request.getApplication().getCookieNameProps("_shibsession_");
-    const char* session_id = request.getCookie(shib_cookie.first.c_str());
-    if (session_id) {
+    const Application& app = request.getApplication();
+    string session_id = app.getServiceProvider().getSessionCache()->active(app, request);
+    if (!session_id.empty()) {
         // Do back channel notification.
         vector<string> sessions(1, session_id);
-        if (!notifyBackChannel(request.getApplication(), request.getRequestURL(), sessions, true)) {
-            request.getApplication().getServiceProvider().getSessionCache()->remove(session_id, request.getApplication());
-            return sendLogoutPage(request.getApplication(), request, true, "Partial logout failure.");
+        if (!notifyBackChannel(app, request.getRequestURL(), sessions, true)) {
+            app.getServiceProvider().getSessionCache()->remove(app, request, &request);
+            return sendLogoutPage(app, request, request, true, "Partial logout failure.");
         }
-        request.getServiceProvider().getSessionCache()->remove(session_id, request.getApplication());
+        request.getServiceProvider().getSessionCache()->remove(app, request, &request);
     }
 
-    return sendLogoutPage(request.getApplication(), request, true, "Logout was successful.");
+    // Route back to return location specified, or use the local template.
+    const char* dest = request.getParameter("return");
+    if (dest)
+        return make_pair(true, request.sendRedirect(dest));
+    return sendLogoutPage(app, request, request, true, "Logout was successful.");
 }