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.
18 * AttributeIssuerRegexFunctor.cpp
20 * A match function that evaluates to true if the Attribute issuer matches the provided regular
\r
25 #include "exceptions.h"
26 #include "attribute/filtering/FilteringContext.h"
27 #include "attribute/filtering/FilterPolicyContext.h"
29 #include <xercesc/util/regx/RegularExpression.hpp>
33 static const XMLCh options[] = UNICODE_LITERAL_7(o,p,t,i,o,n,s);
34 static const XMLCh regex[] = UNICODE_LITERAL_5(r,e,g,e,x);
37 * A match function that evaluates to true if the Attribute issuer matches the provided regular
\r
40 class SHIBSP_DLLLOCAL AttributeIssuerRegexFunctor : public MatchFunctor
42 RegularExpression* m_regex;
44 AttributeIssuerRegexFunctor(const DOMElement* e) {
45 const XMLCh* r = e ? e->getAttributeNS(NULL,regex) : NULL;
47 throw ConfigurationException("AttributeIssuerRegex MatchFunctor requires non-empty regex attribute.");
49 m_regex = new RegularExpression(r, e->getAttributeNS(NULL,options));
51 catch (XMLException& ex) {
\r
52 xmltooling::auto_ptr_char temp(ex.getMessage());
\r
53 throw ConfigurationException(temp.get());
\r
57 virtual ~AttributeIssuerRegexFunctor() {
61 bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
62 return m_regex->matches(filterContext.getAttributeIssuer());
65 bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
66 return m_regex->matches(filterContext.getAttributeIssuer());
70 MatchFunctor* SHIBSP_DLLLOCAL AttributeIssuerRegexFactory(const std::pair<const FilterPolicyContext*,const DOMElement*>& p)
72 return new AttributeIssuerRegexFunctor(p.second);