Fix linefeeds
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / ChainingMetadataProvider.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 /**
18  * @file saml/security/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/util/Threads.h>
28
29 namespace opensaml {
30     namespace saml2md {
31         
32         /**
33          * MetadataProvider that uses multiple providers in sequence.
34          */
35         class SAML_API ChainingMetadataProvider
36             : public ObservableMetadataProvider, public ObservableMetadataProvider::Observer {
37         public:
38             /**
39              * Constructor.
40              * 
41              * If a DOM is supplied, the following XML content is supported:
42              * 
43              * <ul>
44              *  <li>&lt;MetadataProvider&gt; elements with a type attribute
45              * </ul>
46              * 
47              * XML namespaces are ignored in the processing of this content.
48              * 
49              * @param e DOM to supply configuration for provider
50              */
51             ChainingMetadataProvider(const DOMElement* e=NULL);
52             
53             /**
54              * Destructor will delete any embedded engines.
55              */
56             virtual ~ChainingMetadataProvider();
57     
58             /**
59              * Adds a provider for future calls. The provider <strong>MUST</strong> be
60              * initialized before adding it. 
61              * 
62              * @param newProvider provider to add
63              */
64             void addMetadataProvider(MetadataProvider* newProvider) {
65                 m_providers.push_back(newProvider);
66             }
67     
68             /**
69              * Removes a provider. The caller must delete the provider if necessary.
70              * 
71              * @param oldProvider provider to remove
72              * @return  the old provider
73              */
74             MetadataProvider* removeMetadataProvider(MetadataProvider* oldProvider) {
75                 for (std::vector<MetadataProvider*>::iterator i=m_providers.begin(); i!=m_providers.end(); i++) {
76                     if (oldProvider==(*i)) {
77                         m_providers.erase(i);
78                         return oldProvider;
79                     }
80                 }
81                 return NULL;
82             }
83
84             xmltooling::Lockable* lock();
85             void unlock();
86             void init();
87             const xmlsignature::KeyResolver* getKeyResolver() const;
88             const xmltooling::XMLObject* getMetadata() const;
89             const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
90             const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const;
91             const EntityDescriptor* getEntityDescriptor(const SAMLArtifact* artifact) const;
92             void onEvent(MetadataProvider& provider);
93     
94         private:
95             xmltooling::ThreadKey* m_tlsKey;
96             std::vector<MetadataProvider*> m_providers;
97         };
98     };    
99 };
100
101 #endif /* __saml_chainmeta_h__ */