2 * Copyright 2001-2007 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.
20 * A MatchFunctor that logical ORs the results of contained functors.
24 #include "exceptions.h"
25 #include "attribute/filtering/FilterPolicyContext.h"
26 #include "util/SPConstants.h"
28 #include <xercesc/util/XMLUniDefs.hpp>
29 #include <xmltooling/util/XMLHelper.h>
31 using namespace shibsp;
32 using namespace xmltooling;
38 * A MatchFunctor that logical ORs the results of contained functors.
40 class SHIBSP_DLLLOCAL OrMatchFunctor : public MatchFunctor
43 OrMatchFunctor(const pair<const FilterPolicyContext*,const DOMElement*>& p);
45 bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
46 for (vector<const MatchFunctor*>::const_iterator mf = m_functors.begin(); mf!=m_functors.end(); ++mf)
47 if ((*mf)->evaluatePolicyRequirement(filterContext))
52 bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
53 for (vector<const MatchFunctor*>::const_iterator mf = m_functors.begin(); mf!=m_functors.end(); ++mf)
54 if ((*mf)->evaluatePermitValue(filterContext, attribute, index))
60 MatchFunctor* buildFunctor(const DOMElement* e, const FilterPolicyContext* functorMap);
62 vector<const MatchFunctor*> m_functors;
65 MatchFunctor* SHIBSP_DLLLOCAL OrFunctorFactory(const pair<const FilterPolicyContext*,const DOMElement*>& p)
67 return new OrMatchFunctor(p);
70 static XMLCh _id[] = UNICODE_LITERAL_2(i,d);
71 static XMLCh _ref[] = UNICODE_LITERAL_3(r,e,f);
72 static XMLCh Rule[] = UNICODE_LITERAL_4(R,u,l,e);
73 static XMLCh RuleReference[] = UNICODE_LITERAL_13(R,u,l,e,R,e,f,e,r,e,n,c,e);
76 OrMatchFunctor::OrMatchFunctor(const pair<const FilterPolicyContext*,const DOMElement*>& p)
79 const DOMElement* e = XMLHelper::getFirstChildElement(p.second);
82 if (XMLHelper::isNodeNamed(e, shibspconstants::SHIB2ATTRIBUTEFILTER_MF_BASIC_NS, Rule)) {
83 func = buildFunctor(e, p.first);
85 else if (XMLHelper::isNodeNamed(e, shibspconstants::SHIB2ATTRIBUTEFILTER_MF_BASIC_NS, RuleReference)) {
86 auto_ptr_char ref(e->getAttributeNS(NULL, _ref));
87 if (ref.get() && *ref.get()) {
88 multimap<string,MatchFunctor*>::const_iterator rule = p.first->getMatchFunctors().find(ref.get());
89 func = (rule!=p.first->getMatchFunctors().end()) ? rule->second : NULL;
94 m_functors.push_back(func);
96 e = XMLHelper::getNextSiblingElement(e);
100 MatchFunctor* OrMatchFunctor::buildFunctor(const DOMElement* e, const FilterPolicyContext* functorMap)
102 // We'll track and map IDs just for consistency, but don't require them or worry about dups.
103 auto_ptr_char temp(e->getAttributeNS(NULL,_id));
104 const char* id = (temp.get() && *temp.get()) ? temp.get() : "";
105 if (*id && functorMap->getMatchFunctors().count(id))
108 auto_ptr<QName> type(XMLHelper::getXSIType(e));
110 throw ConfigurationException("Child Rule found with no xsi:type.");
112 MatchFunctor* func = SPConfig::getConfig().MatchFunctorManager.newPlugin(*type.get(), make_pair(functorMap,e));
113 functorMap->getMatchFunctors().insert(make_pair(id, func));