Moved ReplayCache into xmltooling
[shibboleth/cpp-opensaml.git] / samltest / binding.h
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "internal.h"
18
19 #include <saml/SAMLConfig.h>
20 #include <saml/binding/MessageDecoder.h>
21 #include <saml/binding/MessageEncoder.h>
22 #include <saml/saml2/metadata/MetadataProvider.h>
23 #include <saml/security/X509TrustEngine.h>
24
25 using namespace saml2md;
26 using namespace xmlsignature;
27
28 class SAMLBindingBaseTestCase : public MessageDecoder::HTTPRequest
29 {
30 protected:
31     CredentialResolver* m_creds; 
32     MetadataProvider* m_metadata;
33     opensaml::X509TrustEngine* m_trust;
34     map<string,string> m_fields;
35
36 public:
37     void setUp() {
38         m_creds=NULL;
39         m_metadata=NULL;
40         m_trust=NULL;
41         m_fields.clear();
42
43         try {
44             string config = data_path + "binding/ExampleMetadataProvider.xml";
45             ifstream in(config.c_str());
46             DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
47             XercesJanitor<DOMDocument> janitor(doc);
48     
49             auto_ptr_XMLCh path("path");
50             string s = data_path + "binding/example-metadata.xml";
51             auto_ptr_XMLCh file(s.c_str());
52             doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
53     
54             m_metadata = SAMLConfig::getConfig().MetadataProviderManager.newPlugin(
55                 FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement()
56                 );
57             m_metadata->init();
58
59             config = data_path + "FilesystemCredentialResolver.xml";
60             ifstream in2(config.c_str());
61             DOMDocument* doc2=XMLToolingConfig::getConfig().getParser().parse(in2);
62             XercesJanitor<DOMDocument> janitor2(doc2);
63             m_creds = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(
64                 FILESYSTEM_CREDENTIAL_RESOLVER,doc2->getDocumentElement()
65                 );
66                 
67             m_trust = dynamic_cast<X509TrustEngine*>(
68                 SAMLConfig::getConfig().TrustEngineManager.newPlugin(EXPLICIT_KEY_SAMLTRUSTENGINE, NULL)
69                 );
70         }
71         catch (XMLToolingException& ex) {
72             TS_TRACE(ex.what());
73             tearDown();
74             throw;
75         }
76
77     }
78     
79     void tearDown() {
80         delete m_creds;
81         delete m_metadata;
82         delete m_trust;
83         m_creds=NULL;
84         m_metadata=NULL;
85         m_trust=NULL;
86         m_fields.clear();
87     }
88
89     const char* getParameter(const char* name) const {
90         map<string,string>::const_iterator i=m_fields.find(name);
91         return i==m_fields.end() ? NULL : i->second.c_str();
92     }
93
94     vector<const char*>::size_type getParameters(const char* name, vector<const char*>& values) const {
95         values.clear();
96         map<string,string>::const_iterator i=m_fields.find(name);
97         if (i!=m_fields.end())
98             values.push_back(i->second.c_str());
99         return values.size();
100     }
101 };