1310374344e7d862d84781d3c97f654349ca7cec
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / ChainingMetadataProvider.h
1 /*
2  *  Copyright 2001-2007 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 /**
18  * @file saml/saml2/metadata/ChainingMetadataProvider.h
19  * 
20  * MetadataProvider that uses multiple providers in sequence.
21  */
22
23 #ifndef __saml_chainmeta_h__
24 #define __saml_chainmeta_h__
25
26 #include <saml/saml2/metadata/ObservableMetadataProvider.h>
27 #include <xmltooling/logging.h>
28 #include <xmltooling/util/Threads.h>
29
30 namespace opensaml {
31     namespace saml2md {
32
33 #if defined (_MSC_VER)
34         #pragma warning( push )
35         #pragma warning( disable : 4251 )
36 #endif
37
38         /**
39          * MetadataProvider that uses multiple providers in sequence.
40          */
41         class SAML_API ChainingMetadataProvider
42             : public ObservableMetadataProvider, public ObservableMetadataProvider::Observer {
43         public:
44             /**
45              * Constructor.
46              * 
47              * If a DOM is supplied, the following XML content is supported:
48              * 
49              * <ul>
50              *  <li>&lt;MetadataProvider&gt; elements with a type attribute
51              * </ul>
52              * 
53              * XML namespaces are ignored in the processing of this content.
54              * 
55              * @param e DOM to supply configuration for provider
56              */
57             ChainingMetadataProvider(const xercesc::DOMElement* e=NULL);
58             
59             /**
60              * Destructor will delete any embedded engines.
61              */
62             virtual ~ChainingMetadataProvider();
63     
64             /**
65              * Adds a provider for future calls. The provider <strong>MUST</strong> be
66              * initialized before adding it. 
67              * 
68              * @param newProvider provider to add
69              */
70             void addMetadataProvider(MetadataProvider* newProvider) {
71                 m_providers.push_back(newProvider);
72             }
73     
74             /**
75              * Removes a provider. The caller must delete the provider if necessary.
76              * 
77              * @param oldProvider provider to remove
78              * @return  the old provider
79              */
80             MetadataProvider* removeMetadataProvider(MetadataProvider* oldProvider) {
81                 for (std::vector<MetadataProvider*>::iterator i=m_providers.begin(); i!=m_providers.end(); i++) {
82                     if (oldProvider==(*i)) {
83                         m_providers.erase(i);
84                         return oldProvider;
85                     }
86                 }
87                 return NULL;
88             }
89
90             using MetadataProvider::getEntityDescriptor;
91             using MetadataProvider::getEntitiesDescriptor;
92
93             xmltooling::Lockable* lock();
94             void unlock();
95             void init();
96             const xmltooling::XMLObject* getMetadata() const;
97             const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
98             std::pair<const EntityDescriptor*,const RoleDescriptor*> getEntityDescriptor(const Criteria& criteria) const;
99             void onEvent(const ObservableMetadataProvider& provider) const;
100     
101             const xmltooling::Credential* resolve(const xmltooling::CredentialCriteria* criteria=NULL) const;
102             std::vector<const xmltooling::Credential*>::size_type resolve(
103                 std::vector<const xmltooling::Credential*>& results, const xmltooling::CredentialCriteria* criteria=NULL
104                 ) const;
105
106         private:
107             bool m_firstMatch;
108             xmltooling::ThreadKey* m_tlsKey;
109             std::vector<MetadataProvider*> m_providers;
110             xmltooling::logging::Category& m_log;
111         };
112
113 #if defined (_MSC_VER)
114         #pragma warning( pop )
115 #endif
116
117     };
118 };
119
120 #endif /* __saml_chainmeta_h__ */