Major revamp of credential and trust handling code, PKIX engine still needs work.
[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/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 #if defined (_MSC_VER)
33         #pragma warning( push )
34         #pragma warning( disable : 4251 )
35 #endif
36
37         /**
38          * MetadataProvider that uses multiple providers in sequence.
39          */
40         class SAML_API ChainingMetadataProvider
41             : public ObservableMetadataProvider, public ObservableMetadataProvider::Observer {
42         public:
43             /**
44              * Constructor.
45              * 
46              * If a DOM is supplied, the following XML content is supported:
47              * 
48              * <ul>
49              *  <li>&lt;MetadataProvider&gt; elements with a type attribute
50              * </ul>
51              * 
52              * XML namespaces are ignored in the processing of this content.
53              * 
54              * @param e DOM to supply configuration for provider
55              */
56             ChainingMetadataProvider(const DOMElement* e=NULL);
57             
58             /**
59              * Destructor will delete any embedded engines.
60              */
61             virtual ~ChainingMetadataProvider();
62     
63             /**
64              * Adds a provider for future calls. The provider <strong>MUST</strong> be
65              * initialized before adding it. 
66              * 
67              * @param newProvider provider to add
68              */
69             void addMetadataProvider(MetadataProvider* newProvider) {
70                 m_providers.push_back(newProvider);
71             }
72     
73             /**
74              * Removes a provider. The caller must delete the provider if necessary.
75              * 
76              * @param oldProvider provider to remove
77              * @return  the old provider
78              */
79             MetadataProvider* removeMetadataProvider(MetadataProvider* oldProvider) {
80                 for (std::vector<MetadataProvider*>::iterator i=m_providers.begin(); i!=m_providers.end(); i++) {
81                     if (oldProvider==(*i)) {
82                         m_providers.erase(i);
83                         return oldProvider;
84                     }
85                 }
86                 return NULL;
87             }
88
89             xmltooling::Lockable* lock();
90             void unlock();
91             void init();
92             const xmltooling::XMLObject* getMetadata() const;
93             const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
94             const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const;
95             const EntityDescriptor* getEntityDescriptor(const SAMLArtifact* artifact) const;
96             void onEvent(MetadataProvider& provider);
97     
98             const xmltooling::Credential* resolve(const xmltooling::CredentialCriteria* criteria=NULL) const;
99             std::vector<const xmltooling::Credential*>::size_type resolve(
100                 std::vector<const xmltooling::Credential*>& results, const xmltooling::CredentialCriteria* criteria=NULL
101                 ) const;
102
103         private:
104             xmltooling::ThreadKey* m_tlsKey;
105             std::vector<MetadataProvider*> m_providers;
106         };
107
108 #if defined (_MSC_VER)
109         #pragma warning( pop )
110 #endif
111
112     };
113 };
114
115 #endif /* __saml_chainmeta_h__ */