2 * Copyright 2001-2009 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 * AttributeIssuerRegexFunctor.cpp
20 * A match function that evaluates to true if the Attribute issuer matches the provided regular
25 #include "exceptions.h"
26 #include "attribute/filtering/FilteringContext.h"
27 #include "attribute/filtering/FilterPolicyContext.h"
28 #include "attribute/filtering/MatchFunctor.h"
30 #include <xercesc/util/regx/RegularExpression.hpp>
34 static const XMLCh options[] = UNICODE_LITERAL_7(o,p,t,i,o,n,s);
35 static const XMLCh regex[] = UNICODE_LITERAL_5(r,e,g,e,x);
38 * A match function that evaluates to true if the Attribute issuer matches the provided regular
41 class SHIBSP_DLLLOCAL AttributeIssuerRegexFunctor : public MatchFunctor
43 RegularExpression* m_regex;
45 AttributeIssuerRegexFunctor(const DOMElement* e) {
46 const XMLCh* r = e ? e->getAttributeNS(NULL,regex) : NULL;
48 throw ConfigurationException("AttributeIssuerRegex MatchFunctor requires non-empty regex attribute.");
50 m_regex = new RegularExpression(r, e->getAttributeNS(NULL,options));
52 catch (XMLException& ex) {
53 xmltooling::auto_ptr_char temp(ex.getMessage());
54 throw ConfigurationException(temp.get());
58 virtual ~AttributeIssuerRegexFunctor() {
62 bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
63 return m_regex->matches(filterContext.getAttributeIssuer());
66 bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
67 return m_regex->matches(filterContext.getAttributeIssuer());
71 MatchFunctor* SHIBSP_DLLLOCAL AttributeIssuerRegexFactory(const std::pair<const FilterPolicyContext*,const DOMElement*>& p)
73 return new AttributeIssuerRegexFunctor(p.second);