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.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * AttributeIssuerRegexFunctor.cpp
24 * A match function that evaluates to true if the Attribute issuer matches the provided regular
29 #include "exceptions.h"
30 #include "attribute/filtering/FilteringContext.h"
31 #include "attribute/filtering/FilterPolicyContext.h"
32 #include "attribute/filtering/MatchFunctor.h"
34 #include <xercesc/util/regx/RegularExpression.hpp>
38 static const XMLCh options[] = UNICODE_LITERAL_7(o,p,t,i,o,n,s);
39 static const XMLCh regex[] = UNICODE_LITERAL_5(r,e,g,e,x);
42 * A match function that evaluates to true if the Attribute issuer matches the provided regular
45 class SHIBSP_DLLLOCAL AttributeIssuerRegexFunctor : public MatchFunctor
47 boost::scoped_ptr<RegularExpression> m_regex;
49 AttributeIssuerRegexFunctor(const DOMElement* e) {
50 const XMLCh* r = e ? e->getAttributeNS(nullptr, regex) : nullptr;
52 throw ConfigurationException("AttributeIssuerRegex MatchFunctor requires non-empty regex attribute.");
54 m_regex.reset(new RegularExpression(r, e->getAttributeNS(nullptr,options)));
56 catch (XMLException& ex) {
57 xmltooling::auto_ptr_char temp(ex.getMessage());
58 throw ConfigurationException(temp.get());
62 virtual ~AttributeIssuerRegexFunctor() {}
64 bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
65 return m_regex->matches(filterContext.getAttributeIssuer());
68 bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
69 return m_regex->matches(filterContext.getAttributeIssuer());
73 MatchFunctor* SHIBSP_DLLLOCAL AttributeIssuerRegexFactory(const std::pair<const FilterPolicyContext*,const DOMElement*>& p)
75 return new AttributeIssuerRegexFunctor(p.second);