CPPOST-15 - Adds APIs to support advanced metadata providers.
[shibboleth/cpp-sp.git] / shibsp / handler / impl / TransformSessionInitiator.cpp
index fa712d8..36759f3 100644 (file)
@@ -31,6 +31,7 @@
 #include "util/SPConstants.h"
 
 #ifndef SHIBSP_LITE
+# include "metadata/MetadataProviderCriteria.h"
 # include <saml/saml2/metadata/Metadata.h>
 #endif
 #include <xmltooling/XMLToolingConfig.h>
@@ -62,7 +63,6 @@ namespace shibsp {
     static SHIBSP_DLLLOCAL TransformSINodeFilter g_TSINFilter;
 
 #ifndef SHIBSP_LITE
-    static const XMLCh alwaysRun[] =    UNICODE_LITERAL_9(a,l,w,a,y,s,R,u,n);
     static const XMLCh force[] =        UNICODE_LITERAL_5(f,o,r,c,e);
     static const XMLCh match[] =        UNICODE_LITERAL_5(m,a,t,c,h);
     static const XMLCh Regex[] =        UNICODE_LITERAL_5(R,e,g,e,x);
@@ -99,6 +99,9 @@ namespace shibsp {
                             auto_ptr_char repl(e->getFirstChild()->getNodeValue());
                             m_regex.push_back(make_pair((*flag==chDigit_1 || *flag==chLatin_t), pair<string,string>(m.get(), repl.get())));
                         }
+                        else {
+                            m_log.warn("Unknown element found in Transform SessionInitiator configuration, check for errors.");
+                        }
                     }
                     e = XMLHelper::getNextSiblingElement(e);
                 }
@@ -203,7 +206,7 @@ void TransformSessionInitiator::doRequest(const Application& application, string
     MetadataProvider* m=application.getMetadataProvider();
     Locker locker(m);
 
-    MetadataProvider::Criteria mc(entityID.c_str(), &IDPSSODescriptor::ELEMENT_QNAME);
+    MetadataProviderCriteria mc(application, entityID.c_str(), &IDPSSODescriptor::ELEMENT_QNAME);
     pair<const EntityDescriptor*,const RoleDescriptor*> entity;
     if (!m_alwaysRun) {
         // First check the original value, it might be valid already.
@@ -248,6 +251,10 @@ void TransformSessionInitiator::doRequest(const Application& application, string
                 auto_ptr_char narrow(temp);
                 XMLString::release(&temp);
 
+                // For some reason it returns the match string if it doesn't match the expression.
+                if (entityID == narrow.get())
+                    continue;
+
                 if (r->first) {
                     m_log.info("forcibly transformed entityID from (%s) to (%s)", entityID.c_str(), narrow.get());
                     entityID = narrow.get();