Imported Upstream version 2.4+dfsg
[shibboleth/sp.git] / shibsp / attribute / resolver / impl / DelegationAttributeExtractor.cpp
index d44311e..3f410cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2009 Internet2
+ *  Copyright 2009-2010 Internet2
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include "util/SPConstants.h"
 
 #include <saml/saml2/core/Assertions.h>
+#include <saml/saml2/metadata/Metadata.h>
 #include <saml/saml2/metadata/MetadataCredentialCriteria.h>
+#include <xmltooling/security/CredentialResolver.h>
+#include <xmltooling/util/DateTime.h>
 #include <xmltooling/util/XMLHelper.h>
 #include <xercesc/util/XMLUniDefs.hpp>
 
@@ -83,20 +86,10 @@ namespace shibsp {
     static const XMLCh formatter[] =    UNICODE_LITERAL_9(f,o,r,m,a,t,t,e,r);
 };
 
-DelegationExtractor::DelegationExtractor(const DOMElement* e) : m_attributeId("delegate"), m_formatter("$Name")
+DelegationExtractor::DelegationExtractor(const DOMElement* e)
+    : m_attributeId(XMLHelper::getAttrString(e, "delegate", attributeId)),
+        m_formatter(XMLHelper::getAttrString(e, "$Name", formatter))
 {
-    if (e) {
-        const XMLCh* a = e->getAttributeNS(NULL, attributeId);
-        if (a && *a) {
-            auto_ptr_char temp(a);
-            m_attributeId = temp.get();
-        }
-        a = e->getAttributeNS(NULL, formatter);
-        if (a && *a) {
-            auto_ptr_char temp(a);
-            m_formatter = temp.get();
-        }
-    }
 }
 
 void DelegationExtractor::extractAttributes(
@@ -122,7 +115,7 @@ void DelegationExtractor::extractAttributes(
                     continue;
                 }
 
-                saml2::NameID* n = NULL;
+                saml2::NameID* n = nullptr;
                 if ((*d)->getEncryptedID()) {
                     CredentialResolver* cr = application.getCredentialResolver();
                     if (!cr) {
@@ -131,7 +124,7 @@ void DelegationExtractor::extractAttributes(
 
                     try {
                         const XMLCh* recipient = application.getRelyingParty(
-                            issuer ? dynamic_cast<EntityDescriptor*>(issuer->getParent()) : NULL
+                            issuer ? dynamic_cast<EntityDescriptor*>(issuer->getParent()) : nullptr
                             )->getXMLString("entityID").second;
                         Locker credlocker(cr);
                         if (issuer) {
@@ -155,7 +148,7 @@ void DelegationExtractor::extractAttributes(
                 }
 
                 if (n) {
-                    DDF val = DDF(NULL).structure();
+                    DDF val = DDF(nullptr).structure();
                     if ((*d)->getConfirmationMethod()) {
                         auto_ptr_char temp((*d)->getConfirmationMethod());
                         val.addmember("ConfirmationMethod").string(temp.get());
@@ -165,29 +158,29 @@ void DelegationExtractor::extractAttributes(
                         val.addmember("DelegationInstant").string(temp.get());
                     }
 
-                    auto_arrayptr<char> name(toUTF8(n->getName()));\r
-                    if (name.get() && *name.get()) {\r
-                        val.addmember("Name").string(name.get());\r
-                        char* str = toUTF8(n->getFormat());\r
-                        if (str && *str)\r
-                            val.addmember("Format").string(str);\r
-                        delete[] str;\r
-\r
-                        str = toUTF8(n->getNameQualifier());\r
-                        if (str && *str)\r
-                            val.addmember("NameQualifier").string(str);\r
-                        delete[] str;\r
-\r
-                        str = toUTF8(n->getSPNameQualifier());\r
-                        if (str && *str)\r
-                            val.addmember("SPNameQualifier").string(str);\r
-                        delete[] str;\r
-\r
-                        str = toUTF8(n->getSPProvidedID());\r
-                        if (str && *str)\r
-                            val.addmember("SPProvidedID").string(str);\r
-                        delete[] str;\r
-                    }\r
+                    auto_arrayptr<char> name(toUTF8(n->getName()));
+                    if (name.get() && *name.get()) {
+                        val.addmember("Name").string(name.get());
+                        char* str = toUTF8(n->getFormat());
+                        if (str && *str)
+                            val.addmember("Format").string(str);
+                        delete[] str;
+
+                        str = toUTF8(n->getNameQualifier());
+                        if (str && *str)
+                            val.addmember("NameQualifier").string(str);
+                        delete[] str;
+
+                        str = toUTF8(n->getSPNameQualifier());
+                        if (str && *str)
+                            val.addmember("SPNameQualifier").string(str);
+                        delete[] str;
+
+                        str = toUTF8(n->getSPProvidedID());
+                        if (str && *str)
+                            val.addmember("SPProvidedID").string(str);
+                        delete[] str;
+                    }
 
                     if (n != (*d)->getNameID())
                         delete n;