72b9bbffcc6f0f44809711fd8d4af9c4fee629de
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / DynamicMetadataProvider.h
1 /*
2  *  Copyright 2001-2009 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=NULL);
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             /** Caps the allowable cache duration of a metadata instance. */
61             time_t m_maxCacheDuration;
62
63             /**
64              * Resolves a metadata instance using the supplied criteria.
65              *
66              * @param criteria  lookup criteria
67              * @return  a valid metadata instance
68              */
69             virtual EntityDescriptor* resolve(const Criteria& criteria) const;
70
71         private:
72             mutable xmltooling::RWLock* m_lock;
73             typedef std::map<xmltooling::xstring,time_t> cachemap_t;
74             mutable cachemap_t m_cacheMap;
75         };
76
77     };
78 };
79
80 #endif /* __saml2_dynmetadataprov_h__ */