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