https://issues.shibboleth.net/jira/browse/SSPCPP-274
authorScott Cantor <cantor.2@osu.edu>
Thu, 28 Jan 2010 18:39:03 +0000 (18:39 +0000)
committerScott Cantor <cantor.2@osu.edu>
Thu, 28 Jan 2010 18:39:03 +0000 (18:39 +0000)
15 files changed:
adfs/adfs.cpp
schemas/shibboleth-2.0-native-sp-config.xsd
shibsp/handler/AbstractHandler.h
shibsp/handler/Handler.h
shibsp/handler/SessionInitiator.h
shibsp/handler/impl/AbstractHandler.cpp
shibsp/handler/impl/ChainingSessionInitiator.cpp
shibsp/handler/impl/CookieSessionInitiator.cpp
shibsp/handler/impl/FormSessionInitiator.cpp
shibsp/handler/impl/SAML2SessionInitiator.cpp
shibsp/handler/impl/SAMLDSSessionInitiator.cpp
shibsp/handler/impl/SessionInitiator.cpp
shibsp/handler/impl/Shib1SessionInitiator.cpp
shibsp/handler/impl/TransformSessionInitiator.cpp
shibsp/handler/impl/WAYFSessionInitiator.cpp

index 41c78e6..006c3bd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -322,7 +322,7 @@ extern "C" void ADFS_EXPORTS xmltooling_extension_term()
 pair<bool,long> ADFSSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
 {
     // We have to know the IdP to function.
-    if (entityID.empty())
+    if (entityID.empty() || !checkCompatibility(request, isHandler))
         return make_pair(false,0L);
 
     string target;
index 310505e..4b48bef 100644 (file)
                <attribute name="entityID" type="anyURI"/>
         <attribute name="discoveryURL" type="anyURI"/>
                <attribute name="isPassive" type="boolean"/>
+        <attribute name="returnOnError" type="boolean"/>
                <attribute name="forceAuthn" type="boolean"/>
                <attribute name="authnContextClassRef" type="anyURI"/>
                <attribute name="authnContextComparison" type="samlp:AuthnContextComparisonType"/>
                     <attribute name="acsIndex" type="unsignedShort"/>
                                        <attribute name="defaultACSIndex" type="unsignedShort"/>   <!-- deprecated -->
                     <attribute name="isPassive" type="boolean"/>
+                    <attribute name="returnOnError" type="boolean"/>
                     <attribute name="forceAuthn" type="boolean"/>
                     <attribute name="authnContextClassRef" type="anyURI"/>
                     <attribute name="authnContextComparison" type="samlp:AuthnContextComparisonType"/>
index fcc5927..d797b27 100644 (file)
@@ -44,15 +44,12 @@ namespace opensaml {
 #endif
 
 namespace xmltooling {
-    class XMLTOOL_API HTTPRequest;
-    class XMLTOOL_API HTTPResponse;
     class XMLTOOL_API XMLObject;
 };
 
 namespace shibsp {
 
     class SHIBSP_API Application;
-    class SHIBSP_API SPRequest;
 
 #if defined (_MSC_VER)
     #pragma warning( push )
@@ -80,6 +77,8 @@ namespace shibsp {
             const std::map<std::string,std::string>* remapper=NULL
             );
 
+        void log(SPRequest::SPLogLevel level, const std::string& msg) const;
+
 #ifndef SHIBSP_LITE
         /**
          * Examines a protocol response message for errors and raises an annotated exception
@@ -134,42 +133,6 @@ namespace shibsp {
 #endif
 
         /**
-         * Implements various mechanisms to preserve RelayState,
-         * such as cookies or StorageService-backed keys.
-         * 
-         * <p>If a supported mechanism can be identified, the input parameter will be
-         * replaced with a suitable state key.
-         * 
-         * @param application   the associated Application
-         * @param response      outgoing HTTP response
-         * @param relayState    RelayState token to supply with message
-         */
-        virtual void preserveRelayState(
-            const Application& application, xmltooling::HTTPResponse& response, std::string& relayState
-            ) const;
-
-        /**
-         * Implements various mechanisms to recover RelayState,
-         * such as cookies or StorageService-backed keys.
-         * 
-         * <p>If a supported mechanism can be identified, the input parameter will be
-         * replaced with the recovered state information.
-         * 
-         * @param application   the associated Application
-         * @param request       incoming HTTP request
-         * @param response      outgoing HTTP response
-         * @param relayState    RelayState token supplied with message
-         * @param clear         true iff the token state should be cleared
-         */
-        virtual void recoverRelayState(
-            const Application& application,
-            const xmltooling::HTTPRequest& request,
-            xmltooling::HTTPResponse& response,
-            std::string& relayState,
-            bool clear=true
-            ) const;
-        
-        /**
          * Implements a mechanism to preserve form post data.
          *
          * @param application   the associated Application
@@ -205,7 +168,7 @@ namespace shibsp {
 
         /**
          * Post a redirect response with post data.
-         * 
+         *
          * @param application   the associated Application
          * @param response      outgoing HTTP response
          * @param request       incoming HTTP request
index f397e27..24bb798 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef __shibsp_handler_h__
 #define __shibsp_handler_h__
 
+#include <shibsp/SPRequest.h>
 #include <shibsp/util/PropertySet.h>
 
 #ifndef SHIBSP_LITE
@@ -33,9 +34,12 @@ namespace opensaml {
 };
 #endif
 
-namespace shibsp {
+namespace xmltooling {
+    class XMLTOOL_API HTTPRequest;
+    class XMLTOOL_API HTTPResponse;
+};
 
-    class SHIBSP_API SPRequest;
+namespace shibsp {
 
     /**
      * Pluggable runtime functionality that implement protocols and services
@@ -45,6 +49,51 @@ namespace shibsp {
         MAKE_NONCOPYABLE(Handler);
     protected:
         Handler();
+
+        /**
+         * Log using handler's specific logging object.
+         *
+         * @param level logging level
+         * @param msg   message to log
+         */
+        virtual void log(SPRequest::SPLogLevel level, const std::string& msg) const;
+
+        /**
+         * Implements various mechanisms to preserve RelayState,
+         * such as cookies or StorageService-backed keys.
+         *
+         * <p>If a supported mechanism can be identified, the input parameter will be
+         * replaced with a suitable state key.
+         *
+         * @param application   the associated Application
+         * @param response      outgoing HTTP response
+         * @param relayState    RelayState token to supply with message
+         */
+        virtual void preserveRelayState(
+            const Application& application, xmltooling::HTTPResponse& response, std::string& relayState
+            ) const;
+
+        /**
+         * Implements various mechanisms to recover RelayState,
+         * such as cookies or StorageService-backed keys.
+         *
+         * <p>If a supported mechanism can be identified, the input parameter will be
+         * replaced with the recovered state information.
+         *
+         * @param application   the associated Application
+         * @param request       incoming HTTP request
+         * @param response      outgoing HTTP response
+         * @param relayState    RelayState token supplied with message
+         * @param clear         true iff the token state should be cleared
+         */
+        virtual void recoverRelayState(
+            const Application& application,
+            const xmltooling::HTTPRequest& request,
+            xmltooling::HTTPResponse& response,
+            std::string& relayState,
+            bool clear=true
+            ) const;
+
     public:
         virtual ~Handler();
 
index 67530d4..d31d988 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,6 +25,9 @@
 
 #include <shibsp/handler/Handler.h>
 
+#include <set>
+#include <string>
+
 namespace shibsp {
 
     /**
@@ -40,12 +43,34 @@ namespace shibsp {
         /** Property remapper for configuration compatibility. */
         static std::map<std::string,std::string> m_remapper;
 
+        /** Set of optional settings supported by handler. */
+        std::set<std::string> m_supportedOptions;
+
         SessionInitiator();
 
+        /**
+         * Examines the request and applicable settings to determine whether
+         * the handler is able to support the request.
+         * <p>If the handler is within a chain, the method will return false,
+         * otherwise an exception will be raised.
+         *
+         * @param request   SP request context
+         * @param isHandler true iff executing in the context of a direct handler invocation
+         * @return  true iff the request appears to be compatible
+         */
+        bool checkCompatibility(SPRequest& request, bool isHandler) const;
+
     public:
         virtual ~SessionInitiator();
 
         /**
+         * Indicates the set of optional settings supported by the handler.
+         *
+         * @return  an array of the optional settings supported
+         */
+        virtual const std::set<std::string>& getSupportedOptions() const;
+
+        /**
          * Executes an incoming request.
          * 
          * <p>SessionInitiators can be run either directly by incoming web requests
index d1c8d58..39ac7dc 100644 (file)
@@ -139,156 +139,18 @@ Handler::~Handler()
 {
 }
 
-AbstractHandler::AbstractHandler(
-    const DOMElement* e, Category& log, DOMNodeFilter* filter, const map<string,string>* remapper
-    ) : m_log(log), m_configNS(shibspconstants::SHIB2SPCONFIG_NS) {
-    load(e,NULL,filter,remapper);
-}
-
-AbstractHandler::~AbstractHandler()
+void Handler::log(SPRequest::SPLogLevel level, const string& msg) const
 {
+    Category::getInstance(SHIBSP_LOGCAT".Handler").log(
+        (level == SPRequest::SPDebug ? Priority::DEBUG :
+        (level == SPRequest::SPInfo ? Priority::INFO :
+        (level == SPRequest::SPWarn ? Priority::WARN :
+        (level == SPRequest::SPError ? Priority::ERROR : Priority::CRIT)))),
+        msg
+        );
 }
 
-#ifndef SHIBSP_LITE
-
-const char* Handler::getType() const
-{
-    return getString("type").second;
-}
-
-void AbstractHandler::checkError(const XMLObject* response, const saml2md::RoleDescriptor* role) const
-{
-    const saml2p::StatusResponseType* r2 = dynamic_cast<const saml2p::StatusResponseType*>(response);
-    if (r2) {
-        const saml2p::Status* status = r2->getStatus();
-        if (status) {
-            const saml2p::StatusCode* sc = status->getStatusCode();
-            const XMLCh* code = sc ? sc->getValue() : NULL;
-            if (code && !XMLString::equals(code,saml2p::StatusCode::SUCCESS)) {
-                FatalProfileException ex("SAML response contained an error.");
-                annotateException(&ex, role, status);   // throws it
-            }
-        }
-    }
-
-    const saml1p::Response* r1 = dynamic_cast<const saml1p::Response*>(response);
-    if (r1) {
-        const saml1p::Status* status = r1->getStatus();
-        if (status) {
-            const saml1p::StatusCode* sc = status->getStatusCode();
-            const xmltooling::QName* code = sc ? sc->getValue() : NULL;
-            if (code && *code != saml1p::StatusCode::SUCCESS) {
-                FatalProfileException ex("SAML response contained an error.");
-                ex.addProperty("statusCode", code->toString().c_str());
-                if (sc->getStatusCode()) {
-                    code = sc->getStatusCode()->getValue();
-                    if (code)
-                        ex.addProperty("statusCode2", code->toString().c_str());
-                }
-                if (status->getStatusMessage()) {
-                    auto_ptr_char msg(status->getStatusMessage()->getMessage());
-                    if (msg.get() && *msg.get())
-                        ex.addProperty("statusMessage", msg.get());
-                }
-                ex.raise();
-            }
-        }
-    }
-}
-
-void AbstractHandler::fillStatus(saml2p::StatusResponseType& response, const XMLCh* code, const XMLCh* subcode, const char* msg) const
-{
-    saml2p::Status* status = saml2p::StatusBuilder::buildStatus();
-    saml2p::StatusCode* scode = saml2p::StatusCodeBuilder::buildStatusCode();
-    status->setStatusCode(scode);
-    scode->setValue(code);
-    if (subcode) {
-        saml2p::StatusCode* ssubcode = saml2p::StatusCodeBuilder::buildStatusCode();
-        scode->setStatusCode(ssubcode);
-        ssubcode->setValue(subcode);
-    }
-    if (msg) {
-        pair<bool,bool> flag = getBool("detailedErrors", m_configNS.get());
-        auto_ptr_XMLCh widemsg((flag.first && flag.second) ? msg : "Error processing request.");
-        saml2p::StatusMessage* sm = saml2p::StatusMessageBuilder::buildStatusMessage();
-        status->setStatusMessage(sm);
-        sm->setMessage(widemsg.get());
-    }
-    response.setStatus(status);
-}
-
-long AbstractHandler::sendMessage(
-    const MessageEncoder& encoder,
-    XMLObject* msg,
-    const char* relayState,
-    const char* destination,
-    const saml2md::RoleDescriptor* role,
-    const Application& application,
-    HTTPResponse& httpResponse,
-    bool signIfPossible
-    ) const
-{
-    const EntityDescriptor* entity = role ? dynamic_cast<const EntityDescriptor*>(role->getParent()) : NULL;
-    const PropertySet* relyingParty = application.getRelyingParty(entity);
-    pair<bool,const char*> flag = signIfPossible ? make_pair(true,(const char*)"true") : relyingParty->getString("signing");
-    if (role && flag.first &&
-        (!strcmp(flag.second, "true") ||
-            (encoder.isUserAgentPresent() && !strcmp(flag.second, "front")) ||
-            (!encoder.isUserAgentPresent() && !strcmp(flag.second, "back")))) {
-        CredentialResolver* credResolver=application.getCredentialResolver();
-        if (credResolver) {
-            Locker credLocker(credResolver);
-            const Credential* cred = NULL;
-            pair<bool,const char*> keyName = relyingParty->getString("keyName");
-            pair<bool,const XMLCh*> sigalg = relyingParty->getXMLString("signingAlg");
-            if (role) {
-                MetadataCredentialCriteria mcc(*role);
-                mcc.setUsage(Credential::SIGNING_CREDENTIAL);
-                if (keyName.first)
-                    mcc.getKeyNames().insert(keyName.second);
-                if (sigalg.first)
-                    mcc.setXMLAlgorithm(sigalg.second);
-                cred = credResolver->resolve(&mcc);
-            }
-            else {
-                CredentialCriteria cc;
-                cc.setUsage(Credential::SIGNING_CREDENTIAL);
-                if (keyName.first)
-                    cc.getKeyNames().insert(keyName.second);
-                if (sigalg.first)
-                    cc.setXMLAlgorithm(sigalg.second);
-                cred = credResolver->resolve(&cc);
-            }
-            if (cred) {
-                // Signed request.
-                return encoder.encode(
-                    httpResponse,
-                    msg,
-                    destination,
-                    entity,
-                    relayState,
-                    &application,
-                    cred,
-                    sigalg.second,
-                    relyingParty->getXMLString("digestAlg").second
-                    );
-            }
-            else {
-                m_log.warn("no signing credential resolved, leaving message unsigned");
-            }
-        }
-        else {
-            m_log.warn("no credential resolver installed, leaving message unsigned");
-        }
-    }
-
-    // Unsigned request.
-    return encoder.encode(httpResponse, msg, destination, entity, relayState, &application);
-}
-
-#endif
-
-void AbstractHandler::preserveRelayState(const Application& application, HTTPResponse& response, string& relayState) const
+void Handler::preserveRelayState(const Application& application, HTTPResponse& response, string& relayState) const
 {
     if (relayState.empty())
         return;
@@ -328,7 +190,9 @@ void AbstractHandler::preserveRelayState(const Application& application, HTTPRes
                         relayState = string(mech.second-3) + ':' + rsKey;
                     }
                     else {
-                        m_log.error("Storage-backed RelayState with invalid StorageService ID (%s)", mech.second);
+                        string msg("Storage-backed RelayState with invalid StorageService ID (");
+                        msg = msg + mech.second+ ')';
+                        log(SPRequest::SPError, msg);
                         relayState.erase();
                     }
 #endif
@@ -350,7 +214,7 @@ void AbstractHandler::preserveRelayState(const Application& application, HTTPRes
         throw ConfigurationException("Unsupported relayState mechanism ($1).", params(1,mech.second));
 }
 
-void AbstractHandler::recoverRelayState(
+void Handler::recoverRelayState(
     const Application& application, const HTTPRequest& request, HTTPResponse& response, string& relayState, bool clear
     ) const
 {
@@ -379,7 +243,9 @@ void AbstractHandler::recoverRelayState(
                             relayState.erase();
                     }
                     else {
-                        m_log.error("Storage-backed RelayState with invalid StorageService ID (%s)", ssid.c_str());
+                        string msg("Storage-backed RelayState with invalid StorageService ID (");
+                        msg += ssid + ')';
+                        log(SPRequest::SPError, msg);
                         relayState.erase();
                     }
 #endif
@@ -392,7 +258,7 @@ void AbstractHandler::recoverRelayState(
                     DDFJanitor jin(in),jout(out);
                     out = application.getServiceProvider().getListenerService()->send(in);
                     if (!out.isstring()) {
-                        m_log.error("StorageService-backed RelayState mechanism did not return a state value.");
+                        log(SPRequest::SPError, "StorageService-backed RelayState mechanism did not return a state value.");
                         relayState.erase();
                     }
                     else {
@@ -451,6 +317,166 @@ void AbstractHandler::recoverRelayState(
     }
 }
 
+AbstractHandler::AbstractHandler(
+    const DOMElement* e, Category& log, DOMNodeFilter* filter, const map<string,string>* remapper
+    ) : m_log(log), m_configNS(shibspconstants::SHIB2SPCONFIG_NS) {
+    load(e,NULL,filter,remapper);
+}
+
+AbstractHandler::~AbstractHandler()
+{
+}
+
+void AbstractHandler::log(SPRequest::SPLogLevel level, const string& msg) const
+{
+    m_log.log(
+        (level == SPRequest::SPDebug ? Priority::DEBUG :
+        (level == SPRequest::SPInfo ? Priority::INFO :
+        (level == SPRequest::SPWarn ? Priority::WARN :
+        (level == SPRequest::SPError ? Priority::ERROR : Priority::CRIT)))),
+        msg
+        );
+}
+
+#ifndef SHIBSP_LITE
+
+const char* Handler::getType() const
+{
+    return getString("type").second;
+}
+
+void AbstractHandler::checkError(const XMLObject* response, const saml2md::RoleDescriptor* role) const
+{
+    const saml2p::StatusResponseType* r2 = dynamic_cast<const saml2p::StatusResponseType*>(response);
+    if (r2) {
+        const saml2p::Status* status = r2->getStatus();
+        if (status) {
+            const saml2p::StatusCode* sc = status->getStatusCode();
+            const XMLCh* code = sc ? sc->getValue() : NULL;
+            if (code && !XMLString::equals(code,saml2p::StatusCode::SUCCESS)) {
+                FatalProfileException ex("SAML response contained an error.");
+                annotateException(&ex, role, status);   // throws it
+            }
+        }
+    }
+
+    const saml1p::Response* r1 = dynamic_cast<const saml1p::Response*>(response);
+    if (r1) {
+        const saml1p::Status* status = r1->getStatus();
+        if (status) {
+            const saml1p::StatusCode* sc = status->getStatusCode();
+            const xmltooling::QName* code = sc ? sc->getValue() : NULL;
+            if (code && *code != saml1p::StatusCode::SUCCESS) {
+                FatalProfileException ex("SAML response contained an error.");
+                ex.addProperty("statusCode", code->toString().c_str());
+                if (sc->getStatusCode()) {
+                    code = sc->getStatusCode()->getValue();
+                    if (code)
+                        ex.addProperty("statusCode2", code->toString().c_str());
+                }
+                if (status->getStatusMessage()) {
+                    auto_ptr_char msg(status->getStatusMessage()->getMessage());
+                    if (msg.get() && *msg.get())
+                        ex.addProperty("statusMessage", msg.get());
+                }
+                ex.raise();
+            }
+        }
+    }
+}
+
+void AbstractHandler::fillStatus(saml2p::StatusResponseType& response, const XMLCh* code, const XMLCh* subcode, const char* msg) const
+{
+    saml2p::Status* status = saml2p::StatusBuilder::buildStatus();
+    saml2p::StatusCode* scode = saml2p::StatusCodeBuilder::buildStatusCode();
+    status->setStatusCode(scode);
+    scode->setValue(code);
+    if (subcode) {
+        saml2p::StatusCode* ssubcode = saml2p::StatusCodeBuilder::buildStatusCode();
+        scode->setStatusCode(ssubcode);
+        ssubcode->setValue(subcode);
+    }
+    if (msg) {
+        pair<bool,bool> flag = getBool("detailedErrors", m_configNS.get());
+        auto_ptr_XMLCh widemsg((flag.first && flag.second) ? msg : "Error processing request.");
+        saml2p::StatusMessage* sm = saml2p::StatusMessageBuilder::buildStatusMessage();
+        status->setStatusMessage(sm);
+        sm->setMessage(widemsg.get());
+    }
+    response.setStatus(status);
+}
+
+long AbstractHandler::sendMessage(
+    const MessageEncoder& encoder,
+    XMLObject* msg,
+    const char* relayState,
+    const char* destination,
+    const saml2md::RoleDescriptor* role,
+    const Application& application,
+    HTTPResponse& httpResponse,
+    bool signIfPossible
+    ) const
+{
+    const EntityDescriptor* entity = role ? dynamic_cast<const EntityDescriptor*>(role->getParent()) : NULL;
+    const PropertySet* relyingParty = application.getRelyingParty(entity);
+    pair<bool,const char*> flag = signIfPossible ? make_pair(true,(const char*)"true") : relyingParty->getString("signing");
+    if (role && flag.first &&
+        (!strcmp(flag.second, "true") ||
+            (encoder.isUserAgentPresent() && !strcmp(flag.second, "front")) ||
+            (!encoder.isUserAgentPresent() && !strcmp(flag.second, "back")))) {
+        CredentialResolver* credResolver=application.getCredentialResolver();
+        if (credResolver) {
+            Locker credLocker(credResolver);
+            const Credential* cred = NULL;
+            pair<bool,const char*> keyName = relyingParty->getString("keyName");
+            pair<bool,const XMLCh*> sigalg = relyingParty->getXMLString("signingAlg");
+            if (role) {
+                MetadataCredentialCriteria mcc(*role);
+                mcc.setUsage(Credential::SIGNING_CREDENTIAL);
+                if (keyName.first)
+                    mcc.getKeyNames().insert(keyName.second);
+                if (sigalg.first)
+                    mcc.setXMLAlgorithm(sigalg.second);
+                cred = credResolver->resolve(&mcc);
+            }
+            else {
+                CredentialCriteria cc;
+                cc.setUsage(Credential::SIGNING_CREDENTIAL);
+                if (keyName.first)
+                    cc.getKeyNames().insert(keyName.second);
+                if (sigalg.first)
+                    cc.setXMLAlgorithm(sigalg.second);
+                cred = credResolver->resolve(&cc);
+            }
+            if (cred) {
+                // Signed request.
+                return encoder.encode(
+                    httpResponse,
+                    msg,
+                    destination,
+                    entity,
+                    relayState,
+                    &application,
+                    cred,
+                    sigalg.second,
+                    relyingParty->getXMLString("digestAlg").second
+                    );
+            }
+            else {
+                m_log.warn("no signing credential resolved, leaving message unsigned");
+            }
+        }
+        else {
+            m_log.warn("no credential resolver installed, leaving message unsigned");
+        }
+    }
+
+    // Unsigned request.
+    return encoder.encode(httpResponse, msg, destination, entity, relayState, &application);
+}
+
+#endif
+
 void AbstractHandler::preservePostData(
     const Application& application, const HTTPRequest& request, HTTPResponse& response, const char* relayState
     ) const
index 1cbc45b..468a9e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -111,10 +111,15 @@ ChainingSessionInitiator::ChainingSessionInitiator(const DOMElement* e, const ch
         }
         e = XMLHelper::getNextSiblingElement(e, _SessionInitiator);
     }
+
+    m_supportedOptions.insert("isPassive");
 }
 
 pair<bool,long> ChainingSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
 {
+    if (!checkCompatibility(request, isHandler))
+        return make_pair(false,0L);
+
     pair<bool,long> ret;
     for (vector<SessionInitiator*>::const_iterator i = m_handlers.begin(); i!=m_handlers.end(); ++i) {
         ret = (*i)->run(request, entityID, isHandler);
index b79ed15..9cc548e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
 #include "internal.h"
 #include "Application.h"
 #include "exceptions.h"
-#include "SPRequest.h"
 #include "handler/AbstractHandler.h"
 #include "handler/SessionInitiator.h"
 
@@ -52,7 +51,9 @@ namespace shibsp {
     {
     public:
         CookieSessionInitiator(const DOMElement* e, const char* appId)
-            : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".SessionInitiator.Cookie")), m_followMultiple(getBool("followMultiple").second) {
+            : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".SessionInitiator.Cookie")),
+              m_followMultiple(getBool("followMultiple").second) {
+            m_supportedOptions.insert("isPassive");
         }
         virtual ~CookieSessionInitiator() {}
         
@@ -76,7 +77,7 @@ namespace shibsp {
 pair<bool,long> CookieSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
 {
     // The IdP CANNOT be specified for us to run.
-    if (!entityID.empty())
+    if (!entityID.empty() || !checkCompatibility(request, isHandler))
         return make_pair(false,0L);
 
     // If there's no entityID yet, we can check for cookie processing.
index 53f6008..f419280 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
 #include "internal.h"
 #include "Application.h"
 #include "exceptions.h"
-#include "SPRequest.h"
 #include "handler/AbstractHandler.h"
 #include "handler/SessionInitiator.h"
 #include "util/TemplateParameters.h"
@@ -74,6 +73,9 @@ namespace shibsp {
 
 pair<bool,long> FormSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
 {
+    if (!checkCompatibility(request, isHandler))
+        return make_pair(false,0L);
+
     string target;
     const char* option;
     const Application& app=request.getApplication();
index 87a3750..02e2550 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
 #include "Application.h"
 #include "exceptions.h"
 #include "ServiceProvider.h"
-#include "SPRequest.h"
 #include "handler/AbstractHandler.h"
 #include "handler/RemotedHandler.h"
 #include "handler/SessionInitiator.h"
@@ -204,6 +203,8 @@ SAML2SessionInitiator::SAML2SessionInitiator(const DOMElement* e, const char* ap
         string address = m_appId + loc.second + "::run::SAML2SI";
         setAddress(address.c_str());
     }
+
+    m_supportedOptions.insert("isPassive");
 }
 
 void SAML2SessionInitiator::setParent(const PropertySet* parent)
@@ -230,7 +231,7 @@ pair<bool,long> SAML2SessionInitiator::run(SPRequest& request, string& entityID,
     }
 
     // We have to know the IdP to function unless this is ECP.
-    if (!ECP && (entityID.empty()))
+    if ((!ECP && entityID.empty()) || !checkCompatibility(request, isHandler))
         return make_pair(false,0L);
 
     string target;
index 85b65bb..d95c05e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
 #include "internal.h"
 #include "Application.h"
 #include "exceptions.h"
-#include "SPRequest.h"
 #include "handler/AbstractHandler.h"
 #include "handler/SessionInitiator.h"
 
@@ -65,6 +64,7 @@ namespace shibsp {
             url = getString("entityIDParam");
             if (url.first)
                 m_returnParam = url.second;
+            m_supportedOptions.insert("isPassive");
         }
         virtual ~SAMLDSSessionInitiator() {}
 
@@ -146,7 +146,7 @@ pair<bool,long> SAMLDSSessionInitiator::run(SPRequest& request, string& entityID
 {
     // The IdP CANNOT be specified for us to run. Otherwise, we'd be redirecting to a DS
     // anytime the IdP's metadata was wrong.
-    if (!entityID.empty())
+    if (!entityID.empty() || !checkCompatibility(request, isHandler))
         return make_pair(false,0L);
 
     string target;
@@ -171,7 +171,11 @@ pair<bool,long> SAMLDSSessionInitiator::run(SPRequest& request, string& entityID
 
         option = request.getParameter("isPassive");
         if (option)
-            isPassive = !strcmp(option,"true");
+            isPassive = (*option=='t' || *option=='1');
+        else {
+            pair<bool,bool> passopt = getBool("isPassive");
+            isPassive = passopt.first && passopt.second;
+        }
 
         option = request.getParameter("discoveryURL");
         if (option)
@@ -182,7 +186,9 @@ pair<bool,long> SAMLDSSessionInitiator::run(SPRequest& request, string& entityID
         // The target resource is the current one and everything else is
         // defaulted or set by content policy.
         target=request.getRequestURL();
-        pair<bool,bool> passopt = getBool("isPassive");
+        pair<bool,bool> passopt = request.getRequestSettings().first->getBool("isPassive");
+        if (!passopt.first)
+            passopt = getBool("isPassive");
         isPassive = passopt.first && passopt.second;
         discoveryURL = request.getRequestSettings().first->getString("discoveryURL");
     }
index b02e7d0..8ee76b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
  */
 
 #include "internal.h"
+#include "exceptions.h"
 #include "SPRequest.h"
 #include "handler/SessionInitiator.h"
 
@@ -71,25 +72,101 @@ const char* SessionInitiator::getType() const
 }
 #endif
 
+const set<string>& SessionInitiator::getSupportedOptions() const
+{
+    return m_supportedOptions;
+}
+
+bool SessionInitiator::checkCompatibility(SPRequest& request, bool isHandler) const
+{
+    bool isPassive = false;
+    if (isHandler) {
+        const char* flag = request.getParameter("isPassive");
+        if (flag) {
+            isPassive = (*flag=='1' || *flag=='t');
+        }
+        else {
+            pair<bool,bool> flagprop = getBool("isPassive");
+            isPassive = (flagprop.first && flagprop.second);
+        }
+    }
+    else {
+        // It doesn't really make sense to use isPassive with automated sessions, but...
+        pair<bool,bool> flagprop = request.getRequestSettings().first->getBool("isPassive");
+        if (!flagprop.first)
+            flagprop = getBool("isPassive");
+        isPassive = (flagprop.first && flagprop.second);
+    }
+
+    // Check for support of isPassive if it's used.
+    if (isPassive && getSupportedOptions().count("isPassive") == 0) {
+        if (getParent()) {
+            log(SPRequest::SPInfo, "handler does not support isPassive option");
+            return false;
+        }
+        throw ConfigurationException("Unsupported option (isPassive) supplied to SessionInitiator.");
+    }
+
+    return true;
+}
+
 pair<bool,long> SessionInitiator::run(SPRequest& request, bool isHandler) const
 {
-    const char* entityID=NULL;
+    const char* entityID = NULL;
     pair<bool,const char*> param = getString("entityIDParam");
-
     if (isHandler) {
-        entityID=request.getParameter(param.first ? param.second : "entityID");
+        entityID = request.getParameter(param.first ? param.second : "entityID");
         if (!param.first && (!entityID || !*entityID))
             entityID=request.getParameter("providerId");
     }
     if (!entityID || !*entityID) {
-        RequestMapper::Settings settings = request.getRequestSettings();
-        param = settings.first->getString("entityID");
+        param = request.getRequestSettings().first->getString("entityID");
         if (param.first)
             entityID = param.second;
     }
     if (!entityID || !*entityID)
-        entityID=getString("entityID").second;
+        entityID = getString("entityID").second;
 
     string copy(entityID ? entityID : "");
-    return run(request, copy, isHandler);
+
+    try {
+        return run(request, copy, isHandler);
+    }
+    catch (exception& ex) {
+        // If it's a handler operation, and isPassive is used or returnOnError is set, we trap the error.
+        if (isHandler) {
+            bool returnOnError = false;
+            const char* flag = request.getParameter("isPassive");
+            if (flag && (*flag == 't' || *flag == '1')) {
+                returnOnError = true;
+            }
+            else {
+                pair<bool,bool> flagprop = getBool("isPassive");
+                if (flagprop.first && flagprop.second) {
+                    returnOnError = true;
+                }
+                else {
+                    flag = request.getParameter("returnOnError");
+                    if (flag) {
+                        returnOnError = (*flag=='1' || *flag=='t');
+                    }
+                    else {
+                        flagprop = getBool("returnOnError");
+                        returnOnError = (flagprop.first && flagprop.second);
+                    }
+                }
+            }
+
+            if (returnOnError) {
+                // Log it and attempt to recover relay state so we can get back.
+                log(SPRequest::SPError, ex.what());
+                log(SPRequest::SPInfo, "trapping SessionInitiator error condition and returning to target location");
+                const char* flag = request.getParameter("target");
+                string target(flag ? flag : "");
+                recoverRelayState(request.getApplication(), request, request, target, false);
+                return make_pair(true, request.sendRedirect(target.c_str()));
+            }
+        }
+        throw;
+    }
 }
index 7bdc6cd..72f431b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
 #include "Application.h"
 #include "exceptions.h"
 #include "ServiceProvider.h"
-#include "SPRequest.h"
 #include "handler/AbstractHandler.h"
 #include "handler/RemotedHandler.h"
 #include "handler/SessionInitiator.h"
@@ -113,7 +112,7 @@ void Shib1SessionInitiator::setParent(const PropertySet* parent)
 pair<bool,long> Shib1SessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
 {
     // We have to know the IdP to function.
-    if (entityID.empty())
+    if (entityID.empty() || !checkCompatibility(request, isHandler))
         return make_pair(false,0L);
 
     string target;
index 390d3d8..ac53b42 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -85,6 +85,7 @@ namespace shibsp {
                 string address = m_appId + loc.second + "::run::TransformSI";
                 setAddress(address.c_str());
             }
+            m_supportedOptions.insert("isPassive");
 
 #ifndef SHIBSP_LITE
             if (SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) {
@@ -157,7 +158,7 @@ void TransformSessionInitiator::setParent(const PropertySet* parent)
 pair<bool,long> TransformSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
 {
     // We have to have a candidate name to function.
-    if (entityID.empty())
+    if (entityID.empty() || !checkCompatibility(request, isHandler))
         return make_pair(false,0L);
 
     string target;
index aeeedf1..e56f75e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -82,7 +82,7 @@ pair<bool,long> WAYFSessionInitiator::run(SPRequest& request, string& entityID,
 {
     // The IdP CANNOT be specified for us to run. Otherwise, we'd be redirecting to a WAYF
     // anytime the IdP's metadata was wrong.
-    if (!entityID.empty())
+    if (!entityID.empty() || !checkCompatibility(request, isHandler))
         return make_pair(false,0L);
 
     string target;