/*
- * Copyright 2001-2009 Internet2
+ * Copyright 2001-2010 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* AttributeScopeRegexFunctor.cpp
*
- * A match function that evaluates an attribute value's scope against the provided regular expression.
+ * A match function that evaluates an attribute value's scope against the
+ * provided regular expression.
*/
#include "internal.h"
#include "attribute/filtering/FilterPolicyContext.h"
#include "attribute/filtering/MatchFunctor.h"
+#include <xmltooling/util/XMLHelper.h>
#include <xercesc/util/regx/RegularExpression.hpp>
using namespace shibsp;
using namespace std;
+using xmltooling::XMLHelper;
namespace shibsp {
*/
class SHIBSP_DLLLOCAL AttributeScopeRegexFunctor : public MatchFunctor
{
- xmltooling::auto_ptr_char m_attributeID;
+ string m_attributeID;
RegularExpression* m_regex;
bool hasScope(const FilteringContext& filterContext) const;
bool matches(const Attribute& attribute, size_t index) const;
public:
- AttributeScopeRegexFunctor(const DOMElement* e)
- : m_attributeID(e ? e->getAttributeNS(NULL,attributeID) : NULL) {
- const XMLCh* r = e ? e->getAttributeNS(NULL,regex) : NULL;
+ AttributeScopeRegexFunctor(const DOMElement* e) : m_regex(nullptr), m_attributeID(XMLHelper::getAttrString(e, nullptr, attributeID)) {
+ const XMLCh* r = e ? e->getAttributeNS(nullptr,regex) : nullptr;
if (!r || !*r)
throw ConfigurationException("AttributeScopeRegex MatchFunctor requires non-empty regex attribute.");
try {
- m_regex = new RegularExpression(r, e->getAttributeNS(NULL,options));
+ m_regex = new RegularExpression(r, e->getAttributeNS(nullptr,options));
}
catch (XMLException& ex) {
xmltooling::auto_ptr_char temp(ex.getMessage());
}
bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
- if (!m_attributeID.get() || !*m_attributeID.get())
+ if (m_attributeID.empty())
throw AttributeFilteringException("No attributeID specified.");
return hasScope(filterContext);
}
bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
- if (!m_attributeID.get() || !*m_attributeID.get() || XMLString::equals(m_attributeID.get(), attribute.getId()))
+ if (m_attributeID.empty() || m_attributeID == attribute.getId())
return matches(attribute, index);
return hasScope(filterContext);
}
{
size_t count;
pair<multimap<string,Attribute*>::const_iterator,multimap<string,Attribute*>::const_iterator> attrs =
- filterContext.getAttributes().equal_range(m_attributeID.get());
+ filterContext.getAttributes().equal_range(m_attributeID);
for (; attrs.first != attrs.second; ++attrs.first) {
count = attrs.first->second->valueCount();
for (size_t index = 0; index < count; ++index) {