Add setting to limit metadata caching.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / DynamicMetadataProvider.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/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 opensaml {
29     namespace saml2md {
30
31         /**
32          * Simple implementation of a dynamic, caching MetadataProvider.
33          */
34         class SAML_API DynamicMetadataProvider : public AbstractMetadataProvider
35         {
36         public:
37             /**
38              * Constructor.
39              *
40              * @param e DOM to supply configuration for provider
41              */
42             DynamicMetadataProvider(const xercesc::DOMElement* e=NULL);
43
44             virtual ~DynamicMetadataProvider();
45
46             xmltooling::Lockable* lock() {
47                 m_lock->rdlock();
48                 return this;
49             }
50
51             void unlock() {
52                 m_lock->unlock();
53             }
54
55             void init() {
56             }
57
58             const xmltooling::XMLObject* getMetadata() const {
59                 throw MetadataException("getMetadata operation not implemented on this provider.");
60             }
61
62             std::pair<const EntityDescriptor*,const RoleDescriptor*> getEntityDescriptor(const Criteria& criteria) const;
63
64         protected:
65             /** Controls XML schema validation. */
66             bool m_validate;
67
68             /** Caps the allowable cache duration of a metadata instance. */
69             time_t m_maxCacheDuration;
70
71             /**
72              * Resolves an entityID into a metadata instance for that entity.
73              *
74              * @param entityID      entity ID to resolve
75              * @return  a valid metadata instance
76              */
77             virtual EntityDescriptor* resolve(const char* entityID) const;
78
79         private:
80             mutable xmltooling::RWLock* m_lock;
81         };
82
83     };
84 };
85
86 #endif /* __saml2_dynmetadataprov_h__ */