Revamped binding classes with security policy layer.
[shibboleth/cpp-opensaml.git] / samltest / saml1 / binding / SAML1ArtifactTest.h
index cfa8a2c..e5ebe30 100644 (file)
@@ -1,30 +1,30 @@
-/*
- *  Copyright 2001-2005 Internet2
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "binding.h"
-
-#include <saml/binding/ArtifactMap.h>
-#include <saml/saml1/core/Assertions.h>
-#include <saml/saml1/core/Protocols.h>
-#include <saml/saml1/binding/SAMLArtifactType0001.h>
-#include <xmltooling/validation/ValidatorSuite.h>
-
-using namespace opensaml::saml1p;
-using namespace opensaml::saml1;
-
+/*\r
+ *  Copyright 2001-2005 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include "binding.h"\r
+\r
+#include <saml/binding/ArtifactMap.h>\r
+#include <saml/saml1/core/Assertions.h>\r
+#include <saml/saml1/core/Protocols.h>\r
+#include <saml/saml1/binding/SAMLArtifactType0001.h>\r
+#include <xmltooling/validation/ValidatorSuite.h>\r
+\r
+using namespace opensaml::saml1p;\r
+using namespace opensaml::saml1;\r
+\r
 namespace {\r
     class SAML_DLLLOCAL _addcert : public binary_function<X509Data*,XSECCryptoX509*,void> {\r
     public:\r
@@ -36,81 +36,75 @@ namespace {
         }\r
     };\r
 };\r
-
-class SAML1ArtifactTest : public CxxTest::TestSuite,
-    public SAMLBindingBaseTestCase, public MessageEncoder::ArtifactGenerator, public MessageDecoder::ArtifactResolver {
-public:
-    void setUp() {
-        SAMLBindingBaseTestCase::setUp();
-    }
-
-    void tearDown() {
-        SAMLBindingBaseTestCase::tearDown();
-    }
-
-    void testSAML1Artifact() {
-        try {
-            // Read message to use from file.
-            string path = data_path + "saml1/binding/SAML1Assertion.xml";
-            ifstream in(path.c_str());
-            DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
-            XercesJanitor<DOMDocument> janitor(doc);
-            auto_ptr<Assertion> toSend(
-                dynamic_cast<Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
-                );
-            janitor.release();
-
-            // Encode message.
-            auto_ptr<MessageEncoder> encoder(
-                SAMLConfig::getConfig().MessageEncoderManager.newPlugin(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)
-                );
-            encoder->setArtifactGenerator(this);
-            encoder->encode(*this,toSend.get(),"https://sp.example.org/SAML/Artifact","https://sp.example.org/","state",m_creds);
-            toSend.release();
-            
-            // Decode message.
-            string relayState;
-            const RoleDescriptor* issuer=NULL;
-            const XMLCh* securityMech=NULL;
-            QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
-            auto_ptr<MessageDecoder> decoder(
-                SAMLConfig::getConfig().MessageDecoderManager.newPlugin(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)
-                );
-            decoder->setArtifactResolver(this);
-            Locker locker(m_metadata);
-            auto_ptr<Response> response(
-                dynamic_cast<Response*>(
-                    decoder->decode(relayState,issuer,securityMech,*this,m_metadata,&idprole,m_trust)
-                    )
-                );
-            
-            // Test the results.
-            TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
-            TSM_ASSERT("SAML Response not decoded successfully.", response.get());
-            TSM_ASSERT("Message was not verified.", issuer && securityMech && securityMech==samlconstants::SAML1P_NS);
-            auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
-            TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
-            TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
-
-            // Trigger a replay.
-            TSM_ASSERT_THROWS("Did not catch the replay.", 
-                decoder->decode(relayState,issuer,securityMech,*this,m_metadata,&idprole,m_trust),
-                BindingException);
-        }
-        catch (XMLToolingException& ex) {
-            TS_TRACE(ex.what());
-            throw;
-        }
-    }
-
-    SAMLArtifact* generateSAML1Artifact(const char* relyingParty) const {
-        return new SAMLArtifactType0001(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"));
-    }
-    
-    saml2p::SAML2Artifact* generateSAML2Artifact(const char* relyingParty) const {
-        throw BindingException("Not implemented.");
-    }
-    
+\r
+class SAML1ArtifactTest : public CxxTest::TestSuite,\r
+        public SAMLBindingBaseTestCase, public MessageEncoder::ArtifactGenerator, public MessageDecoder::ArtifactResolver {\r
+public:\r
+    void setUp() {\r
+        SAMLBindingBaseTestCase::setUp();\r
+    }\r
+\r
+    void tearDown() {\r
+        SAMLBindingBaseTestCase::tearDown();\r
+    }\r
+\r
+    void testSAML1Artifact() {\r
+        try {\r
+            QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);\r
+            SecurityPolicy policy(m_rules, m_metadata, &idprole, m_trust);\r
+\r
+            // Read message to use from file.\r
+            string path = data_path + "saml1/binding/SAML1Assertion.xml";\r
+            ifstream in(path.c_str());\r
+            DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
+            XercesJanitor<DOMDocument> janitor(doc);\r
+            auto_ptr<Assertion> toSend(\r
+                dynamic_cast<Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))\r
+                );\r
+            janitor.release();\r
+\r
+            // Encode message.\r
+            auto_ptr<MessageEncoder> encoder(\r
+                SAMLConfig::getConfig().MessageEncoderManager.newPlugin(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)\r
+                );\r
+            encoder->setArtifactGenerator(this);\r
+            encoder->encode(*this,toSend.get(),"https://sp.example.org/SAML/Artifact","https://sp.example.org/","state",m_creds);\r
+            toSend.release();\r
+            \r
+            // Decode message.\r
+            string relayState;\r
+            auto_ptr<MessageDecoder> decoder(\r
+                SAMLConfig::getConfig().MessageDecoderManager.newPlugin(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)\r
+                );\r
+            decoder->setArtifactResolver(this);\r
+            Locker locker(m_metadata);\r
+            auto_ptr<Response> response(dynamic_cast<Response*>(decoder->decode(relayState,*this,policy)));\r
+            \r
+            // Test the results.\r
+            TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");\r
+            TSM_ASSERT("SAML Response not decoded successfully.", response.get());\r
+            TSM_ASSERT("Message was not verified.", policy.getIssuer()!=NULL);\r
+            auto_ptr_char entityID(policy.getIssuer()->getName());\r
+            TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));\r
+            TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);\r
+\r
+            // Trigger a replay.\r
+            TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), BindingException);\r
+        }\r
+        catch (XMLToolingException& ex) {\r
+            TS_TRACE(ex.what());\r
+            throw;\r
+        }\r
+    }\r
+\r
+    SAMLArtifact* generateSAML1Artifact(const char* relyingParty) const {\r
+        return new SAMLArtifactType0001(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"));\r
+    }\r
+    \r
+    saml2p::SAML2Artifact* generateSAML2Artifact(const char* relyingParty) const {\r
+        throw BindingException("Not implemented.");\r
+    }\r
+    \r
     Signature* buildSignature(const CredentialResolver* credResolver) const\r
     {\r
         // Build a Signature.\r
@@ -129,39 +123,36 @@ public:
         \r
         return sig;\r
     }\r
-
-    Response* resolve(
-        const XMLCh*& securityMech,
-        const vector<SAMLArtifact*>& artifacts,
-        const IDPSSODescriptor& idpDescriptor,
-        const X509TrustEngine* trustEngine=NULL
-        ) const {
-        TSM_ASSERT_EQUALS("Too many artifacts.", artifacts.size(), 1);
-        XMLObject* xmlObject =
-            SAMLConfig::getConfig().getArtifactMap()->retrieveContent(artifacts.front(), "https://sp.example.org/");
-        Assertion* assertion = dynamic_cast<Assertion*>(xmlObject);
-        TSM_ASSERT("Not an assertion.", assertion!=NULL);
-        auto_ptr<Response> response(ResponseBuilder::buildResponse());
-        response->getAssertions().push_back(assertion);
-        Status* status = StatusBuilder::buildStatus();
-        response->setStatus(status);
-        StatusCode* sc = StatusCodeBuilder::buildStatusCode();
-        status->setStatusCode(sc);
-        sc->setValue(&StatusCode::SUCCESS);
-        response->setSignature(buildSignature(m_creds));
-        vector<Signature*> sigs(1,response->getSignature());
-        response->marshall((DOMDocument*)NULL,&sigs);
-        SchemaValidators.validate(response.get());
-        securityMech = NULL;
-        return response.release();
-    }
-
-    saml2p::ArtifactResponse* resolve(
-        const XMLCh*& securityMech,
-        const saml2p::SAML2Artifact& artifact,
-        const SSODescriptorType& ssoDescriptor,
-        const X509TrustEngine* trustEngine=NULL
-        ) const {
-        throw BindingException("Not implemented.");
-    }
-};
+\r
+    Response* resolve(\r
+        const vector<SAMLArtifact*>& artifacts,\r
+        const IDPSSODescriptor& idpDescriptor,\r
+        SecurityPolicy& policy\r
+        ) const {\r
+        TSM_ASSERT_EQUALS("Too many artifacts.", artifacts.size(), 1);\r
+        XMLObject* xmlObject =\r
+            SAMLConfig::getConfig().getArtifactMap()->retrieveContent(artifacts.front(), "https://sp.example.org/");\r
+        Assertion* assertion = dynamic_cast<Assertion*>(xmlObject);\r
+        TSM_ASSERT("Not an assertion.", assertion!=NULL);\r
+        auto_ptr<Response> response(ResponseBuilder::buildResponse());\r
+        response->getAssertions().push_back(assertion);\r
+        Status* status = StatusBuilder::buildStatus();\r
+        response->setStatus(status);\r
+        StatusCode* sc = StatusCodeBuilder::buildStatusCode();\r
+        status->setStatusCode(sc);\r
+        sc->setValue(&StatusCode::SUCCESS);\r
+        response->setSignature(buildSignature(m_creds));\r
+        vector<Signature*> sigs(1,response->getSignature());\r
+        response->marshall((DOMDocument*)NULL,&sigs);\r
+        SchemaValidators.validate(response.get());\r
+        return response.release();\r
+    }\r
+\r
+    saml2p::ArtifactResponse* resolve(\r
+        const saml2p::SAML2Artifact& artifact,\r
+        const SSODescriptorType& ssoDescriptor,\r
+        SecurityPolicy& policy\r
+        ) const {\r
+        throw BindingException("Not implemented.");\r
+    }\r
+};\r