9a3c44ed9b7adc8696929e7fbbd7318726af0dca
[shibboleth/cpp-sp.git] / shibsp / attribute / filtering / impl / MatchFunctor.cpp
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  * MatchFunctor.cpp
23  * 
24  * A function that evaluates whether an expressed criteria is met by the current filter context.
25  */
26
27 #include "internal.h"
28 #include "attribute/filtering/FilterPolicyContext.h"
29 #include "attribute/filtering/MatchFunctor.h"
30 #include "util/SPConstants.h"
31
32 #include <xercesc/util/XMLUniDefs.hpp>
33
34 using namespace shibsp;
35 using namespace xmltooling;
36 using namespace std;
37
38 #define DECL_FACTORY(name) \
39     SHIBSP_DLLLOCAL PluginManager< MatchFunctor,xmltooling::QName,pair<const FilterPolicyContext*,const DOMElement*> >::Factory name##Factory
40
41 #define DECL_BASIC_QNAME(name,lit) \
42     xmltooling::QName shibsp::name##Type(shibspconstants::SHIB2ATTRIBUTEFILTER_MF_BASIC_NS, lit)
43
44 #define DECL_SAML_QNAME(name,lit) \
45     xmltooling::QName shibsp::name##Type(shibspconstants::SHIB2ATTRIBUTEFILTER_MF_SAML_NS, lit)
46
47 #define REGISTER_FACTORY(name) \
48     mgr.registerFactory(name##Type, name##Factory)
49
50 namespace shibsp {
51     DECL_FACTORY(AnyMatchFunctor);
52     DECL_FACTORY(AndMatchFunctor);
53     DECL_FACTORY(OrMatchFunctor);
54     DECL_FACTORY(NotMatchFunctor);
55     DECL_FACTORY(AttributeIssuerString);
56     DECL_FACTORY(AttributeRequesterString);
57     DECL_FACTORY(AuthenticationMethodString);
58     DECL_FACTORY(AttributeValueString);
59     DECL_FACTORY(AttributeScopeString);
60     DECL_FACTORY(AttributeIssuerRegex);
61     DECL_FACTORY(AttributeRequesterRegex);
62     DECL_FACTORY(AuthenticationMethodRegex);
63     DECL_FACTORY(AttributeValueRegex);
64     DECL_FACTORY(AttributeScopeRegex);
65     DECL_FACTORY(NumberOfAttributeValues);
66     DECL_FACTORY(AttributeIssuerInEntityGroup);
67     DECL_FACTORY(AttributeRequesterInEntityGroup);
68     DECL_FACTORY(AttributeIssuerEntityAttributeExactMatch);
69     DECL_FACTORY(AttributeRequesterEntityAttributeExactMatch);
70     DECL_FACTORY(AttributeIssuerEntityAttributeRegexMatch);
71     DECL_FACTORY(AttributeRequesterEntityAttributeRegexMatch);
72     DECL_FACTORY(AttributeIssuerEntityMatcher);
73     DECL_FACTORY(AttributeRequesterEntityMatcher);
74     DECL_FACTORY(AttributeScopeMatchesShibMDScope);
75     DECL_FACTORY(NameIDQualifierString);
76
77
78     static const XMLCh ANY[] =                          UNICODE_LITERAL_3(A,N,Y);
79     static const XMLCh AND[] =                          UNICODE_LITERAL_3(A,N,D);
80     static const XMLCh OR[] =                           UNICODE_LITERAL_2(O,R);
81     static const XMLCh NOT[] =                          UNICODE_LITERAL_3(N,O,T);
82     static const XMLCh AttributeIssuerString[] =        UNICODE_LITERAL_21(A,t,t,r,i,b,u,t,e,I,s,s,u,e,r,S,t,r,i,n,g);
83     static const XMLCh AttributeRequesterString[] =     UNICODE_LITERAL_24(A,t,t,r,i,b,u,t,e,R,e,q,u,e,s,t,e,r,S,t,r,i,n,g);
84     static const XMLCh AuthenticationMethodString[] =   UNICODE_LITERAL_26(A,u,t,h,e,n,t,i,c,a,t,i,o,n,M,e,t,h,o,d,S,t,r,i,n,g);
85     static const XMLCh AttributeValueString[] =         UNICODE_LITERAL_20(A,t,t,r,i,b,u,t,e,V,a,l,u,e,S,t,r,i,n,g);
86     static const XMLCh AttributeScopeString[] =         UNICODE_LITERAL_20(A,t,t,r,i,b,u,t,e,S,c,o,p,e,S,t,r,i,n,g);
87     static const XMLCh AttributeIssuerRegex[] =         UNICODE_LITERAL_20(A,t,t,r,i,b,u,t,e,I,s,s,u,e,r,R,e,g,e,x);
88     static const XMLCh AttributeRequesterRegex[] =      UNICODE_LITERAL_23(A,t,t,r,i,b,u,t,e,R,e,q,u,e,s,t,e,r,R,e,g,e,x);
89     static const XMLCh AuthenticationMethodRegex[] =    UNICODE_LITERAL_25(A,u,t,h,e,n,t,i,c,a,t,i,o,n,M,e,t,h,o,d,R,e,g,e,x);
90     static const XMLCh AttributeValueRegex[] =          UNICODE_LITERAL_19(A,t,t,r,i,b,u,t,e,V,a,l,u,e,R,e,g,e,x);
91     static const XMLCh AttributeScopeRegex[] =          UNICODE_LITERAL_19(A,t,t,r,i,b,u,t,e,S,c,o,p,e,R,e,g,e,x);
92     static const XMLCh NumberOfAttributeValues[] =      UNICODE_LITERAL_23(N,u,m,b,e,r,O,f,A,t,t,r,i,b,u,t,e,V,a,l,u,e,s);
93     static const XMLCh AttributeIssuerInEntityGroup[] = UNICODE_LITERAL_28(A,t,t,r,i,b,u,t,e,I,s,s,u,e,r,I,n,E,n,t,i,t,y,G,r,o,u,p);
94     static const XMLCh AttributeRequesterInEntityGroup[] = UNICODE_LITERAL_31(A,t,t,r,i,b,u,t,e,R,e,q,u,e,s,t,e,r,I,n,E,n,t,i,t,y,G,r,o,u,p);
95     static const XMLCh AttributeIssuerEntityAttributeExactMatch[] = UNICODE_LITERAL_40(A,t,t,r,i,b,u,t,e,I,s,s,u,e,r,E,n,t,i,t,y,A,t,t,r,i,b,u,t,e,E,x,a,c,t,M,a,t,c,h);
96     static const XMLCh AttributeRequesterEntityAttributeExactMatch[] = UNICODE_LITERAL_43(A,t,t,r,i,b,u,t,e,R,e,q,u,e,s,t,e,r,E,n,t,i,t,y,A,t,t,r,i,b,u,t,e,E,x,a,c,t,M,a,t,c,h);
97     static const XMLCh AttributeIssuerEntityAttributeRegexMatch[] = UNICODE_LITERAL_40(A,t,t,r,i,b,u,t,e,I,s,s,u,e,r,E,n,t,i,t,y,A,t,t,r,i,b,u,t,e,R,e,g,e,x,M,a,t,c,h);
98     static const XMLCh AttributeRequesterEntityAttributeRegexMatch[] = UNICODE_LITERAL_43(A,t,t,r,i,b,u,t,e,R,e,q,u,e,s,t,e,r,E,n,t,i,t,y,A,t,t,r,i,b,u,t,e,R,e,g,e,x,M,a,t,c,h);
99     static const XMLCh AttributeIssuerEntityMatcher[] = UNICODE_LITERAL_28(A,t,t,r,i,b,u,t,e,I,s,s,u,e,r,E,n,t,i,t,y,M,a,t,c,h,e,r);
100     static const XMLCh AttributeRequesterEntityMatcher[] = UNICODE_LITERAL_31(A,t,t,r,i,b,u,t,e,R,e,q,u,e,s,t,e,r,E,n,t,i,t,y,M,a,t,c,h,e,r);
101     static const XMLCh AttributeScopeMatchesShibMDScope[] = UNICODE_LITERAL_32(A,t,t,r,i,b,u,t,e,S,c,o,p,e,M,a,t,c,h,e,s,S,h,i,b,M,D,S,c,o,p,e);
102     static const XMLCh NameIDQualifierString[] =        UNICODE_LITERAL_21(N,a,m,e,I,D,Q,u,a,l,i,f,i,e,r,S,t,r,i,n,g);
103 };
104
105 DECL_BASIC_QNAME(AnyMatchFunctor, ANY);
106 DECL_BASIC_QNAME(AndMatchFunctor, AND);
107 DECL_BASIC_QNAME(OrMatchFunctor, OR);
108 DECL_BASIC_QNAME(NotMatchFunctor, NOT);
109 DECL_BASIC_QNAME(AttributeIssuerString, AttributeIssuerString);
110 DECL_BASIC_QNAME(AttributeRequesterString, AttributeRequesterString);
111 DECL_BASIC_QNAME(AuthenticationMethodString, AuthenticationMethodString);
112 DECL_BASIC_QNAME(AttributeValueString, AttributeValueString);
113 DECL_BASIC_QNAME(AttributeScopeString, AttributeScopeString);
114 DECL_BASIC_QNAME(AttributeIssuerRegex, AttributeIssuerRegex);
115 DECL_BASIC_QNAME(AttributeRequesterRegex, AttributeRequesterRegex);
116 DECL_BASIC_QNAME(AuthenticationMethodRegex, AuthenticationMethodRegex);
117 DECL_BASIC_QNAME(AttributeValueRegex, AttributeValueRegex);
118 DECL_BASIC_QNAME(AttributeScopeRegex, AttributeScopeRegex);
119 DECL_BASIC_QNAME(NumberOfAttributeValues, NumberOfAttributeValues);
120 DECL_SAML_QNAME(AttributeIssuerInEntityGroup, AttributeIssuerInEntityGroup);
121 DECL_SAML_QNAME(AttributeRequesterInEntityGroup, AttributeRequesterInEntityGroup);
122 DECL_SAML_QNAME(AttributeIssuerEntityAttributeExactMatch, AttributeIssuerEntityAttributeExactMatch);
123 DECL_SAML_QNAME(AttributeRequesterEntityAttributeExactMatch, AttributeRequesterEntityAttributeExactMatch);
124 DECL_SAML_QNAME(AttributeIssuerEntityAttributeRegexMatch, AttributeIssuerEntityAttributeRegexMatch);
125 DECL_SAML_QNAME(AttributeRequesterEntityAttributeRegexMatch, AttributeRequesterEntityAttributeRegexMatch);
126 DECL_SAML_QNAME(AttributeIssuerEntityMatcher, AttributeIssuerEntityMatcher);
127 DECL_SAML_QNAME(AttributeRequesterEntityMatcher, AttributeRequesterEntityMatcher);
128 DECL_SAML_QNAME(AttributeScopeMatchesShibMDScope, AttributeScopeMatchesShibMDScope);
129 DECL_SAML_QNAME(NameIDQualifierString, NameIDQualifierString);
130
131 void SHIBSP_API shibsp::registerMatchFunctors()
132 {
133     PluginManager< MatchFunctor,xmltooling::QName,pair<const FilterPolicyContext*,const DOMElement*> >& mgr =
134         SPConfig::getConfig().MatchFunctorManager;
135     REGISTER_FACTORY(AnyMatchFunctor);
136     REGISTER_FACTORY(AndMatchFunctor);
137     REGISTER_FACTORY(OrMatchFunctor);
138     REGISTER_FACTORY(NotMatchFunctor);
139     REGISTER_FACTORY(AttributeIssuerString);
140     REGISTER_FACTORY(AttributeRequesterString);
141     REGISTER_FACTORY(AuthenticationMethodString);
142     REGISTER_FACTORY(AttributeValueString);
143     REGISTER_FACTORY(AttributeScopeString);
144     REGISTER_FACTORY(AttributeIssuerRegex);
145     REGISTER_FACTORY(AttributeRequesterRegex);
146     REGISTER_FACTORY(AuthenticationMethodRegex);
147     REGISTER_FACTORY(AttributeValueRegex);
148     REGISTER_FACTORY(AttributeScopeRegex);
149     REGISTER_FACTORY(NumberOfAttributeValues);
150     REGISTER_FACTORY(AttributeIssuerInEntityGroup);
151     REGISTER_FACTORY(AttributeRequesterInEntityGroup);
152     REGISTER_FACTORY(AttributeIssuerEntityAttributeExactMatch);
153     REGISTER_FACTORY(AttributeRequesterEntityAttributeExactMatch);
154     REGISTER_FACTORY(AttributeIssuerEntityAttributeRegexMatch);
155     REGISTER_FACTORY(AttributeRequesterEntityAttributeRegexMatch);
156     REGISTER_FACTORY(AttributeIssuerEntityMatcher);
157     REGISTER_FACTORY(AttributeRequesterEntityMatcher);
158     REGISTER_FACTORY(AttributeScopeMatchesShibMDScope);
159     REGISTER_FACTORY(NameIDQualifierString);
160 }
161
162 MatchFunctor::MatchFunctor()
163 {
164 }
165
166 MatchFunctor::~MatchFunctor()
167 {
168 }
169
170 FilterPolicyContext::FilterPolicyContext(multimap<string,MatchFunctor*>& functors) : m_functors(functors)
171 {
172 }
173
174 FilterPolicyContext::~FilterPolicyContext()
175 {
176 }
177
178 multimap<string,MatchFunctor*>& FilterPolicyContext::getMatchFunctors() const
179 {
180     return m_functors;
181 }