2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file saml/saml2/metadata/MetadataProvider.h
24 * Supplies an individual source of metadata.
27 #ifndef __saml2_metadataprov_h__
28 #define __saml2_metadataprov_h__
30 #include <saml/base.h>
34 #include <boost/ptr_container/ptr_vector.hpp>
35 #include <xmltooling/exceptions.h>
36 #include <xmltooling/security/CredentialResolver.h>
38 namespace xmltooling {
39 class XMLTOOL_API QName;
40 class XMLTOOL_API XMLObject;
45 class SAML_API SAMLArtifact;
49 class SAML_API EntityDescriptor;
50 class SAML_API EntitiesDescriptor;
51 class SAML_API RoleDescriptor;
52 class SAML_API MetadataCredentialResolver;
53 class SAML_API MetadataFilter;
55 #if defined (_MSC_VER)
56 #pragma warning( push )
57 #pragma warning( disable : 4251 )
61 * Supplies an individual source of metadata.
63 * The source can be a local file, remote service, or the result of a
64 * dynamic lookup, can include local caching, etc. Providers
65 * <strong>MUST</strong> be locked before any lookup operations.
67 class SAML_API MetadataProvider : public virtual xmltooling::CredentialResolver
69 MAKE_NONCOPYABLE(MetadataProvider);
74 * If a DOM is supplied, a set of default logic will be used to identify
75 * and build MetadataFilter plugins and install them into the provider.
77 * The following XML content is supported:
80 * <li><MetadataFilter> elements with a type attribute and type-specific content
81 * <li><Exclude> elements representing a BlacklistMetadataFilter
82 * <li><BlacklistMetadataFilter> element containing <Exclude> elements
83 * <li><Include> elements representing a WhitelistMetadataFilter
84 * <li><SignatureMetadataFilter> element containing a <KeyResolver> element
85 * <li><WhitelistMetadataFilter> element containing <Include> elements
88 * XML namespaces are ignored in the processing of these elements.
90 * @param e DOM to supply configuration for provider
92 MetadataProvider(const xercesc::DOMElement* e=nullptr);
96 * Destructor will delete any installed filters.
98 virtual ~MetadataProvider();
101 * Returns an identifier for the provider for logging/status purposes.
103 * @return an identifier, or null
105 virtual const char* getId() const;
108 * Adds a metadata filter to apply to any resolved metadata. Will not be applied
109 * to metadata that is already loaded.
111 * @param newFilter metadata filter to add
113 virtual void addMetadataFilter(MetadataFilter* newFilter);
116 * Removes a metadata filter. The caller must delete the filter if necessary.
118 * @param oldFilter metadata filter to remove
119 * @return the old filter
121 virtual MetadataFilter* removeMetadataFilter(MetadataFilter* oldFilter);
124 * Should be called after instantiating provider and adding filters, but before
125 * performing any lookup operations. Allows the provider to defer initialization
126 * processes that are likely to result in exceptions until after the provider is
127 * safely created. Providers SHOULD perform as much processing as possible in
128 * this method so as to report/log any errors that would affect later processing.
130 virtual void init()=0;
133 * Generate an XML representation of the provider's status. The XML must be
134 * well-formed, but is otherwise arbitrary.
136 * @param os stream to write status information to
138 virtual void outputStatus(std::ostream& os) const;
141 * Gets the entire metadata tree, after the registered filter has been applied.
142 * The caller MUST unlock the provider when finished with the data.
144 * @return the entire metadata tree
146 virtual const xmltooling::XMLObject* getMetadata() 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 nullptr if there is no metadata or no valid metadata
158 virtual const EntitiesDescriptor* getEntitiesDescriptor(const XMLCh* name, bool requireValidMetadata=true) const;
161 * Gets the metadata for a given group of entities. If a valid group is returned,
162 * the resolver will be left in a locked state. The caller MUST unlock the
163 * resolver when finished with the group.
165 * @param name the name of the group
166 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
168 * @return the group's metadata or nullptr if there is no metadata or no valid metadata
170 virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const=0;
173 * Batches up criteria for entity lookup.
175 struct SAML_API Criteria {
177 * Default constructor.
184 * @param id entityID to lookup
185 * @param q element/type of role, if any
186 * @param prot protocol support constant, if any
187 * @param valid true iff stale metadata should be ignored
189 Criteria(const XMLCh* id, const xmltooling::QName* q=nullptr, const XMLCh* prot=nullptr, bool valid=true);
194 * @param id entityID to lookup
195 * @param q element/type of role, if any
196 * @param prot protocol support constant, if any
197 * @param valid true iff stale metadata should be ignored
199 Criteria(const char* id, const xmltooling::QName* q=nullptr, const XMLCh* prot=nullptr, bool valid=true);
204 * @param a artifact to lookup
205 * @param q element/type of role, if any
206 * @param prot protocol support constant, if any
207 * @param valid true iff stale metadata should be ignored
209 Criteria(const SAMLArtifact* a, const xmltooling::QName* q=nullptr, const XMLCh* prot=nullptr, bool valid=true);
214 * Restores the object to its default state.
216 virtual void reset();
218 /** Unique ID of entity. */
219 const XMLCh* entityID_unicode;
220 /** Unique ID of entity. */
221 const char* entityID_ascii;
223 const SAMLArtifact* artifact;
224 /** Element or schema type QName of metadata role. */
225 const xmltooling::QName* role;
226 /** Protocol support constant. */
227 const XMLCh* protocol;
228 /** Backup protocol support constant. */
229 const XMLCh* protocol2;
230 /** Controls whether stale metadata is ignored. */
235 * Gets entity metadata based on supplied criteria. If a valid entity is returned,
236 * the provider will be left in a locked state. The caller MUST unlock the
237 * provider when finished with the entity.
239 * @param criteria lookup criteria
241 * @return the entity's metadata (and optionally a role) or nullptr if there is no qualifying metadata
243 virtual std::pair<const EntityDescriptor*,const RoleDescriptor*> getEntityDescriptor(const Criteria& criteria) const=0;
247 * Applies any installed filters to a metadata instance.
249 * @param xmlObject the metadata to be filtered
251 void doFilters(xmltooling::XMLObject& xmlObject) const;
254 boost::ptr_vector<MetadataFilter> m_filters;
257 #if defined (_MSC_VER)
258 #pragma warning( pop )
262 * Registers MetadataProvider classes into the runtime.
264 void SAML_API registerMetadataProviders();
266 /** MetadataProvider based on local or remote XML file */
267 #define XML_METADATA_PROVIDER "XML"
269 /** MetadataProvider based on dynamic resolution */
270 #define DYNAMIC_METADATA_PROVIDER "Dynamic"
272 /** MetadataProvider that wraps a sequence of metadata providers. */
273 #define CHAINING_METADATA_PROVIDER "Chaining"
275 /** MetadataProvider that loads a directory of files. */
276 #define FOLDER_METADATA_PROVIDER "Folder"
278 /** MetadataProvider that returns an empty "dummy" entity descriptor. */
279 #define NULL_METADATA_PROVIDER "Null"
281 DECL_XMLTOOLING_EXCEPTION(MetadataException,SAML_EXCEPTIONAPI(SAML_API),opensaml::saml2md,xmltooling::XMLToolingException,Exceptions related to metadata use);
285 #endif /* __saml2_metadataprov_h__ */