2 * Copyright 2001-2006 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file saml/saml2/metadata/MetadataProvider.h
20 * Supplies an individual source of metadata.
23 #ifndef __saml2_metadataprov_h__
24 #define __saml2_metadataprov_h__
26 #include <saml/saml2/metadata/MetadataFilter.h>
28 #include <xmltooling/Lockable.h>
29 #include <xmltooling/signature/KeyResolver.h>
33 class SAML_API SAMLArtifact;
38 * Supplies an individual source of metadata.
40 * The source can be a local file, remote service, or the result of a
41 * dynamic lookup, can include local caching, etc. Providers
42 * <strong>MUST</strong> be locked before any lookup operations.
44 class SAML_API MetadataProvider : public virtual xmltooling::Lockable
46 MAKE_NONCOPYABLE(MetadataProvider);
52 * If a DOM is supplied, a set of default logic will be used to identify
53 * and build MetadataFilter plugins and install them into the provider.
54 * A KeyResolver can also be supplied, or a default resolver will be used.
56 * The following XML content is supported:
59 * <li><KeyResolver> elements with a type attribute
60 * <li><MetadataFilter> elements with a type attribute and type-specific content
61 * <li><Exclude> elements representing a BlacklistMetadataFilter
62 * <li><BlacklistMetadataFilter> element containing <Exclude> elements
63 * <li><Include> elements representing a WhitelistMetadataFilter
64 * <li><SignatureMetadataFilter> element containing a <KeyResolver> element
65 * <li><WhitelistMetadataFilter> element containing <Include> elements
68 * XML namespaces are ignored in the processing of these elements.
70 * @param e DOM to supply configuration for provider
72 MetadataProvider(const DOMElement* e=NULL);
76 * Destructor will delete any installed filters.
78 virtual ~MetadataProvider();
81 * Adds a metadata filter to apply to any resolved metadata. Will not be applied
82 * to metadata that is already loaded.
84 * @param newFilter metadata filter to add
86 virtual void addMetadataFilter(MetadataFilter* newFilter) {
87 m_filters.push_back(newFilter);
91 * Removes a metadata filter. The caller must delete the filter if necessary.
93 * @param oldFilter metadata filter to remove
94 * @return the old filter
96 virtual MetadataFilter* removeMetadataFilter(MetadataFilter* oldFilter) {
97 for (std::vector<MetadataFilter*>::iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
98 if (oldFilter==(*i)) {
107 * Should be called after instantiating provider and adding filters, but before
108 * performing any lookup operations. Allows the provider to defer initialization
109 * processes that are likely to result in exceptions until after the provider is
110 * safely created. Providers SHOULD perform as much processing as possible in
111 * this method so as to report/log any errors that would affect later processing.
113 virtual void init()=0;
116 * Returns a KeyResolver associated with this metadata provider, if any.
118 * @return an associated KeyResolver, or NULL
120 virtual const xmlsignature::KeyResolver* getKeyResolver() const {
125 * Gets the entire metadata tree, after the registered filter has been applied.
126 * The caller MUST unlock the provider when finished with the data.
128 * @return the entire metadata tree
130 virtual const xmltooling::XMLObject* getMetadata() const=0;
133 * Gets the metadata for a given entity. If a valid entity is returned,
134 * the provider will be left in a locked state. The caller MUST unlock the
135 * provider when finished with the entity.
137 * @param id the ID of the entity
138 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
140 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
142 virtual const EntityDescriptor* getEntityDescriptor(const XMLCh* id, bool requireValidMetadata=true) const;
145 * Gets the metadata for a given entity. If a valid entity is returned,
146 * the provider will be left in a locked state. The caller MUST unlock the
147 * provider when finished with the entity.
149 * @param id the ID of the entity
150 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
152 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
154 virtual const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const;
157 * Gets the metadata for an entity that issued a SAML artifact. If a valid entity is returned,
158 * the provider will be left in a locked state. The caller MUST unlock the
159 * provider when finished with the entity.
161 * @param artifact a SAML artifact to find the issuer of
163 * @return the entity's metadata or NULL if there is no valid metadata
165 virtual const EntityDescriptor* getEntityDescriptor(const SAMLArtifact* artifact) const;
168 * Gets the metadata for a given group of entities. If a valid group is returned,
169 * the resolver will be left in a locked state. The caller MUST unlock the
170 * resolver when finished with the group.
172 * @param name the name of the group
173 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
175 * @return the group's metadata or NULL if there is no metadata or no valid metadata
177 virtual const EntitiesDescriptor* getEntitiesDescriptor(const XMLCh* name, bool requireValidMetadata=true) const;
180 * Gets the metadata for a given group of entities. If a valid group is returned,
181 * the resolver will be left in a locked state. The caller MUST unlock the
182 * resolver when finished with the group.
184 * @param name the name of the group
185 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
187 * @return the group's metadata or NULL if there is no metadata or no valid metadata
189 virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
192 /** Embedded KeyResolver instance. */
193 xmlsignature::KeyResolver* m_resolver;
196 * Applies any installed filters to a metadata instance.
198 * @param xmlObject the metadata to be filtered
200 void doFilters(xmltooling::XMLObject& xmlObject) const;
203 * Loads an entity into the cache for faster lookup. This includes
204 * processing known reverse lookup strategies for artifacts.
206 * @param site entity definition
207 * @param validUntil expiration time of the entity definition
209 virtual void index(EntityDescriptor* site, time_t validUntil);
212 * Loads a group of entities into the cache for faster lookup.
214 * @param group group definition
215 * @param validUntil expiration time of the group definition
217 virtual void index(EntitiesDescriptor* group, time_t validUntil);
220 * Clear the cache of known entities and groups.
222 virtual void clearDescriptorIndex();
225 std::vector<MetadataFilter*> m_filters;
227 typedef std::multimap<std::string,const EntityDescriptor*> sitemap_t;
228 typedef std::multimap<std::string,const EntitiesDescriptor*> groupmap_t;
235 * Registers MetadataProvider classes into the runtime.
237 void SAML_API registerMetadataProviders();
239 /** MetadataProvider based on local XML files */
240 #define FILESYSTEM_METADATA_PROVIDER "org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"
244 #endif /* __saml2_metadataprov_h__ */