Change license header.
[shibboleth/sp.git] / shibsp / attribute / filtering / impl / AttributeRequesterStringFunctor.cpp
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 /**
22  * AttributeRequesterStringFunctor.cpp
23  * 
24  * A match function that matches the attribute requester's name against the specified value.
25  */
26
27 #include "internal.h"
28 #include "exceptions.h"
29 #include "attribute/filtering/FilteringContext.h"
30 #include "attribute/filtering/FilterPolicyContext.h"
31 #include "attribute/filtering/MatchFunctor.h"
32
33 #include <xmltooling/util/XMLHelper.h>
34 using xmltooling::XMLHelper;
35
36 namespace shibsp {
37
38     static const XMLCh value[] = UNICODE_LITERAL_5(v,a,l,u,e);
39     static const XMLCh ignoreCase[] = UNICODE_LITERAL_10(i,g,n,o,r,e,C,a,s,e);
40
41     /**
42      * A match function that matches the attribute requester's name against the specified value.
43      */
44     class SHIBSP_DLLLOCAL AttributeRequesterStringFunctor : public MatchFunctor
45     {
46         const XMLCh* m_value;
47         bool m_ignoreCase;
48     public:
49         AttributeRequesterStringFunctor(const DOMElement* e) : m_value(nullptr), m_ignoreCase(XMLHelper::getAttrBool(e, false, ignoreCase)) {
50             m_value = e ? e->getAttributeNS(nullptr,value) : nullptr;
51             if (!m_value || !*m_value)
52                 throw ConfigurationException("AttributeRequesterString MatchFunctor requires non-empty value attribute.");
53         }
54
55         bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
56             if (m_ignoreCase)
57                 return (XMLString::compareIString(m_value, filterContext.getAttributeRequester()) == 0);
58             else
59                 return XMLString::equals(m_value, filterContext.getAttributeRequester());
60         }
61
62         bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
63             return evaluatePolicyRequirement(filterContext);
64         }
65     };
66
67     MatchFunctor* SHIBSP_DLLLOCAL AttributeRequesterStringFactory(const std::pair<const FilterPolicyContext*,const DOMElement*>& p)
68     {
69         return new AttributeRequesterStringFunctor(p.second);
70     }
71
72 };