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 <xmltooling/Lockable.h>
27 #include <saml/saml2/metadata/MetadataFilter.h>
31 class SAML_API SAMLArtifact;
36 * Supplies an individual source of metadata.
38 * The source can be a local file, remote service, or the result of a
39 * dynamic lookup, can include local caching, etc. Providers
40 * <strong>MUST</strong> be locked before any lookup operations.
42 class SAML_API MetadataProvider : public virtual xmltooling::Lockable
44 MAKE_NONCOPYABLE(MetadataProvider);
48 * Constructor. If a DOM is supplied, a set of default logic will be
49 * used to identify and build MetadataFilter plugins and install them
50 * into the provider. The following XML content is supported:
53 * <li><MetadataFilter> elements with a type attribute
54 * <li><Exclude> elements representing a BlacklistMetadataFilter
55 * <li><BlacklistMetadataFilter> element containing <Exclude> elements
56 * <li><Include> elements representing a WhitelistMetadataFilter
57 * <li><WhitelistMetadataFilter> element containing <Include> elements
60 * XML namespaces are ignored in the processing of these elements.
62 * @param e DOM to supply configuration for provider
64 MetadataProvider(const DOMElement* e=NULL);
68 * Destructor will delete any installed filters.
70 virtual ~MetadataProvider();
73 * Adds a metadata filter to apply to any resolved metadata. Will not be applied
74 * to metadata that is already loaded.
76 * @param newFilter metadata filter to add
78 virtual void addMetadataFilter(MetadataFilter* newFilter) {
79 m_filters.push_back(newFilter);
83 * Removes a metadata filter. The caller must delete the filter if necessary.
85 * @param oldFilter metadata filter to remove
86 * @return the old filter
88 virtual MetadataFilter* removeMetadataFilter(MetadataFilter* oldFilter) {
89 for (std::vector<MetadataFilter*>::iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
90 if (oldFilter==(*i)) {
99 * Should be called after instantiating provider and adding filters, but before
100 * performing any lookup operations. Allows the provider to defer initialization
101 * processes that are likely to result in exceptions until after the provider is
102 * safely created. Providers SHOULD perform as much processing as possible in
103 * this method so as to report/log any errors that would affect later processing.
105 virtual void init()=0;
108 * Gets the entire metadata tree, after the registered filter has been applied.
109 * The caller MUST unlock the provider when finished with the data.
111 * @return the entire metadata tree
113 virtual const xmltooling::XMLObject* getMetadata() const=0;
116 * Gets the metadata for a given entity. If a valid entity is returned,
117 * the provider will be left in a locked state. The caller MUST unlock the
118 * provider when finished with the entity.
120 * @param id the ID of the entity
121 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
123 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
125 virtual const EntityDescriptor* getEntityDescriptor(const XMLCh* id, bool requireValidMetadata=true) const;
128 * Gets the metadata for a given entity. If a valid entity is returned,
129 * the provider will be left in a locked state. The caller MUST unlock the
130 * provider when finished with the entity.
132 * @param id the ID of the entity
133 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
135 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
137 virtual const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const;
140 * Gets the metadata for an entity that issued a SAML artifact. If a valid entity is returned,
141 * the provider will be left in a locked state. The caller MUST unlock the
142 * provider when finished with the entity.
144 * @param artifact a SAML artifact to find the issuer of
146 * @return the entity's metadata or NULL if there is no valid metadata
148 virtual const EntityDescriptor* getEntityDescriptor(const SAMLArtifact* artifact) const;
151 * Gets the metadata for a given group of entities. If a valid group is returned,
152 * the resolver will be left in a locked state. The caller MUST unlock the
153 * resolver when finished with the group.
155 * @param name the name of the group
156 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
158 * @return the group's metadata or NULL if there is no metadata or no valid metadata
160 virtual const EntitiesDescriptor* getEntitiesDescriptor(const XMLCh* name, bool requireValidMetadata=true) const;
163 * Gets the metadata for a given group of entities. If a valid group is returned,
164 * the resolver will be left in a locked state. The caller MUST unlock the
165 * resolver when finished with the group.
167 * @param name the name of the group
168 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
170 * @return the group's metadata or NULL if there is no metadata or no valid metadata
172 virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
176 * Applies any installed filters to a metadata instance.
178 * @param xmlObject the metadata to be filtered
180 void doFilters(xmltooling::XMLObject& xmlObject) const;
183 * Loads an entity into the cache for faster lookup. This includes
184 * processing known reverse lookup strategies for artifacts.
186 * @param site entity definition
187 * @param validUntil expiration time of the entity definition
189 virtual void index(EntityDescriptor* site, time_t validUntil);
192 * Loads a group of entities into the cache for faster lookup.
194 * @param group group definition
195 * @param validUntil expiration time of the group definition
197 virtual void index(EntitiesDescriptor* group, time_t validUntil);
200 * Clear the cache of known entities and groups.
202 virtual void clearIndex();
205 std::vector<MetadataFilter*> m_filters;
207 typedef std::multimap<std::string,const EntityDescriptor*> sitemap_t;
208 typedef std::multimap<std::string,const EntitiesDescriptor*> groupmap_t;
215 * Registers MetadataProvider classes into the runtime.
217 void SAML_API registerMetadataProviders();
219 /** MetadataProvider based on local XML files */
220 #define FILESYSTEM_METADATA_PROVIDER "org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"
224 #endif /* __saml2_metadataprov_h__ */