Boost changes
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / AbstractMetadataProvider.h
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * @file saml/saml2/metadata/AbstractMetadataProvider.h
23  * 
24  * Base class for caching metadata providers.
25  */
26
27 #ifndef __saml2_absmetadataprov_h__
28 #define __saml2_absmetadataprov_h__
29
30 #include <saml/saml2/metadata/ObservableMetadataProvider.h>
31
32 #include <ctime>
33 #include <map>
34 #include <vector>
35 #include <string>
36
37 namespace xmltooling {
38     class XMLTOOL_API Credential;
39     class XMLTOOL_API CredentialCriteria;
40     class XMLTOOL_API KeyInfoResolver;
41     class XMLTOOL_API Mutex;
42 };
43
44 namespace opensaml {
45     namespace saml2md {
46         
47         class SAML_API MetadataFilter;
48
49 #if defined (_MSC_VER)
50         #pragma warning( push )
51         #pragma warning( disable : 4251 )
52 #endif
53
54         /**
55          * Base class for caching metadata providers.
56          */
57         class SAML_API AbstractMetadataProvider : public ObservableMetadataProvider
58         {
59         protected:
60             /**
61              * Constructor.
62              * 
63              * If a DOM is supplied, a set of default logic will be used to identify
64              * and build a KeyInfoResolver plugin and install it into the provider.
65              * 
66              * The following XML content is supported:
67              * 
68              * <ul>
69              *  <li>&lt;KeyInfoResolver&gt; elements with a type attribute
70              * </ul>
71              * 
72              * XML namespaces are ignored in the processing of these elements.
73              * 
74              * @param e DOM to supply configuration for provider
75              */
76             AbstractMetadataProvider(const xercesc::DOMElement* e=nullptr);
77             
78         public:
79             virtual ~AbstractMetadataProvider();
80             
81             using MetadataProvider::getEntityDescriptor;
82             using MetadataProvider::getEntitiesDescriptor;
83
84             void outputStatus(std::ostream& os) const;
85             void emitChangeEvent() const;
86             std::pair<const EntityDescriptor*,const RoleDescriptor*> getEntityDescriptor(const Criteria& criteria) const;
87             const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
88             const xmltooling::Credential* resolve(const xmltooling::CredentialCriteria* criteria=nullptr) const;
89             std::vector<const xmltooling::Credential*>::size_type resolve(
90                 std::vector<const xmltooling::Credential*>& results, const xmltooling::CredentialCriteria* criteria=nullptr
91                 ) const;
92
93         protected:
94             /** Time of last update for reporting. */
95             mutable time_t m_lastUpdate;
96
97             /** Embedded KeyInfoResolver instance. */
98             xmltooling::KeyInfoResolver* m_resolver;
99
100             /**
101              * Loads an entity into the cache for faster lookup.
102              * <p>This includes processing known reverse lookup strategies for artifacts.
103              * The validUntil parameter will contain the smallest value found on output.
104              * 
105              * @param site          entity definition
106              * @param validUntil    maximum expiration time of the entity definition
107              * @param replace       true iff existing entries for the same entity should be cleared/replaced
108              */
109             virtual void indexEntity(EntityDescriptor* site, time_t& validUntil, bool replace=false) const;
110
111             /**
112              * Loads a group of entities into the cache for faster lookup.
113              * <p>The validUntil parameter will contain the smallest value found on output.
114              * 
115              * @param group         group definition
116              * @param validUntil    maximum expiration time of the group definition
117              */
118             virtual void indexGroup(EntitiesDescriptor* group, time_t& validUntil) const;
119
120             /**
121              * @deprecated
122              * Loads an entity into the cache for faster lookup.
123              * <p>This includes processing known reverse lookup strategies for artifacts.
124              * 
125              * @param site          entity definition
126              * @param validUntil    maximum expiration time of the entity definition
127              * @param replace       true iff existing entries for the same entity should be cleared/replaced
128              */
129             virtual void index(EntityDescriptor* site, time_t validUntil, bool replace=false) const;
130
131             /**
132              * @deprecated
133              * Loads a group of entities into the cache for faster lookup.
134              * 
135              * @param group         group definition
136              * @param validUntil    maximum expiration time of the group definition
137              */
138             virtual void index(EntitiesDescriptor* group, time_t validUntil) const;
139
140             /**
141              * Clear the cache of known entities and groups.
142              *
143              * @param freeSites true iff the objects cached in the site map should be freed.
144              */
145             virtual void clearDescriptorIndex(bool freeSites=false);
146
147         private:
148             typedef std::multimap<std::string,const EntityDescriptor*> sitemap_t;
149             typedef std::multimap<std::string,const EntitiesDescriptor*> groupmap_t;
150             mutable sitemap_t m_sites;
151             mutable sitemap_t m_sources;
152             mutable groupmap_t m_groups;
153
154             std::auto_ptr<xmltooling::KeyInfoResolver> m_resolverWrapper;
155             std::auto_ptr<xmltooling::Mutex> m_credentialLock;
156             typedef std::map< const RoleDescriptor*, std::vector<xmltooling::Credential*> > credmap_t;
157             mutable credmap_t m_credentialMap;
158             const credmap_t::mapped_type& resolveCredentials(const RoleDescriptor& role) const;
159         };
160
161 #if defined (_MSC_VER)
162         #pragma warning( pop )
163         #pragma warning( disable : 4251 )
164 #endif
165         
166     };
167 };
168
169 #endif /* __saml2_absmetadataprov_h__ */