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;
37 class SAML_API EntityDescriptor;
38 class SAML_API EntitiesDescriptor;
41 * Supplies an individual source of metadata.
43 * The source can be a local file, remote service, or the result of a
44 * dynamic lookup, can include local caching, etc. Providers
45 * <strong>MUST</strong> be locked before any lookup operations.
47 class SAML_API MetadataProvider : public virtual xmltooling::Lockable
49 MAKE_NONCOPYABLE(MetadataProvider);
55 * If a DOM is supplied, a set of default logic will be used to identify
56 * and build MetadataFilter plugins and install them into the provider.
58 * The following XML content is supported:
61 * <li><MetadataFilter> elements with a type attribute and type-specific content
62 * <li><Exclude> elements representing a BlacklistMetadataFilter
63 * <li><BlacklistMetadataFilter> element containing <Exclude> elements
64 * <li><Include> elements representing a WhitelistMetadataFilter
65 * <li><SignatureMetadataFilter> element containing a <KeyResolver> element
66 * <li><WhitelistMetadataFilter> element containing <Include> elements
69 * XML namespaces are ignored in the processing of these elements.
71 * @param e DOM to supply configuration for provider
73 MetadataProvider(const DOMElement* e=NULL);
77 * Destructor will delete any installed filters.
79 virtual ~MetadataProvider();
82 * Adds a metadata filter to apply to any resolved metadata. Will not be applied
83 * to metadata that is already loaded.
85 * @param newFilter metadata filter to add
87 virtual void addMetadataFilter(MetadataFilter* newFilter) {
88 m_filters.push_back(newFilter);
92 * Removes a metadata filter. The caller must delete the filter if necessary.
94 * @param oldFilter metadata filter to remove
95 * @return the old filter
97 virtual MetadataFilter* removeMetadataFilter(MetadataFilter* oldFilter) {
98 for (std::vector<MetadataFilter*>::iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
99 if (oldFilter==(*i)) {
108 * Should be called after instantiating provider and adding filters, but before
109 * performing any lookup operations. Allows the provider to defer initialization
110 * processes that are likely to result in exceptions until after the provider is
111 * safely created. Providers SHOULD perform as much processing as possible in
112 * this method so as to report/log any errors that would affect later processing.
114 virtual void init()=0;
117 * Returns a KeyResolver associated with this metadata provider, if any.
119 * @return an associated KeyResolver, or NULL
121 virtual const xmlsignature::KeyResolver* getKeyResolver() const=0;
124 * Gets the entire metadata tree, after the registered filter has been applied.
125 * The caller MUST unlock the provider when finished with the data.
127 * @return the entire metadata tree
129 virtual const xmltooling::XMLObject* getMetadata() const=0;
132 * Gets the metadata for a given entity. If a valid entity is returned,
133 * the provider will be left in a locked state. The caller MUST unlock the
134 * provider when finished with the entity.
136 * @param id the ID of the entity
137 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
139 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
141 virtual const EntityDescriptor* getEntityDescriptor(const XMLCh* id, bool requireValidMetadata=true) const;
144 * Gets the metadata for a given entity. If a valid entity is returned,
145 * the provider will be left in a locked state. The caller MUST unlock the
146 * provider when finished with the entity.
148 * @param id the ID of the entity
149 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
151 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
153 virtual const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const=0;
156 * Gets the metadata for an entity that issued a SAML artifact. If a valid entity is returned,
157 * the provider will be left in a locked state. The caller MUST unlock the
158 * provider when finished with the entity.
160 * @param artifact a SAML artifact to find the issuer of
162 * @return the entity's metadata or NULL if there is no valid metadata
164 virtual const EntityDescriptor* getEntityDescriptor(const SAMLArtifact* artifact) const=0;
167 * Gets the metadata for a given group of entities. If a valid group is returned,
168 * the resolver will be left in a locked state. The caller MUST unlock the
169 * resolver when finished with the group.
171 * @param name the name of the group
172 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
174 * @return the group's metadata or NULL if there is no metadata or no valid metadata
176 virtual const EntitiesDescriptor* getEntitiesDescriptor(const XMLCh* name, bool requireValidMetadata=true) const;
179 * Gets the metadata for a given group of entities. If a valid group is returned,
180 * the resolver will be left in a locked state. The caller MUST unlock the
181 * resolver when finished with the group.
183 * @param name the name of the group
184 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
186 * @return the group's metadata or NULL if there is no metadata or no valid metadata
188 virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const=0;
192 * Applies any installed filters to a metadata instance.
194 * @param xmlObject the metadata to be filtered
196 void doFilters(xmltooling::XMLObject& xmlObject) const;
199 std::vector<MetadataFilter*> m_filters;
203 * Registers MetadataProvider classes into the runtime.
205 void SAML_API registerMetadataProviders();
207 /** MetadataProvider based on local XML files */
208 #define FILESYSTEM_METADATA_PROVIDER "org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"
210 /** MetadataProvider that wraps a sequence of metadata providers. */
211 #define CHAINING_METADATA_PROVIDER "org.opensaml.saml2.metadata.provider.ChainingMetadataProvider"
215 #endif /* __saml2_metadataprov_h__ */