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>
34 * Supplies an individual source of metadata.
36 * The source can be a local file, remote service, or the result of a
37 * dynamic lookup, can include local caching, etc.
39 class SAML_API MetadataProvider : public virtual xmltooling::Lockable
41 MAKE_NONCOPYABLE(MetadataProvider);
45 * Constructor. If a DOM is supplied, a set of default logic will be
46 * used to identify and build MetadataFilter plugins and install them
47 * into the provider. The following XML content is supported:
50 * <li><MetadataFilter> elements with a type attribute
51 * <li><Exclude> elements representing a BlacklistMetadataFilter
52 * <li><BlacklistMetadataFilter> element containing <Exclude> elements
53 * <li><Include> elements representing a WhitelistMetadataFilter
54 * <li><WhitelistMetadataFilter> element containing <Include> elements
57 * XML namespaces are ignored in the processing of these elements.
59 * @param e DOM to supply configuration for provider
61 MetadataProvider(const DOMElement* e=NULL);
65 * Destructor will delete any installed filters.
67 virtual ~MetadataProvider();
70 * Adds a metadata filter to apply to any resolved metadata. Will not be applied
71 * to metadata that is already loaded.
73 * @param newFilter metadata filter to add
75 virtual void addMetadataFilter(MetadataFilter* newFilter) {
76 m_filters.push_back(newFilter);
80 * Removes a metadata filter. The caller must delete the filter if necessary.
82 * @param oldFilter metadata filter to remove
83 * @return the old filter
85 virtual MetadataFilter* removeMetadataFilter(MetadataFilter* oldFilter) {
86 for (std::vector<MetadataFilter*>::iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
87 if (oldFilter==(*i)) {
96 * Should be called after instantiating provider and adding filters, but before
97 * performing any lookup operations. Allows the provider to defer initialization
98 * processes that are likely to result in exceptions until after the provider is
99 * safely created. Providers SHOULD perform as much processing as possible in
100 * this method so as to report/log any errors that would affect later processing.
102 virtual void init()=0;
105 * Gets the entire metadata tree, after the registered filter has been applied.
106 * The caller MUST unlock the provider when finished with the data.
108 * @return the entire metadata tree
110 virtual const xmltooling::XMLObject* getMetadata() const=0;
113 * Gets the metadata for a given entity. If a valid entity is returned,
114 * the provider will be left in a locked state. The caller MUST unlock the
115 * provider when finished with the entity.
117 * @param id the ID of the entity
118 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
120 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
122 virtual const EntityDescriptor* getEntityDescriptor(const XMLCh* id, bool requireValidMetadata=true) const=0;
125 * Gets the metadata for a given entity. If a valid entity is returned,
126 * the provider will be left in a locked state. The caller MUST unlock the
127 * provider when finished with the entity.
129 * @param id the ID of the entity
130 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
132 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
134 virtual const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const=0;
137 * Gets the metadata for a given group of entities. If a valid group is returned,
138 * the resolver will be left in a locked state. The caller MUST unlock the
139 * resolver when finished with the group.
141 * @param name the name of the group
142 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
144 * @return the group's metadata or NULL if there is no metadata or no valid metadata
146 virtual const EntitiesDescriptor* getEntitiesDescriptor(const XMLCh* name, bool requireValidMetadata=true) const=0;
149 * Gets the metadata for a given group of entities. If a valid group is returned,
150 * the resolver will be left in a locked state. The caller MUST unlock the
151 * resolver when finished with the group.
153 * @param name the name of the group
154 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
156 * @return the group's metadata or NULL if there is no metadata or no valid metadata
158 virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const=0;
162 * Applies any installed filters to a metadata instance.
164 * @param xmlObject the metadata to be filtered
166 void doFilters(xmltooling::XMLObject& xmlObject) const;
169 std::vector<MetadataFilter*> m_filters;
173 * Registers MetadataProvider classes into the runtime.
175 void SAML_API registerMetadataProviders();
177 /** MetadataProvider based on local XML files */
178 #define FILESYSTEM_METADATA_PROVIDER "org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"
182 #endif /* __saml2_metadataprov_h__ */