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 * AttributeScopeMatchesShibMDScopeFunctor.cpp
24 * A match function that ensures that an attributes value's scope matches
25 * a scope given in metadata for the entity or role.
29 #include "exceptions.h"
30 #include "attribute/Attribute.h"
31 #include "attribute/filtering/FilteringContext.h"
32 #include "attribute/filtering/FilterPolicyContext.h"
33 #include "attribute/filtering/MatchFunctor.h"
34 #include "metadata/MetadataExt.h"
36 #include <saml/saml2/metadata/Metadata.h>
37 #include <xercesc/util/regx/RegularExpression.hpp>
39 using namespace opensaml::saml2md;
40 using namespace xmltooling;
45 static const XMLCh groupID[] = UNICODE_LITERAL_7(g,r,o,u,p,I,D);
48 * A match function that ensures that an attributes value's scope matches a scope given in metadata for the entity or role.
50 class SHIBSP_DLLLOCAL AttributeScopeMatchesShibMDScopeFunctor : public MatchFunctor
53 bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
54 throw AttributeFilteringException("Metadata scope matching not usable as a PolicyRequirement.");
57 bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
58 const RoleDescriptor* issuer = filterContext.getAttributeIssuerMetadata();
62 const char* scope = attribute.getScope(index);
63 if (!scope || !*scope)
65 auto_arrayptr<XMLCh> widescope(fromUTF8(scope));
68 const Extensions* ext = issuer->getExtensions();
70 const vector<XMLObject*>& exts = ext->getUnknownXMLObjects();
71 for (vector<XMLObject*>::const_iterator e = exts.begin(); e != exts.end(); ++e) {
72 rule = dynamic_cast<const Scope*>(*e);
73 if (rule && matches(*rule, widescope)) {
79 ext = dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getExtensions();
81 const vector<XMLObject*>& exts = ext->getUnknownXMLObjects();
82 for (vector<XMLObject*>::const_iterator e = exts.begin(); e != exts.end(); ++e) {
83 rule = dynamic_cast<const Scope*>(*e);
84 if (rule && matches(*rule, widescope)) {
94 bool matches(const Scope& rule, auto_arrayptr<XMLCh>& scope) const {
95 const XMLCh* val = rule.getValue();
98 RegularExpression re(val);
99 return re.matches(scope.get());
102 return XMLString::equals(val, scope.get());
109 MatchFunctor* SHIBSP_DLLLOCAL AttributeScopeMatchesShibMDScopeFactory(const pair<const FilterPolicyContext*,const DOMElement*>& p)
111 return new AttributeScopeMatchesShibMDScopeFunctor();