2 * Copyright 2001-2007 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/XMLObject.h>
27 #include <xmltooling/security/CredentialResolver.h>
31 class SAML_API SAMLArtifact;
35 class SAML_API EntityDescriptor;
36 class SAML_API EntitiesDescriptor;
37 class SAML_API RoleDescriptor;
38 class SAML_API MetadataCredentialResolver;
39 class SAML_API MetadataFilter;
41 #if defined (_MSC_VER)
42 #pragma warning( push )
43 #pragma warning( disable : 4251 )
47 * Supplies an individual source of metadata.
49 * The source can be a local file, remote service, or the result of a
50 * dynamic lookup, can include local caching, etc. Providers
51 * <strong>MUST</strong> be locked before any lookup operations.
53 class SAML_API MetadataProvider : public virtual xmltooling::CredentialResolver
55 MAKE_NONCOPYABLE(MetadataProvider);
60 * If a DOM is supplied, a set of default logic will be used to identify
61 * and build MetadataFilter plugins and install them into the provider.
63 * The following XML content is supported:
66 * <li><MetadataFilter> elements with a type attribute and type-specific content
67 * <li><Exclude> elements representing a BlacklistMetadataFilter
68 * <li><BlacklistMetadataFilter> element containing <Exclude> elements
69 * <li><Include> elements representing a WhitelistMetadataFilter
70 * <li><SignatureMetadataFilter> element containing a <KeyResolver> element
71 * <li><WhitelistMetadataFilter> element containing <Include> elements
74 * XML namespaces are ignored in the processing of these elements.
76 * @param e DOM to supply configuration for provider
78 MetadataProvider(const DOMElement* e=NULL);
82 * Destructor will delete any installed filters.
84 virtual ~MetadataProvider();
87 * Adds a metadata filter to apply to any resolved metadata. Will not be applied
88 * to metadata that is already loaded.
90 * @param newFilter metadata filter to add
92 virtual void addMetadataFilter(MetadataFilter* newFilter) {
93 m_filters.push_back(newFilter);
97 * Removes a metadata filter. The caller must delete the filter if necessary.
99 * @param oldFilter metadata filter to remove
100 * @return the old filter
102 virtual MetadataFilter* removeMetadataFilter(MetadataFilter* oldFilter) {
103 for (std::vector<MetadataFilter*>::iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
104 if (oldFilter==(*i)) {
113 * Should be called after instantiating provider and adding filters, but before
114 * performing any lookup operations. Allows the provider to defer initialization
115 * processes that are likely to result in exceptions until after the provider is
116 * safely created. Providers SHOULD perform as much processing as possible in
117 * this method so as to report/log any errors that would affect later processing.
119 virtual void init()=0;
122 * Gets the entire metadata tree, after the registered filter has been applied.
123 * The caller MUST unlock the provider when finished with the data.
125 * @return the entire metadata tree
127 virtual const xmltooling::XMLObject* getMetadata() const=0;
130 * Gets the metadata for a given entity. If a valid entity is returned,
131 * the provider will be left in a locked state. The caller MUST unlock the
132 * provider when finished with the entity.
134 * @param id the ID of the entity
135 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
137 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
139 virtual const EntityDescriptor* getEntityDescriptor(const XMLCh* id, bool requireValidMetadata=true) const;
142 * Gets the metadata for a given entity. If a valid entity is returned,
143 * the provider will be left in a locked state. The caller MUST unlock the
144 * provider when finished with the entity.
146 * @param id the ID of the entity
147 * @param requireValidMetadata indicates whether the metadata for the entity must be valid/current
149 * @return the entity's metadata or NULL if there is no metadata or no valid metadata
151 virtual const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const=0;
154 * Gets the metadata for an entity that issued a SAML artifact. If a valid entity is returned,
155 * the provider will be left in a locked state. The caller MUST unlock the
156 * provider when finished with the entity.
158 * @param artifact a SAML artifact to find the issuer of
160 * @return the entity's metadata or NULL if there is no valid metadata
162 virtual const EntityDescriptor* getEntityDescriptor(const SAMLArtifact* artifact) const=0;
165 * Gets the metadata for a given group of entities. If a valid group is returned,
166 * the resolver will be left in a locked state. The caller MUST unlock the
167 * resolver when finished with the group.
169 * @param name the name of the group
170 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
172 * @return the group's metadata or NULL if there is no metadata or no valid metadata
174 virtual const EntitiesDescriptor* getEntitiesDescriptor(const XMLCh* name, bool requireValidMetadata=true) const;
177 * Gets the metadata for a given group of entities. If a valid group is returned,
178 * the resolver will be left in a locked state. The caller MUST unlock the
179 * resolver when finished with the group.
181 * @param name the name of the group
182 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
184 * @return the group's metadata or NULL if there is no metadata or no valid metadata
186 virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const=0;
190 * Applies any installed filters to a metadata instance.
192 * @param xmlObject the metadata to be filtered
194 void doFilters(xmltooling::XMLObject& xmlObject) const;
197 std::vector<MetadataFilter*> m_filters;
200 #if defined (_MSC_VER)
201 #pragma warning( pop )
205 * Registers MetadataProvider classes into the runtime.
207 void SAML_API registerMetadataProviders();
209 /** MetadataProvider based on local or remote XML file */
210 #define XML_METADATA_PROVIDER "XML"
212 /** MetadataProvider that wraps a sequence of metadata providers. */
213 #define CHAINING_METADATA_PROVIDER "Chaining"
215 DECL_XMLTOOLING_EXCEPTION(MetadataException,SAML_EXCEPTIONAPI(SAML_API),opensaml::saml2md,xmltooling::XMLToolingException,Exceptions related to metadata use);
219 #endif /* __saml2_metadataprov_h__ */