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