Propagate specific errors out when no assertion is processed.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Wed, 28 Nov 2007 00:52:21 +0000 (00:52 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Wed, 28 Nov 2007 00:52:21 +0000 (00:52 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2646 cb58f699-b61c-0410-a6fe-9272a202ed29

shibsp/handler/impl/SAML1Consumer.cpp
shibsp/handler/impl/SAML2Consumer.cpp

index 367b687..4bcc88c 100644 (file)
@@ -162,14 +162,11 @@ void SAML1Consumer::implementProtocol(
     string contextualError;
 
     for (vector<saml1::Assertion*>::const_iterator a = assertions.begin(); a!=assertions.end(); ++a) {
-        // Skip unsigned assertion?
-        if (!(*a)->getSignature() && flag.first && flag.second) {
-            m_log.warn("found unsigned assertion in SAML response, ignoring it per signedAssertions policy");
-            badtokens.push_back(*a);
-            continue;
-        }
-
         try {
+            // Skip unsigned assertion?
+            if (!(*a)->getSignature() && flag.first && flag.second)
+                throw SecurityPolicyException("The incoming assertion was unsigned, violating local security policy.");
+
             // We clear the security flag, so we can tell whether the token was secured on its own.
             policy.setAuthenticated(false);
             policy.reset(true);
@@ -184,11 +181,8 @@ void SAML1Consumer::implementProtocol(
             policy.evaluate(*(*a));
             
             // If no security is in place now, we kick it.
-            if (!alreadySecured && !policy.isAuthenticated()) {
-                m_log.warn("unable to establish security of assertion");
-                badtokens.push_back(*a);
-                continue;
-            }
+            if (!alreadySecured && !policy.isAuthenticated())
+                throw SecurityPolicyException("Unable to establish security of incoming assertion.");
 
             // Now do profile and core semantic validation to ensure we can use it for SSO.
             ssoValidator.validateAssertion(*(*a));
@@ -210,6 +204,8 @@ void SAML1Consumer::implementProtocol(
         }
         catch (exception& ex) {
             m_log.warn("detected a problem with assertion: %s", ex.what());
+            if (!ssoStatement)
+                contextualError = ex.what();
             badtokens.push_back(*a);
         }
     }
index e171ad4..302fe0d 100644 (file)
@@ -148,14 +148,11 @@ void SAML2Consumer::implementProtocol(
     string contextualError;
 
     for (vector<saml2::Assertion*>::const_iterator a = assertions.begin(); a!=assertions.end(); ++a) {
-        // Skip unsigned assertion?
-        if (!(*a)->getSignature() && flag.first && flag.second) {
-            m_log.warn("found unsigned assertion in SAML response, ignoring it per signedAssertions policy");
-            badtokens.push_back(*a);
-            continue;
-        }
-
         try {
+            // Skip unsigned assertion?
+            if (!(*a)->getSignature() && flag.first && flag.second)
+                throw SecurityPolicyException("The incoming assertion was unsigned, violating local security policy.");
+
             // We clear the security flag, so we can tell whether the token was secured on its own.
             policy.setAuthenticated(false);
             policy.reset(true);
@@ -168,26 +165,15 @@ void SAML2Consumer::implementProtocol(
             policy.evaluate(*(*a));
             
             // If no security is in place now, we kick it.
-            if (!alreadySecured && !policy.isAuthenticated()) {
-                m_log.warn("unable to establish security of assertion");
-                badtokens.push_back(*a);
-                continue;
-            }
+            if (!alreadySecured && !policy.isAuthenticated())
+                throw SecurityPolicyException("Unable to establish security of incoming assertion.");
 
             // Now do profile and core semantic validation to ensure we can use it for SSO.
             ssoValidator.validateAssertion(*(*a));
 
             // Address checking.
-            try {
-                if (ssoValidator.getAddress())
-                    checkAddress(application, httpRequest, ssoValidator.getAddress());
-            }
-            catch (exception& ex) {
-                // We save off the message if there's no SSO statement yet.
-                if (!ssoStatement)
-                    contextualError = ex.what();
-                throw;
-            }
+            if (ssoValidator.getAddress())
+                checkAddress(application, httpRequest, ssoValidator.getAddress());
 
             // Track it as a valid token.
             tokens.push_back(*a);
@@ -207,6 +193,8 @@ void SAML2Consumer::implementProtocol(
         }
         catch (exception& ex) {
             m_log.warn("detected a problem with assertion: %s", ex.what());
+            if (!ssoStatement)
+                contextualError = ex.what();
             badtokens.push_back(*a);
         }
     }
@@ -237,14 +225,11 @@ void SAML2Consumer::implementProtocol(
         if (!decrypted)
             continue;
 
-        // Skip unsigned assertion?
-        if (!decrypted->getSignature() && flag.first && flag.second) {
-            m_log.warn("found unsigned assertion in SAML response, ignoring it per signedAssertions policy");
-            badtokens.push_back(decrypted);
-            continue;
-        }
-
         try {
+            // Skip unsigned assertion?
+            if (!decrypted->getSignature() && flag.first && flag.second)
+                throw SecurityPolicyException("The incoming assertion was unsigned, violating local security policy.");
+
             // We clear the security flag, so we can tell whether the token was secured on its own.
             policy.setAuthenticated(false);
             policy.reset(true);
@@ -260,26 +245,15 @@ void SAML2Consumer::implementProtocol(
             policy.evaluate(*decrypted);
             
             // If no security is in place now, we kick it.
-            if (!alreadySecured && !policy.isAuthenticated()) {
-                m_log.warn("unable to establish security of assertion");
-                badtokens.push_back(decrypted);
-                continue;
-            }
+            if (!alreadySecured && !policy.isAuthenticated())
+                throw SecurityPolicyException("Unable to establish security of incoming assertion.");
 
             // Now do profile and core semantic validation to ensure we can use it for SSO.
             ssoValidator.validateAssertion(*decrypted);
 
             // Address checking.
-            try {
-                if (ssoValidator.getAddress())
-                    checkAddress(application, httpRequest, ssoValidator.getAddress());
-            }
-            catch (exception& ex) {
-                // We save off the message if there's no SSO statement yet.
-                if (!ssoStatement)
-                    contextualError = ex.what();
-                throw;
-            }
+            if (ssoValidator.getAddress())
+                checkAddress(application, httpRequest, ssoValidator.getAddress());
 
             // Track it as a valid token.
             tokens.push_back(decrypted);
@@ -299,6 +273,8 @@ void SAML2Consumer::implementProtocol(
         }
         catch (exception& ex) {
             m_log.warn("detected a problem with assertion: %s", ex.what());
+            if (!ssoStatement)
+                contextualError = ex.what();
             badtokens.push_back(decrypted);
         }
     }