Add context API to metadata filters.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / MetadataFilter.h
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 /**
22  * @file saml/saml2/metadata/MetadataFilter.h
23  *
24  * Processes metadata after it's been unmarshalled.
25  */
26
27 #include <saml/saml2/metadata/MetadataProvider.h>
28
29 #ifndef __saml2_metadatafilt_h__
30 #define __saml2_metadatafilt_h__
31
32 namespace opensaml {
33     namespace saml2md {
34
35         /**
36          * Marker interface for supplying environmental context to filters.
37          */
38         class SAML_API MetadataFilterContext
39         {
40             MAKE_NONCOPYABLE(MetadataFilterContext);
41         protected:
42             MetadataFilterContext();
43         public:
44             virtual ~MetadataFilterContext();
45         };
46
47         /**
48          * A metadata filter is used to process metadata after resolution and unmarshalling.
49          *
50          * Some filters might remove everything but identity provider roles, decreasing the data a service provider
51          * needs to work with, or a filter could be used to perform integrity checking on the retrieved metadata by
52          * verifying a digital signature.
53          */
54         class SAML_API MetadataFilter
55         {
56             MAKE_NONCOPYABLE(MetadataFilter);
57         protected:
58             MetadataFilter();
59         public:
60             virtual ~MetadataFilter();
61
62             /**
63              * Returns an identifying string for the filter.
64              *
65              * @return the ID string
66              */
67             virtual const char* getId() const=0;
68
69             /**
70              * @deprecated
71              * Filters the given metadata. Exceptions should generally not be thrown to
72              * signal the removal of information, only for systemic processing failure.
73              *
74              * @param xmlObject the metadata to be filtered
75              */
76             virtual void doFilter(xmltooling::XMLObject& xmlObject) const;
77
78             /**
79              * Filters the given metadata. Exceptions should generally not be thrown to
80              * signal the removal of information, only for systemic processing failure.
81              *
82              * @param ctx       context interface, or nullptr
83              * @param xmlObject the metadata to be filtered
84              */
85             virtual void doFilter(MetadataFilterContext* ctx, xmltooling::XMLObject& xmlObject) const;
86         };
87
88         /**
89          * Registers MetadataFilter classes into the runtime.
90          */
91         void SAML_API registerMetadataFilters();
92
93         /** MetadataFilter that deletes blacklisted entities. */
94         #define BLACKLIST_METADATA_FILTER           "Blacklist"
95
96         /** MetadataFilter that deletes all but whitelisted entities. */
97         #define WHITELIST_METADATA_FILTER           "Whitelist"
98
99         /** MetadataFilter that verifies signatures and filters out any that don't pass. */
100         #define SIGNATURE_METADATA_FILTER           "Signature"
101
102         /** MetadataFilter that enforces expiration requirements. */
103         #define REQUIREVALIDUNTIL_METADATA_FILTER   "RequireValidUntil"
104
105         /** MetadataFilter that removes non-retained roles. */
106         #define ENTITYROLE_METADATA_FILTER          "EntityRoleWhiteList"
107
108         /** MetadataFilter that adds EntityAttributes extension. */
109         #define ENTITYATTR_METADATA_FILTER          "EntityAttributes"
110
111         DECL_XMLTOOLING_EXCEPTION(MetadataFilterException,SAML_EXCEPTIONAPI(SAML_API),opensaml::saml2md,MetadataException,Exceptions related to metadata filtering);
112     };
113 };
114
115 #endif /* __saml2_metadatafilt_h__ */