Improve property inheritance, first batch of SessionInitiators, rename providerId.
[shibboleth/sp.git] / util / samlquery.cpp
index 1d1bd74..08986a9 100644 (file)
@@ -35,6 +35,8 @@
 #include <shibsp/exceptions.h>\r
 #include <shibsp/SPConfig.h>\r
 #include <shibsp/ServiceProvider.h>\r
+#include <shibsp/attribute/resolver/AttributeResolver.h>\r
+#include <shibsp/binding/SOAPClient.h>\r
 #include <shibsp/util/SPConstants.h>\r
 \r
 #include <saml/binding/SecurityPolicy.h>\r
@@ -96,14 +98,14 @@ int main(int argc,char* argv[])
     if (!a_param)\r
         a_param="default";\r
 \r
+    XMLToolingConfig::getConfig().log_config(getenv("SHIBSP_LOGGING") ? getenv("SHIBSP_LOGGING") : SHIBSP_LOGGING);\r
+\r
     SPConfig& conf=SPConfig::getConfig();\r
     conf.setFeatures(\r
         SPConfig::Metadata |\r
         SPConfig::Trust |\r
         SPConfig::Credentials |\r
-        SPConfig::AttributeResolver |\r
-        SPConfig::OutOfProcess |\r
-        SPConfig::Caching\r
+        SPConfig::OutOfProcess\r
         );\r
     if (!conf.init(path))\r
         return -10;\r
@@ -127,7 +129,7 @@ int main(int argc,char* argv[])
     }\r
 \r
     ServiceProvider* sp=conf.getServiceProvider();\r
-    xmltooling::Locker locker(sp);\r
+    sp->lock();\r
 \r
     try {\r
         const Application* app=sp->getApplication(a_param);\r
@@ -137,7 +139,7 @@ int main(int argc,char* argv[])
         auto_ptr_XMLCh domain(q_param);\r
         auto_ptr_XMLCh name(n_param);\r
         auto_ptr_XMLCh format(f_param);\r
-        auto_ptr_XMLCh issuer(app->getString("providerId").second);\r
+        auto_ptr_XMLCh issuer(app->getString("entityID").second);\r
 \r
         MetadataProvider* m=app->getMetadataProvider();\r
         xmltooling::Locker mlocker(m);\r
@@ -157,12 +159,12 @@ int main(int argc,char* argv[])
         else\r
             throw MetadataException("No AttributeAuthority role found in metadata.");\r
 \r
-        QName role(samlconstants::SAML20P_NS, AttributeAuthorityDescriptor::LOCAL_NAME);\r
-        SecurityPolicy policy(sp->getPolicyRules(), m, &role, app->getTrustEngine());\r
+        shibsp::SecurityPolicy policy(*app);\r
+        shibsp::SOAPClient soaper(policy);\r
+        MetadataCredentialCriteria mcc(*AA);\r
 \r
         if (ver == v20) {\r
             auto_ptr_XMLCh binding(samlconstants::SAML20_BINDING_SOAP);\r
-            SAML2SOAPClient soaper(policy,true);\r
             opensaml::saml2p::StatusResponseType* srt=NULL;\r
             const vector<AttributeService*>& endpoints=AA->getAttributeServices();\r
             for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !srt && ep!=endpoints.end(); ++ep) {\r
@@ -171,23 +173,22 @@ int main(int argc,char* argv[])
                         continue;\r
                     auto_ptr_char loc((*ep)->getLocation());\r
                     NameID* nameid = NameIDBuilder::buildNameID();\r
-                    Issuer* iss = IssuerBuilder::buildIssuer();\r
                     opensaml::saml2::Subject* subject = opensaml::saml2::SubjectBuilder::buildSubject();\r
+                    subject->setNameID(nameid);\r
                     opensaml::saml2p::AttributeQuery* query = opensaml::saml2p::AttributeQueryBuilder::buildAttributeQuery();\r
+                    query->setSubject(subject);\r
+                    Issuer* iss = IssuerBuilder::buildIssuer();\r
+                    query->setIssuer(iss);\r
                     nameid->setName(name.get());\r
                     nameid->setFormat(format.get() ? format.get() : NameID::TRANSIENT);\r
                     nameid->setNameQualifier(domain.get());\r
                     iss->setName(issuer.get());\r
-                    subject->setNameID(nameid);\r
-                    query->setSubject(subject);\r
-                    query->setIssuer(iss);\r
-                    auto_ptr<opensaml::saml2p::AttributeQuery> wrapper(query);\r
-                    soaper.sendSAML(query, *AA, loc.get());\r
-                    wrapper.release();  // freed by SOAP client\r
-                    srt = soaper.receiveSAML();\r
+                    SAML2SOAPClient client(soaper);\r
+                    client.sendSAML(query, mcc, loc.get());\r
+                    srt = client.receiveSAML();\r
                 }\r
                 catch (exception& ex) {\r
-                    cerr << ex.what() << endl;\r
+                    cerr << "Caught exception: " << ex.what() << endl << endl;\r
                     soaper.reset();\r
                 }\r
             }\r
@@ -206,7 +207,6 @@ int main(int argc,char* argv[])
         }\r
         else {\r
             auto_ptr_XMLCh binding(samlconstants::SAML1_BINDING_SOAP);\r
-            SAML1SOAPClient soaper(policy,true);\r
             const opensaml::saml1p::Response* response=NULL;\r
             const vector<AttributeService*>& endpoints=AA->getAttributeServices();\r
             for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !response && ep!=endpoints.end(); ++ep) {\r
@@ -216,22 +216,22 @@ int main(int argc,char* argv[])
                     auto_ptr_char loc((*ep)->getLocation());\r
                     NameIdentifier* nameid = NameIdentifierBuilder::buildNameIdentifier();\r
                     opensaml::saml1::Subject* subject = opensaml::saml1::SubjectBuilder::buildSubject();\r
+                    subject->setNameIdentifier(nameid);\r
                     opensaml::saml1p::AttributeQuery* query = opensaml::saml1p::AttributeQueryBuilder::buildAttributeQuery();\r
+                    query->setSubject(subject);\r
                     Request* request = RequestBuilder::buildRequest();\r
+                    request->setAttributeQuery(query);\r
                     nameid->setName(name.get());\r
                     nameid->setFormat(format.get() ? format.get() : shibspconstants::SHIB1_NAMEID_FORMAT_URI);\r
                     nameid->setNameQualifier(domain.get());\r
-                    subject->setNameIdentifier(nameid);\r
-                    query->setSubject(subject);\r
                     query->setResource(issuer.get());\r
                     request->setMinorVersion(ver==v11 ? 1 : 0);\r
-                    auto_ptr<Request> wrapper(request);\r
-                    soaper.sendSAML(request, *AA, loc.get());\r
-                    wrapper.release();  // freed by SOAP client\r
-                    response = soaper.receiveSAML();\r
+                    SAML1SOAPClient client(soaper);\r
+                    client.sendSAML(request, mcc, loc.get());\r
+                    response = client.receiveSAML();\r
                 }\r
                 catch (exception& ex) {\r
-                    cerr << ex.what() << endl;\r
+                    cerr << "Caught exception: " << ex.what() << endl << endl;\r
                     soaper.reset();\r
                 }\r
             }\r
@@ -252,6 +252,7 @@ int main(int argc,char* argv[])
         cerr << ex.what() << endl;\r
     }\r
 \r
+    sp->unlock();\r
     conf.term();\r
     return 0;\r
 }\r