2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "internal.h"
\r
18 #include <saml/SAMLConfig.h>
\r
19 #include <saml/security/TrustEngine.h>
\r
20 #include <saml/saml2/metadata/MetadataProvider.h>
\r
22 using namespace opensaml::saml2;
\r
23 using namespace opensaml::saml2md;
\r
24 using namespace xmlsignature;
\r
26 class ExplicitKeyTrustEngineTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
29 SAMLObjectBaseTestCase::setUp();
\r
33 SAMLObjectBaseTestCase::tearDown();
\r
36 void testExplicitKeyTrustEngine() {
\r
37 string config = data_path + "security/FilesystemMetadataProvider.xml";
\r
38 ifstream in(config.c_str());
\r
39 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
40 XercesJanitor<DOMDocument> janitor(doc);
\r
42 auto_ptr_XMLCh path("path");
\r
43 string s = data_path + "security/example-metadata.xml";
\r
44 auto_ptr_XMLCh file(s.c_str());
\r
45 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
47 // Build metadata provider.
\r
48 auto_ptr<MetadataProvider> metadataProvider(
\r
49 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
52 metadataProvider->init();
\r
54 catch (XMLToolingException& ex) {
\r
55 TS_TRACE(ex.what());
\r
59 // Build trust engine.
\r
60 auto_ptr<opensaml::TrustEngine> trustEngine(
\r
61 SAMLConfig::getConfig().TrustEngineManager.newPlugin(EXPLICIT_KEY_SAMLTRUSTENGINE, NULL)
\r
64 // Get signed assertion.
\r
65 config = data_path + "signature/SAML2Assertion.xml";
\r
66 ifstream in2(config.c_str());
\r
67 DOMDocument* doc2=XMLToolingConfig::getConfig().getParser().parse(in2);
\r
68 XercesJanitor<DOMDocument> janitor2(doc2);
\r
69 auto_ptr<Assertion> assertion(dynamic_cast<Assertion*>(XMLObjectBuilder::getBuilder(doc2->getDocumentElement())->buildFromDocument(doc2)));
\r
72 Locker locker(metadataProvider.get());
\r
73 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor("https://idp.example.org");
\r
74 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
76 RoleDescriptor* role=descriptor->getIDPSSODescriptors().front();
\r
77 TSM_ASSERT("Role not present", role!=NULL);
\r
79 Signature* sig=assertion->getSignature();
\r
80 TSM_ASSERT("Signature not present", sig!=NULL);
\r
81 TSM_ASSERT("Signature failed to validate.", trustEngine->validate(*sig, *role, metadataProvider->getKeyResolver()));
\r
83 descriptor = metadataProvider->getEntityDescriptor("https://idp2.example.org");
\r
84 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
86 role=descriptor->getIDPSSODescriptors().front();
\r
87 TSM_ASSERT("Role not present", role!=NULL);
\r
89 TSM_ASSERT("Signature validated.", !trustEngine->validate(*sig, *role, metadataProvider->getKeyResolver()));
\r