7ddd68bfdf611e853bbdf7463ded4bfc8e956202
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / DynamicMetadataProvider.h
1 /*
2  *  Copyright 2001-2010 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/DynamicMetadataProvider.h
19  *
20  * Simple implementation of a dynamic caching MetadataProvider.
21  */
22
23 #ifndef __saml2_dynmetadataprov_h__
24 #define __saml2_dynmetadataprov_h__
25
26 #include <saml/saml2/metadata/AbstractMetadataProvider.h>
27
28 namespace xmltooling {
29     class XMLTOOL_API RWLock;
30 };
31
32 namespace opensaml {
33     namespace saml2md {
34
35         /**
36          * Simple implementation of a dynamic, caching MetadataProvider.
37          */
38         class SAML_API DynamicMetadataProvider : public AbstractMetadataProvider
39         {
40         public:
41             /**
42              * Constructor.
43              *
44              * @param e DOM to supply configuration for provider
45              */
46             DynamicMetadataProvider(const xercesc::DOMElement* e=nullptr);
47
48             virtual ~DynamicMetadataProvider();
49
50             void init();
51             xmltooling::Lockable* lock();
52             void unlock();
53             const xmltooling::XMLObject* getMetadata() const;
54             std::pair<const EntityDescriptor*,const RoleDescriptor*> getEntityDescriptor(const Criteria& criteria) const;
55
56         protected:
57             /** Controls XML schema validation. */
58             bool m_validate;
59
60             /**
61              * Resolves a metadata instance using the supplied criteria.
62              *
63              * @param criteria  lookup criteria
64              * @return  a valid metadata instance
65              */
66             virtual EntityDescriptor* resolve(const Criteria& criteria) const;
67
68         private:
69             mutable xmltooling::RWLock* m_lock;
70             double m_refreshDelayFactor;
71             time_t m_minCacheDuration, m_maxCacheDuration;
72             typedef std::map<xmltooling::xstring,time_t> cachemap_t;
73             mutable cachemap_t m_cacheMap;
74         };
75
76     };
77 };
78
79 #endif /* __saml2_dynmetadataprov_h__ */