Factor out LogoutInitiator class, simpler API to get ACS by binding.
[shibboleth/cpp-sp.git] / shibsp / handler / impl / LocalLogoutInitiator.cpp
index 687dd32..5468df9 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.
 #include "Application.h"
 #include "ServiceProvider.h"
 #include "SessionCache.h"
+#include "SPRequest.h"
 #include "handler/AbstractHandler.h"
-#include "handler/LogoutHandler.h"
+#include "handler/LogoutInitiator.h"
 
 using namespace shibsp;
 using namespace xmltooling;
-using namespace log4cpp;
 using namespace std;
 
 namespace shibsp {
@@ -39,7 +39,7 @@ namespace shibsp {
     #pragma warning( disable : 4250 )
 #endif
 
-    class SHIBSP_DLLLOCAL LocalLogoutInitiator : public AbstractHandler, public LogoutHandler
+    class SHIBSP_DLLLOCAL LocalLogoutInitiator : public AbstractHandler, public LogoutInitiator
     {
     public:
         LocalLogoutInitiator(const DOMElement* e, const char* appId);
@@ -50,7 +50,6 @@ namespace shibsp {
 
     private:
         string m_appId;
-        vector<Handler*> m_handlers;
     };
 
 #if defined (_MSC_VER)
@@ -64,7 +63,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) {
@@ -93,18 +92,20 @@ 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(), sessions)) {
-            request.getApplication().getServiceProvider().getSessionCache()->remove(session_id, request.getApplication());
-            return sendLogoutPage(request.getApplication(), request, true, "Partial logout failure.");
-        }
-        request.getServiceProvider().getSessionCache()->remove(session_id, request.getApplication());
+        bool result = notifyBackChannel(app, request.getRequestURL(), sessions, true);
+        app.getServiceProvider().getSessionCache()->remove(app, request, &request);
+        if (!result)
+            return sendLogoutPage(app, request, request, "partial");
     }
 
-    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, "local");
 }