Skip extra attempts when SAML response comes back.
[shibboleth/sp.git] / util / samlquery.cpp
index 08986a9..e00c546 100644 (file)
@@ -113,9 +113,9 @@ int main(int argc,char* argv[])
     try {\r
         static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);\r
         static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e);\r
-        DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument();\r
-        XercesJanitor<DOMDocument> docjanitor(dummydoc);\r
-        DOMElement* dummy = dummydoc->createElementNS(NULL,path);\r
+        xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument();\r
+        XercesJanitor<xercesc::DOMDocument> docjanitor(dummydoc);\r
+        xercesc::DOMElement* dummy = dummydoc->createElementNS(NULL,path);\r
         auto_ptr_XMLCh src(config);\r
         dummy->setAttributeNS(NULL,path,src.get());\r
         dummy->setAttributeNS(NULL,validate,xmlconstants::XML_ONE);\r
@@ -183,7 +183,7 @@ int main(int argc,char* argv[])
                     nameid->setFormat(format.get() ? format.get() : NameID::TRANSIENT);\r
                     nameid->setNameQualifier(domain.get());\r
                     iss->setName(issuer.get());\r
-                    SAML2SOAPClient client(soaper);\r
+                    SAML2SOAPClient client(soaper, false);\r
                     client.sendSAML(query, mcc, loc.get());\r
                     srt = client.receiveSAML();\r
                 }\r
@@ -194,7 +194,11 @@ int main(int argc,char* argv[])
             }\r
 \r
             if (!srt)\r
-                throw BindingException("Unable to successfully query for attributes.");\r
+                throw BindingException("Unable to obtain a SAML response from attribute authority.");\r
+            else if (!XMLString::equals(srt->getStatus()->getStatusCode()->getValue(), saml2p::StatusCode::SUCCESS)) {\r
+                delete srt;\r
+                throw BindingException("Attribute authority returned a SAML error.");\r
+            }\r
             const opensaml::saml2p::Response* response = dynamic_cast<opensaml::saml2p::Response*>(srt);\r
 \r
             const vector<opensaml::saml2::Assertion*>& assertions = response->getAssertions();\r
@@ -226,7 +230,7 @@ int main(int argc,char* argv[])
                     nameid->setNameQualifier(domain.get());\r
                     query->setResource(issuer.get());\r
                     request->setMinorVersion(ver==v11 ? 1 : 0);\r
-                    SAML1SOAPClient client(soaper);\r
+                    SAML1SOAPClient client(soaper, false);\r
                     client.sendSAML(request, mcc, loc.get());\r
                     response = client.receiveSAML();\r
                 }\r
@@ -237,7 +241,11 @@ int main(int argc,char* argv[])
             }\r
 \r
             if (!response)\r
-                throw BindingException("Unable to successfully query for attributes.");\r
+                throw BindingException("Unable to obtain a SAML response from attribute authority.");\r
+            else if (*(response->getStatus()->getStatusCode()->getValue()) != saml1p::StatusCode::SUCCESS) {\r
+                delete const_cast<opensaml::saml1p::Response*>(response);\r
+                throw BindingException("Attribute authority returned a SAML error.");\r
+            }\r
 \r
             const vector<opensaml::saml1::Assertion*>& assertions = response->getAssertions();\r
             if (assertions.size())\r