Auto-wrap chained Application plugins, relax order child elements, add some logging.
[shibboleth/sp.git] / shibsp / attribute / resolver / impl / ChainingAttributeResolver.cpp
index c1b3805..fa268cf 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *  Copyright 2001-2007 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.
  * You may obtain a copy of the License at
@@ -16,7 +16,7 @@
 
 /**
  * ChainingAttributeResolver.cpp
- * 
+ *
  * Chains together multiple AttributeResolver plugins.
  */
 
@@ -27,6 +27,7 @@
 #include "attribute/resolver/AttributeResolver.h"
 #include "attribute/resolver/ResolutionContext.h"
 
+#include <saml/Assertion.h>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xmltooling/util/XMLHelper.h>
 
@@ -49,7 +50,7 @@ namespace shibsp {
             const XMLCh* authncontext_decl,
             const vector<const opensaml::Assertion*>* tokens,
             const vector<shibsp::Attribute*>* attributes
-            ) : m_app(application), m_issuer(issuer), m_protocol(protocol), m_nameid(nameid), m_authclass(authncontext_class), m_authdecl(authncontext_decl), m_session(NULL) {
+            ) : m_app(application), m_issuer(issuer), m_protocol(protocol), m_nameid(nameid), m_authclass(authncontext_class), m_authdecl(authncontext_decl), m_session(nullptr) {
             if (tokens)
                 m_tokens.assign(tokens->begin(), tokens->end());
             if (attributes)
@@ -93,7 +94,7 @@ namespace shibsp {
         virtual ~ChainingAttributeResolver() {
             for_each(m_resolvers.begin(), m_resolvers.end(), xmltooling::cleanup<AttributeResolver>());
         }
-        
+
         Lockable* lock() {
             return this;
         }
@@ -104,11 +105,11 @@ namespace shibsp {
             const Application& application,
             const EntityDescriptor* issuer,
             const XMLCh* protocol,
-            const NameID* nameid=NULL,
-            const XMLCh* authncontext_class=NULL,
-            const XMLCh* authncontext_decl=NULL,
-            const vector<const opensaml::Assertion*>* tokens=NULL,
-            const vector<shibsp::Attribute*>* attributes=NULL
+            const NameID* nameid=nullptr,
+            const XMLCh* authncontext_class=nullptr,
+            const XMLCh* authncontext_decl=nullptr,
+            const vector<const opensaml::Assertion*>* tokens=nullptr,
+            const vector<shibsp::Attribute*>* attributes=nullptr
             ) const {
             return new ChainingContext(application, issuer, protocol, nameid, authncontext_class, authncontext_decl, tokens, attributes);
         }
@@ -125,7 +126,7 @@ namespace shibsp {
                 (*i)->getAttributeIds(attributes);
             }
         }
-        
+
     private:
         vector<AttributeResolver*> m_resolvers;
     };
@@ -134,6 +135,8 @@ namespace shibsp {
     static const XMLCh _type[] =                UNICODE_LITERAL_4(t,y,p,e);
 
     SHIBSP_DLLLOCAL PluginManager<AttributeResolver,string,const DOMElement*>::Factory QueryResolverFactory;
+    SHIBSP_DLLLOCAL PluginManager<AttributeResolver,string,const DOMElement*>::Factory SimpleAggregationResolverFactory;
+
     AttributeResolver* SHIBSP_DLLLOCAL ChainingResolverFactory(const DOMElement* const & e)
     {
         return new ChainingAttributeResolver(e);
@@ -143,23 +146,43 @@ namespace shibsp {
 void SHIBSP_API shibsp::registerAttributeResolvers()
 {
     SPConfig::getConfig().AttributeResolverManager.registerFactory(QUERY_ATTRIBUTE_RESOLVER, QueryResolverFactory);
+    SPConfig::getConfig().AttributeResolverManager.registerFactory(SIMPLEAGGREGATION_ATTRIBUTE_RESOLVER, SimpleAggregationResolverFactory);
     SPConfig::getConfig().AttributeResolverManager.registerFactory(CHAINING_ATTRIBUTE_RESOLVER, ChainingResolverFactory);
 }
 
+ResolutionContext::ResolutionContext()
+{
+}
+
+ResolutionContext::~ResolutionContext()
+{
+}
+
+AttributeResolver::AttributeResolver()
+{
+}
+
+AttributeResolver::~AttributeResolver()
+{
+}
+
 ChainingAttributeResolver::ChainingAttributeResolver(const DOMElement* e)
 {
     SPConfig& conf = SPConfig::getConfig();
 
     // Load up the chain of handlers.
-    e = e ? XMLHelper::getFirstChildElement(e, _AttributeResolver) : NULL;
+    e = XMLHelper::getFirstChildElement(e, _AttributeResolver);
     while (e) {
-        auto_ptr_char type(e->getAttributeNS(NULL,_type));
-        if (type.get() && *(type.get())) {
+        string t(XMLHelper::getAttrString(e, nullptr, _type));
+        if (!t.empty()) {
             try {
-                m_resolvers.push_back(conf.AttributeResolverManager.newPlugin(type.get(),e));
+                Category::getInstance(SHIBSP_LOGCAT".AttributeResolver.Chaining").info(
+                    "building AttributeResolver of type (%s)...", t.c_str()
+                    );
+                m_resolvers.push_back(conf.AttributeResolverManager.newPlugin(t.c_str(), e));
             }
             catch (exception& ex) {
-                Category::getInstance(SHIBSP_LOGCAT".AttributeResolver").error(
+                Category::getInstance(SHIBSP_LOGCAT".AttributeResolver.Chaining").error(
                     "caught exception processing embedded AttributeResolver element: %s", ex.what()
                     );
             }
@@ -184,7 +207,7 @@ void ChainingAttributeResolver::resolveAttributes(ResolutionContext& ctx) const
         (*i)->resolveAttributes(*context.get());
 
         chain.m_attributes.insert(chain.m_attributes.end(), context->getResolvedAttributes().begin(), context->getResolvedAttributes().end());
-        chain.m_ownedAttributes.insert(chain.m_attributes.end(), context->getResolvedAttributes().begin(), context->getResolvedAttributes().end());
+        chain.m_ownedAttributes.insert(chain.m_ownedAttributes.end(), context->getResolvedAttributes().begin(), context->getResolvedAttributes().end());
         context->getResolvedAttributes().clear();
 
         chain.m_tokens.insert(chain.m_tokens.end(), context->getResolvedAssertions().begin(), context->getResolvedAssertions().end());