Redesign condition and profile processing based on new policy rules. Fix element...
[shibboleth/cpp-sp.git] / shibsp / handler / impl / AssertionConsumerService.cpp
index 8a4dae1..ead66b3 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.
@@ -147,34 +147,36 @@ pair<bool,long> AssertionConsumerService::processMessage(
     Locker metadataLocker(application.getMetadataProvider());
 
     // Create the policy.
-    shibsp::SecurityPolicy policy(application, &m_role, validate.first && validate.second);
+    auto_ptr<opensaml::SecurityPolicy> policy(
+        createSecurityPolicy(application, &m_role, validate.first && validate.second, policyId.second)
+        );
 
     string relayState;
-    const char* m_template =  getString("postTemplate").second;
-
     try {
         // Decode the message and process it in a protocol-specific way.
-        auto_ptr<XMLObject> msg(m_decoder->decode(relayState, httpRequest, policy));
+        auto_ptr<XMLObject> msg(m_decoder->decode(relayState, httpRequest, *(policy.get())));
         if (!msg.get())
             throw BindingException("Failed to decode an SSO protocol response.");
-        string postData;
-        recoverPostData(application, httpRequest, httpResponse, postData, relayState);
+        DDF postData = recoverPostData(application, httpRequest, httpResponse, relayState.c_str());
+        DDFJanitor postjan(postData);
         recoverRelayState(application, httpRequest, httpResponse, relayState);
-        implementProtocol(application, httpRequest, httpResponse, policy, settings, *msg.get());
+        implementProtocol(application, httpRequest, httpResponse, *(policy.get()), settings, *msg.get());
 
-        auto_ptr_char issuer(policy.getIssuer() ? policy.getIssuer()->getName() : NULL);
+        auto_ptr_char issuer(policy->getIssuer() ? policy->getIssuer()->getName() : NULL);
 
         // History cookie.
         if (issuer.get() && *issuer.get())
             maintainHistory(application, httpRequest, httpResponse, issuer.get());
 
         // Now redirect to the state value. By now, it should be set to *something* usable.
-        if (postData.empty()) {
-          m_log.debug("ACS returning via redirect to: %s", relayState.c_str());
-          return make_pair(true, httpResponse.sendRedirect(relayState.c_str()));
-        } else {
-          m_log.debug("ACS returning via post to: %s", relayState.c_str());
-          return make_pair(true,sendPostResponse(application, httpResponse, relayState, postData));
+        // First check for POST data.
+        if (!postData.islist()) {
+            m_log.debug("ACS returning via redirect to: %s", relayState.c_str());
+            return make_pair(true, httpResponse.sendRedirect(relayState.c_str()));
+        }
+        else {
+            m_log.debug("ACS returning via POST to: %s", relayState.c_str());
+            return make_pair(true, sendPostResponse(application, httpResponse, relayState.c_str(), postData));
         }
     }
     catch (XMLToolingException& ex) {
@@ -221,7 +223,8 @@ void AssertionConsumerService::checkAddress(const Application& application, cons
 
 #ifndef SHIBSP_LITE
 
-void AssertionConsumerService::generateMetadata(SPSSODescriptor& role, const char* handlerURL) const {
+void AssertionConsumerService::generateMetadata(SPSSODescriptor& role, const char* handlerURL) const
+{
     const char* loc = getString("Location").second;
     string hurl(handlerURL);
     if (*loc != '/')
@@ -244,6 +247,13 @@ void AssertionConsumerService::generateMetadata(SPSSODescriptor& role, const cha
     role.getAssertionConsumerServices().push_back(ep);
 }
 
+opensaml::SecurityPolicy* AssertionConsumerService::createSecurityPolicy(
+    const Application& application, const xmltooling::QName* role, bool validate, const char* policyId
+    ) const
+{
+    return new SecurityPolicy(application, role, validate, policyId);
+}
+
 class SHIBSP_DLLLOCAL DummyContext : public ResolutionContext
 {
 public: