Log error when user used as Alias.
[shibboleth/cpp-sp.git] / xmlproviders / XMLAAP.cpp
1 /*
2  *  Copyright 2001-2005 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /* XMLAAP.cpp - XML AAP implementation
18
19    Scott Cantor
20    12/21/02
21
22    $History:$
23 */
24
25 #include "internal.h"
26
27 #include <log4cpp/Category.hh>
28
29 using namespace shibboleth;
30 using namespace saml;
31 using namespace log4cpp;
32 using namespace std;
33
34 #include <xercesc/util/regx/RegularExpression.hpp>
35
36 namespace {
37
38     class XMLAAPImpl : public ReloadableXMLFileImpl
39     {
40     public:
41         XMLAAPImpl(const char* pathname) : ReloadableXMLFileImpl(pathname), anyAttribute(false) { init(); }
42         XMLAAPImpl(const DOMElement* e) : ReloadableXMLFileImpl(e), anyAttribute(false) { init(); }
43         void init();
44         ~XMLAAPImpl();
45         
46         class AttributeRule : public IAttributeRule
47         {
48         public:
49             AttributeRule(const DOMElement* e);
50             ~AttributeRule() {}
51             
52             const XMLCh* getName() const { return m_name; }
53             const XMLCh* getNamespace() const { return m_namespace; }
54             const char* getAlias() const { return m_alias.get(); }
55             const char* getHeader() const { return m_header.get(); }
56             bool getCaseSensitive() const { return m_caseSensitive; }
57             bool getScoped() const { return m_scoped; }
58             void apply(SAMLAttribute& attribute, const IRoleDescriptor* role=NULL) const;
59     
60             enum value_type { literal, regexp, xpath };
61         private:    
62             const XMLCh* m_name;
63             const XMLCh* m_namespace;
64             auto_ptr_char m_alias;
65             auto_ptr_char m_header;
66             bool m_caseSensitive;
67             bool m_scoped;
68
69             struct SiteRule
70             {
71                 SiteRule() : anyValue(false) {}
72                 bool anyValue;
73                 vector<pair<value_type,const XMLCh*> > valueDenials;
74                 vector<pair<value_type,const XMLCh*> > valueAccepts;
75                 vector<pair<value_type,const XMLCh*> > scopeDenials;
76                 vector<pair<value_type,const XMLCh*> > scopeAccepts;
77             };
78             
79             value_type toValueType(const DOMElement* e);
80             bool scopeCheck(
81                 const DOMElement* e,
82                 const IScopedRoleDescriptor* role,
83                 const vector<const SiteRule*>& ruleStack
84                 ) const;
85             bool accept(const DOMElement* e, const IScopedRoleDescriptor* role=NULL) const;
86             
87             SiteRule m_anySiteRule;
88     #ifdef HAVE_GOOD_STL
89             typedef map<xstring,SiteRule> sitemap_t;
90     #else
91             typedef map<string,SiteRule> sitemap_t;
92     #endif
93             sitemap_t m_siteMap;
94         };
95     
96         bool anyAttribute;
97         vector<const IAttributeRule*> m_attrs;
98         map<string,const IAttributeRule*> m_aliasMap;
99     #ifdef HAVE_GOOD_STL
100         typedef map<xstring,AttributeRule*> attrmap_t;
101     #else
102         typedef map<string,AttributeRule*> attrmap_t;
103     #endif
104         attrmap_t m_attrMap;
105     };
106
107     class XMLAAP : public IAAP, public ReloadableXMLFile
108     {
109     public:
110         XMLAAP(const DOMElement* e) : ReloadableXMLFile(e) {}
111         ~XMLAAP() {}
112         
113         bool anyAttribute() const {return static_cast<XMLAAPImpl*>(getImplementation())->anyAttribute;}
114         const IAttributeRule* lookup(const XMLCh* attrName, const XMLCh* attrNamespace=NULL) const;
115         const IAttributeRule* lookup(const char* alias) const;
116         Iterator<const IAttributeRule*> getAttributeRules() const;
117
118     protected:
119         virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const;
120         virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const;
121     };
122
123 }
124
125 IPlugIn* XMLAAPFactory(const DOMElement* e)
126 {
127     auto_ptr<XMLAAP> aap(new XMLAAP(e));
128     aap->getImplementation();
129     return aap.release();
130 }
131
132 ReloadableXMLFileImpl* XMLAAP::newImplementation(const DOMElement* e, bool first) const
133 {
134     return new XMLAAPImpl(e);
135 }
136
137 ReloadableXMLFileImpl* XMLAAP::newImplementation(const char* pathname, bool first) const
138 {
139     return new XMLAAPImpl(pathname);
140 }
141
142 void XMLAAPImpl::init()
143 {
144 #ifdef _DEBUG
145     saml::NDC ndc("init");
146 #endif
147     Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".AAP");
148
149     try
150     {
151         if (!saml::XML::isElementNamed(m_root,::XML::SHIB_NS,SHIB_L(AttributeAcceptancePolicy)))
152         {
153             log.error("Construction requires a valid AAP file: (shib:AttributeAcceptancePolicy as root element)");
154             throw MalformedException("Construction requires a valid AAP file: (shib:AttributeAcceptancePolicy as root element)");
155         }
156
157         // Check for AnyAttribute element.
158         DOMElement* anyAttr = saml::XML::getFirstChildElement(m_root,::XML::SHIB_NS,SHIB_L(AnyAttribute));
159         if (anyAttr) {
160             anyAttribute = true;
161             log.warn("<AnyAttribute> found, will short-circuit all attribute value and scope filtering");
162         }
163
164         // Loop over the AttributeRule elements.
165         DOMNodeList* nlist = m_root->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(AttributeRule));
166         for (XMLSize_t i=0; nlist && i<nlist->getLength(); i++)
167         {
168             AttributeRule* rule=new AttributeRule(static_cast<DOMElement*>(nlist->item(i)));
169 #ifdef HAVE_GOOD_STL
170             xstring key=rule->getName();
171             key=key + chBang + chBang + (rule->getNamespace() ? rule->getNamespace() : Constants::SHIB_ATTRIBUTE_NAMESPACE_URI);
172 #else
173             auto_ptr_char aname(rule->getName());
174             string key(aname.get());
175             key+="!!";
176             if (rule->getNamespace())
177             {
178                 auto_ptr_char ans(rule->getNamespace());
179                 key+=ans.get();
180             }
181             else
182                 key+="urn:mace:shibboleth:1.0:attributeNamespace:uri";
183 #endif
184             m_attrMap[key]=rule;
185             m_attrs.push_back(rule);
186             if (rule->getAlias()) {
187                 if (!strcmp(rule->getAlias(),"user"))
188                     m_aliasMap[rule->getAlias()]=rule;
189                 else
190                     log.error("<AttributeRule> cannot specify Alias of 'user', please use alternate value");
191             }
192         }
193     }
194     catch (SAMLException& e)
195     {
196         log.errorStream() << "Error while parsing AAP: " << e.what() << CategoryStream::ENDLINE;
197         this->~XMLAAPImpl();
198         throw;
199     }
200 #ifndef _DEBUG
201     catch (...)
202     {
203         log.error("Unexpected error while parsing AAP");
204         this->~XMLAAPImpl();
205         throw;
206     }
207 #endif
208 }
209
210 XMLAAPImpl::~XMLAAPImpl()
211 {
212     for (attrmap_t::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
213         delete i->second;
214 }
215
216 XMLAAPImpl::AttributeRule::AttributeRule(const DOMElement* e) :
217     m_alias(e->hasAttributeNS(NULL,SHIB_L(Alias)) ? e->getAttributeNS(NULL,SHIB_L(Alias)) : NULL),
218     m_header(e->hasAttributeNS(NULL,SHIB_L(Header)) ? e->getAttributeNS(NULL,SHIB_L(Header)) : NULL),
219     m_scoped(false)
220     
221 {
222     m_name=e->getAttributeNS(NULL,SHIB_L(Name));
223     m_namespace=e->getAttributeNS(NULL,SHIB_L(Namespace));
224     if (!m_namespace || !*m_namespace)
225         m_namespace=Constants::SHIB_ATTRIBUTE_NAMESPACE_URI;
226     
227     const XMLCh* caseSensitive=e->getAttributeNS(NULL,SHIB_L(CaseSensitive));
228     m_caseSensitive=(!caseSensitive || !*caseSensitive || *caseSensitive==chDigit_1 || *caseSensitive==chLatin_t);
229     
230     const XMLCh* scoped=e->getAttributeNS(NULL,SHIB_L(Scoped));
231     m_scoped=(scoped && (*scoped==chDigit_1 || *scoped==chLatin_t));
232     
233     // Check for an AnySite rule.
234     DOMElement* anysite = saml::XML::getFirstChildElement(e);
235     if (anysite && saml::XML::isElementNamed(static_cast<DOMElement*>(anysite),::XML::SHIB_NS,SHIB_L(AnySite)))
236     {
237         // Process Scope elements.
238         DOMNodeList* vlist = static_cast<DOMElement*>(anysite)->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Scope));
239         for (XMLSize_t i=0; vlist && i<vlist->getLength(); i++)
240         {
241             m_scoped=true;
242             DOMElement* se=static_cast<DOMElement*>(vlist->item(i));
243             DOMNode* valnode=se->getFirstChild();
244             if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE)
245             {
246                 const XMLCh* accept=se->getAttributeNS(NULL,SHIB_L(Accept));
247                 if (!accept || !*accept || *accept==chDigit_1 || *accept==chLatin_t)
248                     m_anySiteRule.scopeAccepts.push_back(pair<value_type,const XMLCh*>(toValueType(se),valnode->getNodeValue()));
249                 else
250                     m_anySiteRule.scopeDenials.push_back(pair<value_type,const XMLCh*>(toValueType(se),valnode->getNodeValue()));
251             }
252         }
253
254         // Check for an AnyValue rule.
255         vlist = static_cast<DOMElement*>(anysite)->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(AnyValue));
256         if (vlist && vlist->getLength())
257         {
258             m_anySiteRule.anyValue=true;
259         }
260         else
261         {
262             // Process each Value element.
263             vlist = static_cast<DOMElement*>(anysite)->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Value));
264             for (XMLSize_t j=0; vlist && j<vlist->getLength(); j++)
265             {
266                 DOMElement* ve=static_cast<DOMElement*>(vlist->item(j));
267                 DOMNode* valnode=ve->getFirstChild();
268                 if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE) {
269                     const XMLCh* accept=ve->getAttributeNS(NULL,SHIB_L(Accept));
270                     if (!accept || !*accept || *accept==chDigit_1 || *accept==chLatin_t)
271                         m_anySiteRule.valueAccepts.push_back(pair<value_type,const XMLCh*>(toValueType(ve),valnode->getNodeValue()));
272                     else
273                         m_anySiteRule.valueDenials.push_back(pair<value_type,const XMLCh*>(toValueType(ve),valnode->getNodeValue()));
274                 }
275             }
276         }
277     }
278
279     // Loop over the SiteRule elements.
280     DOMNodeList* slist = e->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(SiteRule));
281     for (XMLSize_t k=0; slist && k<slist->getLength(); k++)
282     {
283         const XMLCh* srulename=static_cast<DOMElement*>(slist->item(k))->getAttributeNS(NULL,SHIB_L(Name));
284 #ifdef HAVE_GOOD_STL
285         m_siteMap[srulename]=SiteRule();
286         SiteRule& srule=m_siteMap[srulename];
287 #else
288         auto_ptr_char srulename2(srulename);
289         m_siteMap[srulename2.get()]=SiteRule();
290         SiteRule& srule=m_siteMap[srulename2.get()];
291 #endif
292
293         // Process Scope elements.
294         DOMNodeList* vlist = static_cast<DOMElement*>(slist->item(k))->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Scope));
295         for (XMLSize_t i=0; vlist && i<vlist->getLength(); i++)
296         {
297             m_scoped=true;
298             DOMElement* se=static_cast<DOMElement*>(vlist->item(i));
299             DOMNode* valnode=se->getFirstChild();
300             if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE)
301             {
302                 const XMLCh* accept=se->getAttributeNS(NULL,SHIB_L(Accept));
303                 if (!accept || !*accept || *accept==chDigit_1 || *accept==chLatin_t)
304                     srule.scopeAccepts.push_back(pair<value_type,const XMLCh*>(toValueType(se),valnode->getNodeValue()));
305                 else
306                     srule.scopeDenials.push_back(pair<value_type,const XMLCh*>(toValueType(se),valnode->getNodeValue()));
307             }
308         }
309
310         // Check for an AnyValue rule.
311         vlist = static_cast<DOMElement*>(slist->item(k))->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(AnyValue));
312         if (vlist && vlist->getLength())
313         {
314             srule.anyValue=true;
315         }
316         else
317         {
318             // Process each Value element.
319             vlist = static_cast<DOMElement*>(slist->item(k))->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Value));
320             for (XMLSize_t j=0; vlist && j<vlist->getLength(); j++)
321             {
322                 DOMElement* ve=static_cast<DOMElement*>(vlist->item(j));
323                 DOMNode* valnode=ve->getFirstChild();
324                 if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE) {
325                     const XMLCh* accept=ve->getAttributeNS(NULL,SHIB_L(Accept));
326                     if (!accept || !*accept || *accept==chDigit_1 || *accept==chLatin_t)
327                         srule.valueAccepts.push_back(pair<value_type,const XMLCh*>(toValueType(ve),valnode->getNodeValue()));
328                     else
329                         srule.valueDenials.push_back(pair<value_type,const XMLCh*>(toValueType(ve),valnode->getNodeValue()));
330                 }
331             }
332         }
333     }
334 }
335
336 XMLAAPImpl::AttributeRule::value_type XMLAAPImpl::AttributeRule::toValueType(const DOMElement* e)
337 {
338     if (!XMLString::compareString(SHIB_L(literal),e->getAttributeNS(NULL,SHIB_L(Type))))
339         return literal;
340     else if (!XMLString::compareString(SHIB_L(regexp),e->getAttributeNS(NULL,SHIB_L(Type))))
341         return regexp;
342     else if (!XMLString::compareString(SHIB_L(xpath),e->getAttributeNS(NULL,SHIB_L(Type))))
343         return xpath;
344     throw MalformedException("Found an invalid value or scope rule type.");
345 }
346
347 const IAttributeRule* XMLAAP::lookup(const XMLCh* attrName, const XMLCh* attrNamespace) const
348 {
349 #ifdef HAVE_GOOD_STL
350     xstring key=attrName;
351     key=key + chBang + chBang + (attrNamespace ? attrNamespace : Constants::SHIB_ATTRIBUTE_NAMESPACE_URI);
352 #else
353     auto_ptr_char aname(attrName);
354     string key=aname.get();
355     key+="!!";
356     if (attrNamespace)
357     {
358         auto_ptr_char ans(attrNamespace);
359         key+=ans.get();
360     }
361     else
362         key+="urn:mace:shibboleth:1.0:attributeNamespace:uri";
363 #endif
364     XMLAAPImpl* impl=dynamic_cast<XMLAAPImpl*>(getImplementation());
365     XMLAAPImpl::attrmap_t::const_iterator i=impl->m_attrMap.find(key);
366     return (i==impl->m_attrMap.end()) ? NULL : i->second;
367 }
368
369 const IAttributeRule* XMLAAP::lookup(const char* alias) const
370 {
371     XMLAAPImpl* impl=dynamic_cast<XMLAAPImpl*>(getImplementation());
372     map<string,const IAttributeRule*>::const_iterator i=impl->m_aliasMap.find(alias);
373     return (i==impl->m_aliasMap.end()) ? NULL : i->second;
374 }
375
376 Iterator<const IAttributeRule*> XMLAAP::getAttributeRules() const
377 {
378     return dynamic_cast<XMLAAPImpl*>(getImplementation())->m_attrs;
379 }
380
381 namespace {
382     bool match(const XMLCh* exp, const XMLCh* test)
383     {
384         try
385         {
386             RegularExpression re(exp);
387             if (re.matches(test))
388                 return true;
389         }
390         catch (XMLException& ex)
391         {
392             auto_ptr<char> tmp(XMLString::transcode(ex.getMessage()));
393             Category::getInstance(XMLPROVIDERS_LOGCAT".XMLAAPImpl").errorStream()
394                 << "caught exception while parsing regular expression: " << tmp.get() << CategoryStream::ENDLINE;
395         }
396         return false;
397     }
398 }
399
400 bool XMLAAPImpl::AttributeRule::scopeCheck(
401     const DOMElement* e,
402     const IScopedRoleDescriptor* role,
403     const vector<const SiteRule*>& ruleStack
404     ) const
405 {
406 #ifdef _DEBUG
407     saml::NDC ndc("scopeCheck");
408 #endif
409     Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".AAP");
410
411     // Are we scoped?
412     const XMLCh* scope=e->getAttributeNS(NULL,SHIB_L(Scope));
413     if (!scope || !*scope) {
414         // Are we allowed to be unscoped?
415         if (m_scoped && log.isWarnEnabled()) {
416                 auto_ptr_char temp(m_name);
417                 log.warn("attribute (%s) is scoped, no scope supplied, rejecting it",temp.get());
418         }
419         return !m_scoped;
420     }
421
422     // With the new algorithm, we evaluate each matching rule in sequence, separately.
423     for (vector<const SiteRule*>::const_iterator rule=ruleStack.begin(); rule!=ruleStack.end(); rule++) {
424
425         // Now run any denials.
426         vector<pair<value_type,const XMLCh*> >::const_iterator i;
427         for (i=(*rule)->scopeDenials.begin(); i!=(*rule)->scopeDenials.end(); i++) {
428             if ((i->first==literal && !XMLString::compareString(i->second,scope)) ||
429                 (i->first==regexp && match(i->second,scope))) {
430                 if (log.isWarnEnabled()) {
431                     auto_ptr_char temp(m_name);
432                     auto_ptr_char temp2(scope);
433                     log.warn("attribute (%s) scope (%s) denied by site rule, rejecting it",temp.get(),temp2.get());
434                 }
435                 return false;
436             }
437             else if (i->first==xpath)
438                 log.warn("scope checking does not permit XPath rules");
439         }
440
441         // Now run any accepts.
442         for (i=(*rule)->scopeAccepts.begin(); i!=(*rule)->scopeAccepts.end(); i++) {
443             if ((i->first==literal && !XMLString::compareString(i->second,scope)) ||
444                 (i->first==regexp && match(i->second,scope))) {
445                 log.debug("matching site rule, scope match");
446                 return true;
447             }
448             else if (i->first==xpath)
449                 log.warn("scope checking does not permit XPath rules");
450         }
451     }
452
453     // If we still can't decide, defer to metadata.
454     if (role) {
455         Iterator<pair<const XMLCh*,bool> > domains=role->getScopes();
456         while (domains.hasNext()) {
457             const pair<const XMLCh*,bool>& p=domains.next();
458             if ((p.second && match(p.first,scope)) || !XMLString::compareString(p.first,scope)) {
459                 log.debug("scope match via site metadata");
460                 return true;
461             }
462         }
463     }
464     
465     if (log.isWarnEnabled()) {
466         auto_ptr_char temp(m_name);
467         auto_ptr_char temp2(scope);
468         log.warn("attribute (%s) scope (%s) not accepted",temp.get(),temp2.get());
469     }
470     return false;
471 }
472
473 bool XMLAAPImpl::AttributeRule::accept(const DOMElement* e, const IScopedRoleDescriptor* role) const
474 {
475 #ifdef _DEBUG
476     saml::NDC ndc("accept");
477 #endif
478     Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".AAP");
479     
480     if (log.isDebugEnabled()) {
481         auto_ptr_char temp(m_name);
482         auto_ptr_char temp2(role ? role->getEntityDescriptor()->getId() : NULL);
483         log.debug("evaluating value for attribute (%s) from site (%s)",temp.get(),temp2.get() ? temp2.get() : "<unspecified>");
484     }
485     
486     // This is a complete revamp. The "any" cases become a degenerate case, the "least-specific" matching rule.
487     // The first step is to build a list of matching rules, most-specific to least-specific.
488     
489     vector<const SiteRule*> ruleStack;
490     if (role) {
491         // Primary match is against entityID.
492 #ifdef HAVE_GOOD_STL
493         const XMLCh* os=role->getEntityDescriptor()->getId();
494 #else
495         auto_ptr_char pos(role->getEntityDescriptor()->getId());
496         const char* os=pos.get();
497 #endif
498         sitemap_t::const_iterator srule=m_siteMap.find(os);
499         if (srule!=m_siteMap.end())
500             ruleStack.push_back(&srule->second);
501         
502         // Secondary matches are on groups.
503         const IEntitiesDescriptor* group=role->getEntityDescriptor()->getEntitiesDescriptor();
504         while (group) {
505             if (group->getName()) {
506 #ifdef HAVE_GOOD_STL
507                 os=group->getName();
508 #else
509                 auto_ptr_char gname(group->getName());
510                 const char* os=gname.get();
511 #endif
512                 srule=m_siteMap.find(os);
513                 if (srule!=m_siteMap.end())
514                     ruleStack.push_back(&srule->second);
515             }
516             group = group->getEntitiesDescriptor();
517         }
518     }
519     // Tertiary match is the AnySite rule.
520     ruleStack.push_back(&m_anySiteRule);
521
522     // Still don't support complex content models...
523     DOMNode* n=e->getFirstChild();
524     bool bSimple=(n && n->getNodeType()==DOMNode::TEXT_NODE);
525
526     // With the new algorithm, we evaluate each matching rule in sequence, separately.
527     for (vector<const SiteRule*>::const_iterator rule=ruleStack.begin(); rule!=ruleStack.end(); rule++) {
528
529         // Check for shortcut AnyValue blanket rule.
530         if ((*rule)->anyValue) {
531             log.debug("matching site rule, any value match");
532             return scopeCheck(e,role,ruleStack);
533         }
534
535         // Now run any denials.
536         vector<pair<value_type,const XMLCh*> >::const_iterator i;
537         for (i=(*rule)->valueDenials.begin(); bSimple && i!=(*rule)->valueDenials.end(); i++) {
538             switch (i->first) {
539                 case literal:
540                     if ((m_caseSensitive && !XMLString::compareString(i->second,n->getNodeValue())) ||
541                         (!m_caseSensitive && !XMLString::compareIString(i->second,n->getNodeValue()))) {
542                         if (log.isWarnEnabled()) {
543                             auto_ptr_char temp(m_name);
544                             log.warn("attribute (%s) value explicitly denied by site rule, rejecting it",temp.get());
545                         }
546                         return false;
547                     }
548                     break;
549                 
550                 case regexp:
551                     if (match(i->second,n->getNodeValue())) {
552                         if (log.isWarnEnabled()) {
553                             auto_ptr_char temp(m_name);
554                             log.warn("attribute (%s) value explicitly denied by site rule, rejecting it",temp.get());
555                         }
556                         return false;
557                     }
558                     break;
559                 
560                 case xpath:
561                     log.warn("implementation does not support XPath value rules");
562                     break;
563             }
564         }
565
566         // Now run any accepts.
567         for (i=(*rule)->valueAccepts.begin(); bSimple && i!=(*rule)->valueAccepts.end(); i++) {
568             switch (i->first) {
569                 case literal:
570                     if ((m_caseSensitive && !XMLString::compareString(i->second,n->getNodeValue())) ||
571                         (!m_caseSensitive && !XMLString::compareIString(i->second,n->getNodeValue()))) {
572                         log.debug("site rule, value match");
573                         return scopeCheck(e,role,ruleStack);
574                     }
575                     break;
576                 
577                 case regexp:
578                     if (match(i->second,n->getNodeValue())) {
579                         log.debug("site rule, value match");
580                         return scopeCheck(e,role,ruleStack);
581                     }
582                     break;
583                 
584                 case xpath:
585                     log.warn("implementation does not support XPath value rules");
586                     break;
587             }
588         }
589     }
590
591     if (log.isWarnEnabled()) {
592         auto_ptr_char temp(m_name);
593         auto_ptr_char temp2(n->getNodeValue());
594         log.warn("%sattribute (%s) value (%s) could not be validated by policy, rejecting it",
595                  (bSimple ? "" : "complex "),temp.get(),temp2.get());
596     }
597     return false;
598 }
599
600 void XMLAAPImpl::AttributeRule::apply(SAMLAttribute& attribute, const IRoleDescriptor* role) const
601 {
602     // Check each value.
603     DOMNodeList* vals=attribute.getValueElements();
604     int i2=0;
605     for (XMLSize_t i=0; vals && i < vals->getLength(); i++) {
606         if (!accept(static_cast<DOMElement*>(vals->item(i)),role ? dynamic_cast<const IScopedRoleDescriptor*>(role) : NULL))
607             attribute.removeValue(i2);
608         else
609             i2++;
610     }
611     
612     // Now see if we trashed it irrevocably.
613     attribute.checkValidity();
614 }