Add role query options.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Thu, 6 Sep 2007 15:48:26 +0000 (15:48 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Thu, 6 Sep 2007 15:48:26 +0000 (15:48 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2451 cb58f699-b61c-0410-a6fe-9272a202ed29

util/mdquery.cpp

index 4440f8f..b11aa1d 100644 (file)
@@ -46,24 +46,54 @@ using namespace xmltooling::logging;
 using namespace xmltooling;\r
 using namespace std;\r
 \r
+void usage()\r
+{\r
+    cerr << "usage: mdquery -e <entityID> [-a <app id> -nostrict]" << endl;\r
+    cerr << "       mdquery -e <entityID> -r <role> -p <protocol> [-a <app id> -ns <namespace> -nostrict]" << endl;\r
+}\r
+\r
 int main(int argc,char* argv[])\r
 {\r
     char* entityID = NULL;\r
     char* appID = "default";\r
     bool strict = true;\r
+    char* prot = NULL;\r
+    const XMLCh* protocol = NULL;\r
+    char* rname = NULL;\r
+    char* rns = NULL;\r
 \r
     for (int i=1; i<argc; i++) {\r
         if (!strcmp(argv[i],"-e") && i+1<argc)\r
             entityID=argv[++i];\r
         else if (!strcmp(argv[i],"-a") && i+1<argc)\r
             appID=argv[++i];\r
-        else if (!strcmp(argv[i],"--nostrict"))\r
+        else if (!strcmp(argv[i],"-p") && i+1<argc)\r
+            prot=argv[++i];\r
+        else if (!strcmp(argv[i],"-r") && i+1<argc)\r
+            rname=argv[++i];\r
+        else if (!strcmp(argv[i],"-ns") && i+1<argc)\r
+            rns=argv[++i];\r
+        else if (!strcmp(argv[i],"-saml10"))\r
+            protocol=samlconstants::SAML10_PROTOCOL_ENUM;\r
+        else if (!strcmp(argv[i],"-saml11"))\r
+            protocol=samlconstants::SAML11_PROTOCOL_ENUM;\r
+        else if (!strcmp(argv[i],"-saml2"))\r
+            protocol=samlconstants::SAML20P_NS;\r
+        else if (!strcmp(argv[i],"-idp"))\r
+            rname="IDPSSODescriptor";\r
+        else if (!strcmp(argv[i],"-aa"))\r
+            rname="AttributeAuthorityDescriptor";\r
+        else if (!strcmp(argv[i],"-pdp"))\r
+            rname="PDPDescriptor";\r
+        else if (!strcmp(argv[i],"-sp"))\r
+            rname="SPSSODescriptor";\r
+        else if (!strcmp(argv[i],"-nostrict"))\r
             strict = false;\r
     }\r
 \r
     if (!entityID) {\r
-        cerr << "usage: mdquery -e <entityID> [-a <application id> --nostrict]" << endl;\r
-        exit(0);\r
+        usage();\r
+        exit(-10);\r
     }\r
 \r
     char* path=getenv("SHIBSP_SCHEMAS");\r
@@ -80,6 +110,18 @@ int main(int argc,char* argv[])
     if (!conf.init(path))\r
         return -1;\r
 \r
+    if (rname) {\r
+        if (!protocol) {\r
+            if (prot)\r
+                protocol = XMLString::transcode(prot);\r
+        }\r
+        if (!protocol) {\r
+            conf.term();\r
+            usage();\r
+            exit(-10);\r
+        }\r
+    }\r
+\r
     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
@@ -113,7 +155,21 @@ int main(int argc,char* argv[])
     app->getMetadataProvider()->lock();\r
     const EntityDescriptor* entity = app->getMetadataProvider()->getEntityDescriptor(entityID, strict);\r
     if (entity) {\r
-        XMLHelper::serialize(entity->marshall(), cout, true);\r
+        if (rname) {\r
+            const XMLCh* ns = rns ? XMLString::transcode(rns) : samlconstants::SAML20MD_NS;\r
+            auto_ptr_XMLCh n(rname);\r
+            QName q(ns, n.get());\r
+            const RoleDescriptor* role = entity->getRoleDescriptor(q, protocol);\r
+            if (role) {\r
+                XMLHelper::serialize(role->marshall(), cout, true);\r
+            }\r
+            else {\r
+                log.error("compatible role %s not found for (%s)", q.toString().c_str(), entityID);\r
+            }\r
+        }\r
+        else {\r
+            XMLHelper::serialize(entity->marshall(), cout, true);\r
+        }\r
     }\r
     else {\r
         log.error("no metadata found for (%s)", entityID);\r