Change license header, remove stale pkg files.
[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 emitChangeEvent() const;
85             std::pair<const EntityDescriptor*,const RoleDescriptor*> getEntityDescriptor(const Criteria& criteria) const;
86             const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
87             const xmltooling::Credential* resolve(const xmltooling::CredentialCriteria* criteria=nullptr) const;
88             std::vector<const xmltooling::Credential*>::size_type resolve(
89                 std::vector<const xmltooling::Credential*>& results, const xmltooling::CredentialCriteria* criteria=nullptr
90                 ) const;
91
92         protected:
93             /** Embedded KeyInfoResolver instance. */
94             xmltooling::KeyInfoResolver* m_resolver;
95
96             /**
97              * Loads an entity into the cache for faster lookup.
98              * <p>This includes processing known reverse lookup strategies for artifacts.
99              * The validUntil parameter will contain the smallest value found on output.
100              * 
101              * @param site          entity definition
102              * @param validUntil    maximum expiration time of the entity definition
103              * @param replace       true iff existing entries for the same entity should be cleared/replaced
104              */
105             virtual void indexEntity(EntityDescriptor* site, time_t& validUntil, bool replace=false) const;
106
107             /**
108              * Loads a group of entities into the cache for faster lookup.
109              * <p>The validUntil parameter will contain the smallest value found on output.
110              * 
111              * @param group         group definition
112              * @param validUntil    maximum expiration time of the group definition
113              */
114             virtual void indexGroup(EntitiesDescriptor* group, time_t& validUntil) const;
115
116             /**
117              * @deprecated
118              * Loads an entity into the cache for faster lookup.
119              * <p>This includes processing known reverse lookup strategies for artifacts.
120              * 
121              * @param site          entity definition
122              * @param validUntil    maximum expiration time of the entity definition
123              * @param replace       true iff existing entries for the same entity should be cleared/replaced
124              */
125             virtual void index(EntityDescriptor* site, time_t validUntil, bool replace=false) const;
126
127             /**
128              * @deprecated
129              * Loads a group of entities into the cache for faster lookup.
130              * 
131              * @param group         group definition
132              * @param validUntil    maximum expiration time of the group definition
133              */
134             virtual void index(EntitiesDescriptor* group, time_t validUntil) const;
135
136             /**
137              * Clear the cache of known entities and groups.
138              *
139              * @param freeSites true iff the objects cached in the site map should be freed.
140              */
141             virtual void clearDescriptorIndex(bool freeSites=false);
142
143         private:
144             typedef std::multimap<std::string,const EntityDescriptor*> sitemap_t;
145             typedef std::multimap<std::string,const EntitiesDescriptor*> groupmap_t;
146             mutable sitemap_t m_sites;
147             mutable sitemap_t m_sources;
148             mutable groupmap_t m_groups;
149
150             mutable xmltooling::Mutex* m_credentialLock;
151             typedef std::map< const RoleDescriptor*, std::vector<xmltooling::Credential*> > credmap_t;
152             mutable credmap_t m_credentialMap;
153             const credmap_t::mapped_type& resolveCredentials(const RoleDescriptor& role) const;
154         };
155
156 #if defined (_MSC_VER)
157         #pragma warning( pop )
158         #pragma warning( disable : 4251 )
159 #endif
160         
161     };
162 };
163
164 #endif /* __saml2_absmetadataprov_h__ */