c0bc64bb527391b4cdf1e510962f77a0758c5eb7
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / AbstractMetadataProvider.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/AbstractMetadataProvider.h
19  * 
20  * Base class for caching metadata providers.
21  */
22
23 #ifndef __saml2_absmetadataprov_h__
24 #define __saml2_absmetadataprov_h__
25
26 #include <saml/saml2/metadata/ObservableMetadataProvider.h>
27
28 namespace opensaml {
29
30     namespace saml2md {
31         
32         /**
33          * Base class for caching metadata providers.
34          */
35         class SAML_API AbstractMetadataProvider : public ObservableMetadataProvider
36         {
37         protected:
38             /**
39              * Constructor.
40              * 
41              * If a DOM is supplied, a set of default logic will be used to identify
42              * and build a KeyResolver plugin and install it into the provider.
43              * 
44              * The following XML content is supported:
45              * 
46              * <ul>
47              *  <li>&lt;KeyResolver&gt; elements with a type attribute
48              * </ul>
49              * 
50              * XML namespaces are ignored in the processing of these elements.
51              * 
52              * @param e DOM to supply configuration for provider
53              */
54             AbstractMetadataProvider(const DOMElement* e=NULL);
55             
56             void emitChangeEvent();
57             
58         public:
59             virtual ~AbstractMetadataProvider();
60             
61             virtual const xmltooling::KeyResolver* getKeyResolver() const {
62                 return m_resolver;
63             }
64             
65             virtual const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const;
66             virtual const EntityDescriptor* getEntityDescriptor(const SAMLArtifact* artifact) const;
67             virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
68
69         protected:
70             /** Embedded KeyResolver instance. */
71             xmltooling::KeyResolver* m_resolver;
72
73             /**
74              * Loads an entity into the cache for faster lookup. This includes
75              * processing known reverse lookup strategies for artifacts.
76              * 
77              * @param site          entity definition
78              * @param validUntil    expiration time of the entity definition
79              */
80             virtual void index(EntityDescriptor* site, time_t validUntil);
81
82             /**
83              * Loads a group of entities into the cache for faster lookup.
84              * 
85              * @param group         group definition
86              * @param validUntil    expiration time of the group definition
87              */
88             virtual void index(EntitiesDescriptor* group, time_t validUntil);
89         
90             /**
91              * Clear the cache of known entities and groups.
92              */
93             virtual void clearDescriptorIndex();
94         
95         private:
96             std::vector<MetadataFilter*> m_filters;
97
98             typedef std::multimap<std::string,const EntityDescriptor*> sitemap_t;
99             typedef std::multimap<std::string,const EntitiesDescriptor*> groupmap_t;
100             sitemap_t m_sites;
101             sitemap_t m_sources;
102             groupmap_t m_groups;
103         };
104         
105     };
106 };
107
108 #endif /* __saml2_absmetadataprov_h__ */