1eabf5dd4ca80ed1ee413d686de1d0afadc940f7
[shibboleth/sp.git] / shibsp / attribute / filtering / impl / MatchFunctor.cpp
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * MatchFunctor.cpp
19  * 
20  * A function that evaluates whether an expressed criteria is met by the current filter context.
21  */
22
23 #include "internal.h"
24 #include "attribute/filtering/MatchFunctor.h"
25 #include "util/SPConstants.h"
26
27 #include <xercesc/util/XMLUniDefs.hpp>
28
29 using namespace shibsp;
30 using namespace xmltooling;
31 using namespace std;
32
33 #define DECL_FACTORY(name) \
34     SHIBSP_DLLLOCAL PluginManager< MatchFunctor,QName,pair<const FilterPolicyContext*,const DOMElement*> >::Factory name##Factory
35
36 #define DECL_BASIC_QNAME(name,lit) \
37     QName shibsp::name##Type(shibspconstants::SHIB2ATTRIBUTEFILTER_MF_BASIC_NS, lit)
38
39 #define REGISTER_FACTORY(name) \
40     mgr.registerFactory(name##Type, name##Factory)
41
42 namespace shibsp {
43     DECL_FACTORY(AnyMatchFunctor);
44     DECL_FACTORY(AndMatchFunctor);
45     DECL_FACTORY(OrMatchFunctor);
46     DECL_FACTORY(NotMatchFunctor);
47     DECL_FACTORY(AttributeIssuerString);
48     DECL_FACTORY(AttributeRequesterString);
49     DECL_FACTORY(AuthenticationMethodString);
50     DECL_FACTORY(AttributeValueString);
51     DECL_FACTORY(AttributeScopeString);
52     DECL_FACTORY(AttributeIssuerRegex);
53     DECL_FACTORY(AttributeRequesterRegex);
54     DECL_FACTORY(AuthenticationMethodRegex);
55     DECL_FACTORY(AttributeValueRegex);
56     DECL_FACTORY(AttributeScopeRegex);
57
58     static const XMLCh ANY[] =                          UNICODE_LITERAL_3(A,N,Y);
59     static const XMLCh AND[] =                          UNICODE_LITERAL_3(A,N,D);
60     static const XMLCh OR[] =                           UNICODE_LITERAL_2(O,R);
61     static const XMLCh NOT[] =                          UNICODE_LITERAL_3(N,O,T);
62     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);
63     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);
64     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);
65     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);
66     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);
67     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);
68     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);
69     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);
70     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);
71     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);
72 };
73
74 DECL_BASIC_QNAME(AnyMatchFunctor, ANY);
75 DECL_BASIC_QNAME(AndMatchFunctor, AND);
76 DECL_BASIC_QNAME(OrMatchFunctor, OR);
77 DECL_BASIC_QNAME(NotMatchFunctor, NOT);
78 DECL_BASIC_QNAME(AttributeIssuerString, AttributeIssuerString);
79 DECL_BASIC_QNAME(AttributeRequesterString, AttributeRequesterString);
80 DECL_BASIC_QNAME(AuthenticationMethodString, AuthenticationMethodString);
81 DECL_BASIC_QNAME(AttributeValueString, AttributeValueString);
82 DECL_BASIC_QNAME(AttributeScopeString, AttributeScopeString);
83 DECL_BASIC_QNAME(AttributeIssuerRegex, AttributeIssuerRegex);
84 DECL_BASIC_QNAME(AttributeRequesterRegex, AttributeRequesterRegex);
85 DECL_BASIC_QNAME(AuthenticationMethodRegex, AuthenticationMethodRegex);
86 DECL_BASIC_QNAME(AttributeValueRegex, AttributeValueRegex);
87 DECL_BASIC_QNAME(AttributeScopeRegex, AttributeScopeRegex);
88
89 void SHIBSP_API shibsp::registerMatchFunctors()
90 {
91     PluginManager< MatchFunctor,QName,pair<const FilterPolicyContext*,const DOMElement*> >& mgr =
92         SPConfig::getConfig().MatchFunctorManager;
93     REGISTER_FACTORY(AnyMatchFunctor);
94     REGISTER_FACTORY(AndMatchFunctor);
95     REGISTER_FACTORY(OrMatchFunctor);
96     REGISTER_FACTORY(NotMatchFunctor);
97     REGISTER_FACTORY(AttributeIssuerString);
98     REGISTER_FACTORY(AttributeRequesterString);
99     REGISTER_FACTORY(AuthenticationMethodString);
100     REGISTER_FACTORY(AttributeValueString);
101     REGISTER_FACTORY(AttributeScopeString);
102     REGISTER_FACTORY(AttributeIssuerRegex);
103     REGISTER_FACTORY(AttributeRequesterRegex);
104     REGISTER_FACTORY(AuthenticationMethodRegex);
105     REGISTER_FACTORY(AttributeValueRegex);
106     REGISTER_FACTORY(AttributeScopeRegex);
107 }