2 * Copyright 2001-2009 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
20 * SAML Metadata Query tool layered on SP configuration
\r
23 #if defined (_MSC_VER) || defined(__BORLANDC__)
\r
24 # include "config_win32.h"
\r
26 # include "config.h"
\r
30 # define _CRT_NONSTDC_NO_DEPRECATE 1
\r
31 # define _CRT_SECURE_NO_DEPRECATE 1
\r
34 #include <shibsp/Application.h>
\r
35 #include <shibsp/exceptions.h>
\r
36 #include <shibsp/SPConfig.h>
\r
37 #include <shibsp/ServiceProvider.h>
\r
38 #include <shibsp/metadata/MetadataProviderCriteria.h>
\r
39 #include <shibsp/util/SPConstants.h>
\r
40 #include <saml/saml2/metadata/Metadata.h>
\r
41 #include <xmltooling/logging.h>
\r
43 using namespace shibsp;
\r
44 using namespace opensaml::saml2md;
\r
45 using namespace opensaml;
\r
46 using namespace xmltooling::logging;
\r
47 using namespace xmltooling;
\r
48 using namespace std;
\r
50 using xercesc::XMLString;
\r
54 cerr << "usage: mdquery -e <entityID> [-a <app id> -nostrict]" << endl;
\r
55 cerr << " mdquery -e <entityID> -r <role> -p <protocol> [-a <app id> -ns <namespace> -nostrict]" << endl;
\r
58 int main(int argc,char* argv[])
\r
60 char* entityID = NULL;
\r
61 char* appID = "default";
\r
64 const XMLCh* protocol = NULL;
\r
68 for (int i=1; i<argc; i++) {
\r
69 if (!strcmp(argv[i],"-e") && i+1<argc)
\r
71 else if (!strcmp(argv[i],"-a") && i+1<argc)
\r
73 else if (!strcmp(argv[i],"-p") && i+1<argc)
\r
75 else if (!strcmp(argv[i],"-r") && i+1<argc)
\r
77 else if (!strcmp(argv[i],"-ns") && i+1<argc)
\r
79 else if (!strcmp(argv[i],"-saml10"))
\r
80 protocol=samlconstants::SAML10_PROTOCOL_ENUM;
\r
81 else if (!strcmp(argv[i],"-saml11"))
\r
82 protocol=samlconstants::SAML11_PROTOCOL_ENUM;
\r
83 else if (!strcmp(argv[i],"-saml2"))
\r
84 protocol=samlconstants::SAML20P_NS;
\r
85 else if (!strcmp(argv[i],"-idp"))
\r
86 rname="IDPSSODescriptor";
\r
87 else if (!strcmp(argv[i],"-aa"))
\r
88 rname="AttributeAuthorityDescriptor";
\r
89 else if (!strcmp(argv[i],"-pdp"))
\r
90 rname="PDPDescriptor";
\r
91 else if (!strcmp(argv[i],"-sp"))
\r
92 rname="SPSSODescriptor";
\r
93 else if (!strcmp(argv[i],"-nostrict"))
\r
105 protocol = XMLString::transcode(prot);
\r
113 SPConfig& conf=SPConfig::getConfig();
\r
114 conf.setFeatures(SPConfig::Metadata | SPConfig::Trust | SPConfig::OutOfProcess | SPConfig::Credentials);
\r
117 if (!conf.instantiate()) {
\r
122 ServiceProvider* sp=conf.getServiceProvider();
\r
125 Category& log = Category::getInstance(SHIBSP_LOGCAT".Utility.MDQuery");
\r
127 const Application* app = sp->getApplication(appID);
\r
129 log.error("unknown application ID (%s)", appID);
\r
135 app->getMetadataProvider()->lock();
\r
136 MetadataProviderCriteria mc(*app, entityID, NULL, NULL, strict);
\r
138 const XMLCh* ns = rns ? XMLString::transcode(rns) : samlconstants::SAML20MD_NS;
\r
139 auto_ptr_XMLCh n(rname);
\r
140 QName q(ns, n.get());
\r
142 mc.protocol = protocol;
\r
143 const RoleDescriptor* role = app->getMetadataProvider()->getEntityDescriptor(mc).second;
\r
145 XMLHelper::serialize(role->marshall(), cout, true);
\r
147 log.error("compatible role %s not found for (%s)", q.toString().c_str(), entityID);
\r
150 const EntityDescriptor* entity = app->getMetadataProvider()->getEntityDescriptor(mc).first;
\r
152 XMLHelper::serialize(entity->marshall(), cout, true);
\r
154 log.error("no metadata found for (%s)", entityID);
\r
157 app->getMetadataProvider()->unlock();
\r