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.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @file saml/saml2/metadata/AbstractMetadataProvider.h
24 * Base class for caching metadata providers.
27 #ifndef __saml2_absmetadataprov_h__
28 #define __saml2_absmetadataprov_h__
30 #include <saml/saml2/metadata/ObservableMetadataProvider.h>
37 namespace xmltooling {
38 class XMLTOOL_API Credential;
39 class XMLTOOL_API CredentialCriteria;
40 class XMLTOOL_API KeyInfoResolver;
41 class XMLTOOL_API Mutex;
47 class SAML_API MetadataFilter;
49 #if defined (_MSC_VER)
50 #pragma warning( push )
51 #pragma warning( disable : 4251 )
55 * Base class for caching metadata providers.
57 class SAML_API AbstractMetadataProvider : public ObservableMetadataProvider
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.
66 * The following XML content is supported:
69 * <li><KeyInfoResolver> elements with a type attribute
72 * XML namespaces are ignored in the processing of these elements.
74 * @param e DOM to supply configuration for provider
76 AbstractMetadataProvider(const xercesc::DOMElement* e=nullptr);
79 virtual ~AbstractMetadataProvider();
81 using MetadataProvider::getEntityDescriptor;
82 using MetadataProvider::getEntitiesDescriptor;
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
94 /** Time of last update for reporting. */
95 mutable time_t m_lastUpdate;
97 /** Embedded KeyInfoResolver instance. */
98 xmltooling::KeyInfoResolver* m_resolver;
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.
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
109 virtual void indexEntity(EntityDescriptor* site, time_t& validUntil, bool replace=false) const;
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.
115 * @param group group definition
116 * @param validUntil maximum expiration time of the group definition
118 virtual void indexGroup(EntitiesDescriptor* group, time_t& validUntil) const;
122 * Loads an entity into the cache for faster lookup.
123 * <p>This includes processing known reverse lookup strategies for artifacts.
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
129 virtual void index(EntityDescriptor* site, time_t validUntil, bool replace=false) const;
133 * Loads a group of entities into the cache for faster lookup.
135 * @param group group definition
136 * @param validUntil maximum expiration time of the group definition
138 virtual void index(EntitiesDescriptor* group, time_t validUntil) const;
141 * Clear the cache of known entities and groups.
143 * @param freeSites true iff the objects cached in the site map should be freed.
145 virtual void clearDescriptorIndex(bool freeSites=false);
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;
154 mutable xmltooling::Mutex* m_credentialLock;
155 typedef std::map< const RoleDescriptor*, std::vector<xmltooling::Credential*> > credmap_t;
156 mutable credmap_t m_credentialMap;
157 const credmap_t::mapped_type& resolveCredentials(const RoleDescriptor& role) const;
160 #if defined (_MSC_VER)
161 #pragma warning( pop )
162 #pragma warning( disable : 4251 )
168 #endif /* __saml2_absmetadataprov_h__ */