Rework decoder handling in simple resolver, add IdP/SP names to decoder API, hook...
[shibboleth/sp.git] / shibsp / impl / XMLServiceProvider.cpp
index e6d9da8..209b504 100644 (file)
@@ -31,7 +31,7 @@
 #include "SPConfig.h"\r
 #include "SPRequest.h"\r
 #include "TransactionLog.h"\r
-#include "attribute/Attribute.h"\r
+#include "attribute/resolver/AttributeResolver.h"\r
 #include "remoting/ListenerService.h"\r
 #include "security/PKIXTrustEngine.h"\r
 #include "util/DOMPropertySet.h"\r
@@ -93,14 +93,23 @@ namespace {
         pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;\r
         pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;\r
         pair<bool,int> getInt(const char* name, const char* ns=NULL) const;\r
-        const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;\r
+        const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:sp:config:2.0") const;\r
 \r
         // Application\r
         const ServiceProvider& getServiceProvider() const {return *m_sp;}\r
         const char* getId() const {return getString("id").second;}\r
         const char* getHash() const {return m_hash.c_str();}\r
-        MetadataProvider* getMetadataProvider() const;\r
-        TrustEngine* getTrustEngine() const;\r
+\r
+        MetadataProvider* getMetadataProvider() const {\r
+            return (!m_metadata && m_base) ? m_base->getMetadataProvider() : m_metadata;\r
+        }\r
+        TrustEngine* getTrustEngine() const {\r
+            return (!m_trust && m_base) ? m_base->getTrustEngine() : m_trust;\r
+        }\r
+        AttributeResolver* getAttributeResolver() const {\r
+            return (!m_attrResolver && m_base) ? m_base->getAttributeResolver() : m_attrResolver;\r
+        }\r
+\r
         const PropertySet* getCredentialUse(const EntityDescriptor* provider) const;\r
 \r
         const Handler* getDefaultSessionInitiator() const;\r
@@ -110,13 +119,13 @@ namespace {
         const vector<const Handler*>& getAssertionConsumerServicesByBinding(const XMLCh* binding) const;\r
         const Handler* getHandler(const char* path) const;\r
 \r
-        const vector<const XMLCh*>& getAudiences() const;\r
+        const vector<const XMLCh*>& getAudiences() const {\r
+            return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;\r
+        }\r
         Validator* getTokenValidator(time_t ts=0, const opensaml::saml2md::RoleDescriptor* role=NULL) const {\r
             return new TokenValidator(*this, ts, role);\r
         }\r
 \r
-        void validator(const XMLObject* xmlObject) const;\r
-\r
         // Provides filter to exclude special config elements.\r
         short acceptNode(const DOMNode* node) const;\r
     \r
@@ -127,6 +136,7 @@ namespace {
         string m_hash;\r
         MetadataProvider* m_metadata;\r
         TrustEngine* m_trust;\r
+        AttributeResolver* m_attrResolver;\r
         vector<const XMLCh*> m_audiences;\r
 \r
         // manage handler objects\r
@@ -299,6 +309,7 @@ namespace {
 \r
     static const XMLCh _Application[] =         UNICODE_LITERAL_11(A,p,p,l,i,c,a,t,i,o,n);\r
     static const XMLCh Applications[] =         UNICODE_LITERAL_12(A,p,p,l,i,c,a,t,i,o,n,s);\r
+    static const XMLCh _AttributeResolver[] =   UNICODE_LITERAL_17(A,t,t,r,i,b,u,t,e,R,e,s,o,l,v,e,r);\r
     static const XMLCh Credentials[] =          UNICODE_LITERAL_11(C,r,e,d,e,n,t,i,a,l,s);\r
     static const XMLCh CredentialUse[] =        UNICODE_LITERAL_13(C,r,e,d,e,n,t,i,a,l,U,s,e);\r
     static const XMLCh fatal[] =                UNICODE_LITERAL_5(f,a,t,a,l);\r
@@ -465,7 +476,7 @@ XMLApplication::XMLApplication(
     const ServiceProvider* sp,\r
     const DOMElement* e,\r
     const XMLApplication* base\r
-    ) : m_sp(sp), m_base(base), m_metadata(NULL), m_trust(NULL),\r
+    ) : m_sp(sp), m_base(base), m_metadata(NULL), m_trust(NULL), m_attrResolver(NULL),\r
         m_credDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL)\r
 {\r
 #ifdef _DEBUG\r
@@ -600,10 +611,6 @@ XMLApplication::XMLApplication(
         // Always include our own providerId as an audience.\r
         m_audiences.push_back(getXMLString("providerId").second);\r
 \r
-        if (conf.isEnabled(SPConfig::AttributeResolution)) {\r
-            // TODO\r
-        }\r
-\r
         if (conf.isEnabled(SPConfig::Metadata)) {\r
             child = XMLHelper::getFirstChildElement(e,_MetadataProvider);\r
             if (child) {\r
@@ -629,11 +636,25 @@ XMLApplication::XMLApplication(
                     m_trust = xmlConf.TrustEngineManager.newPlugin(type.get(),child);\r
                 }\r
                 catch (exception& ex) {\r
-                    log.crit("error building TrustEngine: %s",ex.what());\r
+                    log.crit("error building TrustEngine: %s", ex.what());\r
                 }\r
             }\r
         }\r
-        \r
+\r
+        if (conf.isEnabled(SPConfig::AttributeResolution)) {\r
+            child = XMLHelper::getFirstChildElement(e,_AttributeResolver);\r
+            if (child) {\r
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
+                log.info("building AttributeResolver of type %s...",type.get());\r
+                try {\r
+                    m_attrResolver = conf.AttributeResolverManager.newPlugin(type.get(),child);\r
+                }\r
+                catch (exception& ex) {\r
+                    log.crit("error building AttributeResolver: %s", ex.what());\r
+                }\r
+            }\r
+        }\r
+\r
         // Finally, load credential mappings.\r
         child = XMLHelper::getFirstChildElement(e,CredentialUse);\r
         if (child) {\r
@@ -676,6 +697,7 @@ void XMLApplication::cleanup()
     for_each(m_credMap.begin(),m_credMap.end(),cleanup_pair<const XMLCh*,PropertySet>());\r
 #endif\r
 \r
+    delete m_attrResolver;\r
     delete m_trust;\r
     delete m_metadata;\r
 }\r
@@ -695,7 +717,8 @@ short XMLApplication::acceptNode(const DOMNode* node) const
         XMLString::equals(name,CredentialUse) ||\r
         XMLString::equals(name,RelyingParty) ||\r
         XMLString::equals(name,_MetadataProvider) ||\r
-        XMLString::equals(name,_TrustEngine))\r
+        XMLString::equals(name,_TrustEngine) ||\r
+        XMLString::equals(name,_AttributeResolver))\r
         return FILTER_REJECT;\r
 \r
     return FILTER_ACCEPT;\r
@@ -749,21 +772,6 @@ const PropertySet* XMLApplication::getPropertySet(const char* name, const char*
     return m_base->getPropertySet(name,ns);\r
 }\r
 \r
-MetadataProvider* XMLApplication::getMetadataProvider() const\r
-{\r
-    return (!m_metadata && m_base) ? m_base->getMetadataProvider() : m_metadata;\r
-}\r
-\r
-TrustEngine* XMLApplication::getTrustEngine() const\r
-{\r
-    return (!m_trust && m_base) ? m_base->getTrustEngine() : m_trust;\r
-}\r
-\r
-const vector<const XMLCh*>& XMLApplication::getAudiences() const\r
-{\r
-    return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;\r
-}\r
-\r
 const PropertySet* XMLApplication::getCredentialUse(const EntityDescriptor* provider) const\r
 {\r
     if (!m_credDefault && m_base)\r