-/*\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/saml2/core/Protocols.h>\r
-#include <saml/saml2/binding/SAML2ArtifactType0004.h>\r
-#include <xmltooling/validation/ValidatorSuite.h>\r
-\r
-using namespace opensaml::saml2p;\r
-using namespace opensaml::saml2;\r
-\r
-class SAML2ArtifactTest : 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 testSAML2Artifact() {\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 + "saml2/binding/SAML2Response.xml";\r
- ifstream in(path.c_str());\r
- DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
- XercesJanitor<DOMDocument> janitor(doc);\r
- auto_ptr<Response> toSend(\r
- dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))\r
- );\r
- janitor.release();\r
-\r
- // Freshen timestamp.\r
- toSend->setIssueInstant(time(NULL));\r
-\r
- // Encode message.\r
- auto_ptr<MessageEncoder> encoder(\r
- SAMLConfig::getConfig().MessageEncoderManager.newPlugin(samlconstants::SAML20_BINDING_HTTP_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::SAML20_BINDING_HTTP_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("RelayState 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
- throw BindingException("Not implemented.");\r
- }\r
- \r
- saml2p::SAML2Artifact* generateSAML2Artifact(const char* relyingParty) const {\r
- return new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"),1);\r
- }\r
- \r
- saml1p::Response* resolve(\r
- const vector<SAMLArtifact*>& artifacts,\r
- const IDPSSODescriptor& idpDescriptor,\r
- SecurityPolicy& policy\r
- ) const {\r
- throw BindingException("Not implemented.");\r
- }\r
-\r
- ArtifactResponse* resolve(\r
- const SAML2Artifact& artifact,\r
- const SSODescriptorType& ssoDescriptor,\r
- SecurityPolicy& policy\r
- ) const {\r
- XMLObject* xmlObject =\r
- SAMLConfig::getConfig().getArtifactMap()->retrieveContent(&artifact, "https://sp.example.org/");\r
- Response* payload = dynamic_cast<Response*>(xmlObject);\r
- TSM_ASSERT("Not a response.", payload!=NULL);\r
- auto_ptr<ArtifactResponse> response(ArtifactResponseBuilder::buildArtifactResponse());\r
- response->setPayload(payload);\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->marshall();\r
- SchemaValidators.validate(response.get());\r
- return response.release();\r
- }\r
-};\r
+/*
+ * Copyright 2001-2007 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/saml2/core/Protocols.h>
+#include <saml/saml2/binding/SAML2ArtifactType0004.h>
+#include <xmltooling/validation/ValidatorSuite.h>
+
+using namespace opensaml::saml2p;
+using namespace opensaml::saml2;
+
+class SAML2ArtifactTest : public CxxTest::TestSuite,
+ public SAMLBindingBaseTestCase, public MessageEncoder::ArtifactGenerator, public MessageDecoder::ArtifactResolver {
+public:
+ void setUp() {
+ SAMLBindingBaseTestCase::setUp();
+ }
+
+ void tearDown() {
+ SAMLBindingBaseTestCase::tearDown();
+ }
+
+ void testSAML2Artifact() {
+ try {
+ QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
+ SecurityPolicy policy(m_rules2, m_metadata, &idprole, m_trust, false);
+
+ // Read message to use from file.
+ string path = data_path + "saml2/binding/SAML2Response.xml";
+ ifstream in(path.c_str());
+ DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
+ XercesJanitor<DOMDocument> janitor(doc);
+ auto_ptr<Response> toSend(
+ dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
+ );
+ janitor.release();
+
+ CredentialCriteria cc;
+ cc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL);
+ Locker clocker(m_creds);
+ const Credential* cred = m_creds->resolve(&cc);
+ TSM_ASSERT("Retrieved credential was null", cred!=NULL);
+
+ // Freshen timestamp.
+ toSend->setIssueInstant(time(NULL));
+
+ // Encode message.
+ auto_ptr<MessageEncoder> encoder(
+ SAMLConfig::getConfig().MessageEncoderManager.newPlugin(
+ samlconstants::SAML20_BINDING_HTTP_ARTIFACT, pair<const DOMElement*,const XMLCh*>(NULL,NULL)
+ )
+ );
+ Locker locker(m_metadata);
+ encoder->encode(
+ *this,toSend.get(),"https://sp.example.org/SAML/SSO",m_metadata->getEntityDescriptor("https://sp.example.org/"),"state",this,cred
+ );
+ toSend.release();
+
+ // Decode message.
+ string relayState;
+ auto_ptr<MessageDecoder> decoder(
+ SAMLConfig::getConfig().MessageDecoderManager.newPlugin(
+ samlconstants::SAML20_BINDING_HTTP_ARTIFACT, pair<const DOMElement*,const XMLCh*>(NULL,NULL)
+ )
+ );
+ decoder->setArtifactResolver(this);
+ auto_ptr<Response> response(dynamic_cast<Response*>(decoder->decode(relayState,*this,policy)));
+
+ // Test the results.
+ TSM_ASSERT_EQUALS("RelayState was not the expected result.", relayState, "state");
+ TSM_ASSERT("SAML Response not decoded successfully.", response.get());
+ TSM_ASSERT("Message was not verified.", policy.isSecure());
+ auto_ptr_char entityID(policy.getIssuer()->getName());
+ 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.
+ policy.reset();
+ TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), BindingException);
+ }
+ catch (XMLToolingException& ex) {
+ TS_TRACE(ex.what());
+ throw;
+ }
+ }
+
+ SAMLArtifact* generateSAML1Artifact(const EntityDescriptor* relyingParty) const {
+ throw BindingException("Not implemented.");
+ }
+
+ saml2p::SAML2Artifact* generateSAML2Artifact(const EntityDescriptor* relyingParty) const {
+ return new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"),1);
+ }
+
+ saml1p::Response* resolve(
+ const vector<SAMLArtifact*>& artifacts,
+ const IDPSSODescriptor& idpDescriptor,
+ SecurityPolicy& policy
+ ) const {
+ throw BindingException("Not implemented.");
+ }
+
+ ArtifactResponse* resolve(
+ const SAML2Artifact& artifact,
+ const SSODescriptorType& ssoDescriptor,
+ SecurityPolicy& policy
+ ) const {
+ XMLObject* xmlObject =
+ SAMLConfig::getConfig().getArtifactMap()->retrieveContent(&artifact, "https://sp.example.org/");
+ Response* payload = dynamic_cast<Response*>(xmlObject);
+ TSM_ASSERT("Not a response.", payload!=NULL);
+
+ auto_ptr<ArtifactResponse> response(ArtifactResponseBuilder::buildArtifactResponse());
+ response->setPayload(payload);
+ Status* status = StatusBuilder::buildStatus();
+ response->setStatus(status);
+ StatusCode* sc = StatusCodeBuilder::buildStatusCode();
+ status->setStatusCode(sc);
+ sc->setValue(StatusCode::SUCCESS);
+ response->marshall();
+ SchemaValidators.validate(response.get());
+ policy.evaluate(*(response.get()), this);
+ return response.release();
+ }
+};