6a757ce8fd3e7620d93bb856ff7f3b3c38ab0101
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / AbstractMetadataProvider.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/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 xmltooling {
29     class XMLTOOL_API Credential;
30     class XMLTOOL_API CredentialCriteria;
31     class XMLTOOL_API KeyInfoResolver;
32     class XMLTOOL_API Mutex;
33 };
34
35 namespace opensaml {
36     namespace saml2md {
37         
38         class SAML_API MetadataFilter;
39
40 #if defined (_MSC_VER)
41         #pragma warning( push )
42         #pragma warning( disable : 4251 )
43 #endif
44
45         /**
46          * Base class for caching metadata providers.
47          */
48         class SAML_API AbstractMetadataProvider : public ObservableMetadataProvider
49         {
50         protected:
51             /**
52              * Constructor.
53              * 
54              * If a DOM is supplied, a set of default logic will be used to identify
55              * and build a KeyInfoResolver plugin and install it into the provider.
56              * 
57              * The following XML content is supported:
58              * 
59              * <ul>
60              *  <li>&lt;KeyInfoResolver&gt; elements with a type attribute
61              * </ul>
62              * 
63              * XML namespaces are ignored in the processing of these elements.
64              * 
65              * @param e DOM to supply configuration for provider
66              */
67             AbstractMetadataProvider(const xercesc::DOMElement* e=NULL);
68             
69         public:
70             virtual ~AbstractMetadataProvider();
71             
72             using MetadataProvider::getEntityDescriptor;
73             using MetadataProvider::getEntitiesDescriptor;
74
75             void emitChangeEvent() const;
76             std::pair<const EntityDescriptor*,const RoleDescriptor*> getEntityDescriptor(const Criteria& criteria) const;
77             const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
78             const xmltooling::Credential* resolve(const xmltooling::CredentialCriteria* criteria=NULL) const;
79             std::vector<const xmltooling::Credential*>::size_type resolve(
80                 std::vector<const xmltooling::Credential*>& results, const xmltooling::CredentialCriteria* criteria=NULL
81                 ) const;
82
83         protected:
84             /** Embedded KeyInfoResolver instance. */
85             xmltooling::KeyInfoResolver* m_resolver;
86
87             /**
88              * Loads an entity into the cache for faster lookup. This includes
89              * processing known reverse lookup strategies for artifacts.
90              * 
91              * @param site          entity definition
92              * @param validUntil    maximum expiration time of the entity definition
93              * @param replace       true iff existing entries for the same entity should be cleared/replaced
94              */
95             virtual void index(EntityDescriptor* site, time_t validUntil, bool replace=false) const;
96
97             /**
98              * Loads a group of entities into the cache for faster lookup.
99              * 
100              * @param group         group definition
101              * @param validUntil    maximum expiration time of the group definition
102              */
103             virtual void index(EntitiesDescriptor* group, time_t validUntil) const;
104         
105             /**
106              * Clear the cache of known entities and groups.
107              *
108              * @param freeSites true iff the objects cached in the site map should be freed.
109              */
110             virtual void clearDescriptorIndex(bool freeSites=false);
111
112         private:
113             typedef std::multimap<std::string,const EntityDescriptor*> sitemap_t;
114             typedef std::multimap<std::string,const EntitiesDescriptor*> groupmap_t;
115             mutable sitemap_t m_sites;
116             mutable sitemap_t m_sources;
117             mutable groupmap_t m_groups;
118
119             mutable xmltooling::Mutex* m_credentialLock;
120             typedef std::map< const RoleDescriptor*, std::vector<xmltooling::Credential*> > credmap_t;
121             mutable credmap_t m_credentialMap;
122             const credmap_t::mapped_type& resolveCredentials(const RoleDescriptor& role) const;
123         };
124
125 #if defined (_MSC_VER)
126         #pragma warning( pop )
127         #pragma warning( disable : 4251 )
128 #endif
129         
130     };
131 };
132
133 #endif /* __saml2_absmetadataprov_h__ */