2 * Copyright 2001-2005 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <saml/binding/ArtifactMap.h>
20 #include <saml/saml1/core/Assertions.h>
21 #include <saml/saml1/core/Protocols.h>
22 #include <saml/saml1/binding/SAMLArtifactType0001.h>
23 #include <xmltooling/validation/ValidatorSuite.h>
25 using namespace opensaml::saml1p;
26 using namespace opensaml::saml1;
28 class SAML1ArtifactTest : public CxxTest::TestSuite,
29 public SAMLBindingBaseTestCase, public MessageEncoder::ArtifactGenerator, public MessageDecoder::ArtifactResolver {
33 SAMLBindingBaseTestCase::setUp();
38 SAMLBindingBaseTestCase::tearDown();
41 void testSAML1Artifact() {
43 // Read message to use from file.
44 string path = data_path + "saml1/binding/SAML1Assertion.xml";
45 ifstream in(path.c_str());
46 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
47 XercesJanitor<DOMDocument> janitor(doc);
48 auto_ptr<Assertion> toSend(
49 dynamic_cast<Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
54 auto_ptr<MessageEncoder> encoder(
55 SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAMLConstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)
57 encoder->setArtifactGenerator(this);
58 encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state",m_creds);
63 const RoleDescriptor* issuer=NULL;
65 QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
66 auto_ptr<MessageDecoder> decoder(
67 SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAMLConstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)
69 decoder->setArtifactResolver(this);
70 Locker locker(m_metadata);
71 auto_ptr<Response> response(
72 dynamic_cast<Response*>(
73 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust)
78 TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
79 TSM_ASSERT("SAML Response not decoded successfully.", response.get());
80 TSM_ASSERT("Message was not verified.", issuer && trusted);
81 auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
82 TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
83 TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
86 TSM_ASSERT_THROWS("Did not catch the replay.",
87 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust),
90 catch (XMLToolingException& ex) {
96 const char* getMethod() const {
100 const char* getRequestURL() const {
101 return "https://sp.example.org/SAML/Artifact";
104 const char* getQueryString() const {
108 SAMLArtifact* generateSAML1Artifact(const char* relyingParty) const {
109 return new SAMLArtifactType0001(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"));
112 saml2p::SAML2Artifact* generateSAML2Artifact(const char* relyingParty) const {
113 throw BindingException("Not implemented.");
118 const vector<SAMLArtifact*>& artifacts,
119 const IDPSSODescriptor& idpDescriptor,
120 const X509TrustEngine* trustEngine=NULL
122 TSM_ASSERT_EQUALS("Too many artifacts.", artifacts.size(), 1);
123 XMLObject* xmlObject =
124 SAMLConfig::getConfig().getArtifactMap()->retrieveContent(artifacts.front(), "https://sp.example.org/");
125 Assertion* assertion = dynamic_cast<Assertion*>(xmlObject);
126 TSM_ASSERT("Not an assertion.", assertion!=NULL);
127 auto_ptr<Response> response(ResponseBuilder::buildResponse());
128 response->getAssertions().push_back(assertion);
129 Status* status = StatusBuilder::buildStatus();
130 response->setStatus(status);
131 StatusCode* sc = StatusCodeBuilder::buildStatusCode();
132 status->setStatusCode(sc);
133 sc->setValue(&StatusCode::SUCCESS);
134 response->marshall();
135 SchemaValidators.validate(response.get());
136 authenticated = true;
137 return response.release();
140 saml2p::ArtifactResponse* resolve(
142 const saml2p::SAML2Artifact& artifact,
143 const SSODescriptorType& ssoDescriptor,
144 const X509TrustEngine* trustEngine=NULL
146 throw BindingException("Not implemented.");