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 * AuthenticationMethodRegexFunctor.cpp
24 * A match function that evaluates to true if the user's authentication
25 * method matches the provided regular expression.
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 user's authentication method matches the provided regular
45 class SHIBSP_DLLLOCAL AuthenticationMethodRegexFunctor : public MatchFunctor
47 RegularExpression* m_regex;
49 AuthenticationMethodRegexFunctor(const DOMElement* e) : m_regex(nullptr) {
50 const XMLCh* r = e ? e->getAttributeNS(nullptr,regex) : nullptr;
52 throw ConfigurationException("AuthenticationMethodRegex MatchFunctor requires non-empty regex attribute.");
54 m_regex = 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 ~AuthenticationMethodRegexFunctor() {
66 bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
67 return (m_regex->matches(filterContext.getAuthnContextClassRef()) || m_regex->matches(filterContext.getAuthnContextDeclRef()));
70 bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
71 return (m_regex->matches(filterContext.getAuthnContextClassRef()) || m_regex->matches(filterContext.getAuthnContextDeclRef()));
75 MatchFunctor* SHIBSP_DLLLOCAL AuthenticationMethodRegexFactory(const std::pair<const FilterPolicyContext*,const DOMElement*>& p)
77 return new AuthenticationMethodRegexFunctor(p.second);