2 * Copyright 2001-2010 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/base.h>
29 #include <xmltooling/exceptions.h>
30 #include <xmltooling/security/CredentialResolver.h>
32 namespace xmltooling {
33 class XMLTOOL_API QName;
34 class XMLTOOL_API XMLObject;
39 class SAML_API SAMLArtifact;
43 class SAML_API EntityDescriptor;
44 class SAML_API EntitiesDescriptor;
45 class SAML_API RoleDescriptor;
46 class SAML_API MetadataCredentialResolver;
47 class SAML_API MetadataFilter;
49 #if defined (_MSC_VER)
50 #pragma warning( push )
51 #pragma warning( disable : 4251 )
55 * Supplies an individual source of metadata.
57 * The source can be a local file, remote service, or the result of a
58 * dynamic lookup, can include local caching, etc. Providers
59 * <strong>MUST</strong> be locked before any lookup operations.
61 class SAML_API MetadataProvider : public virtual xmltooling::CredentialResolver
63 MAKE_NONCOPYABLE(MetadataProvider);
68 * If a DOM is supplied, a set of default logic will be used to identify
69 * and build MetadataFilter plugins and install them into the provider.
71 * The following XML content is supported:
74 * <li><MetadataFilter> elements with a type attribute and type-specific content
75 * <li><Exclude> elements representing a BlacklistMetadataFilter
76 * <li><BlacklistMetadataFilter> element containing <Exclude> elements
77 * <li><Include> elements representing a WhitelistMetadataFilter
78 * <li><SignatureMetadataFilter> element containing a <KeyResolver> element
79 * <li><WhitelistMetadataFilter> element containing <Include> elements
82 * XML namespaces are ignored in the processing of these elements.
84 * @param e DOM to supply configuration for provider
86 MetadataProvider(const xercesc::DOMElement* e=nullptr);
90 * Destructor will delete any installed filters.
92 virtual ~MetadataProvider();
95 * Adds a metadata filter to apply to any resolved metadata. Will not be applied
96 * to metadata that is already loaded.
98 * @param newFilter metadata filter to add
100 virtual void addMetadataFilter(MetadataFilter* newFilter);
103 * Removes a metadata filter. The caller must delete the filter if necessary.
105 * @param oldFilter metadata filter to remove
106 * @return the old filter
108 virtual MetadataFilter* removeMetadataFilter(MetadataFilter* oldFilter);
111 * Should be called after instantiating provider and adding filters, but before
112 * performing any lookup operations. Allows the provider to defer initialization
113 * processes that are likely to result in exceptions until after the provider is
114 * safely created. Providers SHOULD perform as much processing as possible in
115 * this method so as to report/log any errors that would affect later processing.
117 virtual void init()=0;
120 * Gets the entire metadata tree, after the registered filter has been applied.
121 * The caller MUST unlock the provider when finished with the data.
123 * @return the entire metadata tree
125 virtual const xmltooling::XMLObject* getMetadata() const=0;
128 * Gets the metadata for a given group of entities. If a valid group is returned,
129 * the resolver will be left in a locked state. The caller MUST unlock the
130 * resolver when finished with the group.
132 * @param name the name of the group
133 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
135 * @return the group's metadata or nullptr if there is no metadata or no valid metadata
137 virtual const EntitiesDescriptor* getEntitiesDescriptor(const XMLCh* name, bool requireValidMetadata=true) const;
140 * Gets the metadata for a given group of entities. If a valid group is returned,
141 * the resolver will be left in a locked state. The caller MUST unlock the
142 * resolver when finished with the group.
144 * @param name the name of the group
145 * @param requireValidMetadata indicates whether the metadata for the group must be valid/current
147 * @return the group's metadata or nullptr if there is no metadata or no valid metadata
149 virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const=0;
152 * Batches up criteria for entity lookup.
154 struct SAML_API Criteria {
156 * Default constructor.
163 * @param id entityID to lookup
164 * @param q element/type of role, if any
165 * @param prot protocol support constant, if any
166 * @param valid true iff stale metadata should be ignored
168 Criteria(const XMLCh* id, const xmltooling::QName* q=nullptr, const XMLCh* prot=nullptr, bool valid=true);
173 * @param id entityID to lookup
174 * @param q element/type of role, if any
175 * @param prot protocol support constant, if any
176 * @param valid true iff stale metadata should be ignored
178 Criteria(const char* id, const xmltooling::QName* q=nullptr, const XMLCh* prot=nullptr, bool valid=true);
183 * @param a artifact to lookup
184 * @param q element/type of role, if any
185 * @param prot protocol support constant, if any
186 * @param valid true iff stale metadata should be ignored
188 Criteria(const SAMLArtifact* a, const xmltooling::QName* q=nullptr, const XMLCh* prot=nullptr, bool valid=true);
193 * Restores the object to its default state.
195 virtual void reset();
197 /** Unique ID of entity. */
198 const XMLCh* entityID_unicode;
199 /** Unique ID of entity. */
200 const char* entityID_ascii;
202 const SAMLArtifact* artifact;
203 /** Element or schema type QName of metadata role. */
204 const xmltooling::QName* role;
205 /** Protocol support constant. */
206 const XMLCh* protocol;
207 /** Backup protocol support constant. */
208 const XMLCh* protocol2;
209 /** Controls whether stale metadata is ignored. */
214 * Gets entity metadata based on supplied criteria. If a valid entity is returned,
215 * the provider will be left in a locked state. The caller MUST unlock the
216 * provider when finished with the entity.
218 * @param criteria lookup criteria
220 * @return the entity's metadata (and optionally a role) or nullptr if there is no qualifying metadata
222 virtual std::pair<const EntityDescriptor*,const RoleDescriptor*> getEntityDescriptor(const Criteria& criteria) const=0;
226 * Applies any installed filters to a metadata instance.
228 * @param xmlObject the metadata to be filtered
230 void doFilters(xmltooling::XMLObject& xmlObject) const;
233 std::vector<MetadataFilter*> m_filters;
236 #if defined (_MSC_VER)
237 #pragma warning( pop )
241 * Registers MetadataProvider classes into the runtime.
243 void SAML_API registerMetadataProviders();
245 /** MetadataProvider based on local or remote XML file */
246 #define XML_METADATA_PROVIDER "XML"
248 /** MetadataProvider based on dynamic resolution */
249 #define DYNAMIC_METADATA_PROVIDER "Dynamic"
251 /** MetadataProvider that wraps a sequence of metadata providers. */
252 #define CHAINING_METADATA_PROVIDER "Chaining"
254 /** MetadataProvider that returns an empty "dummy" entity descriptor. */
255 #define NULL_METADATA_PROVIDER "Null"
257 DECL_XMLTOOLING_EXCEPTION(MetadataException,SAML_EXCEPTIONAPI(SAML_API),opensaml::saml2md,xmltooling::XMLToolingException,Exceptions related to metadata use);
261 #endif /* __saml2_metadataprov_h__ */