2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
24 * SAML Metadata Query tool layered on SP configuration.
27 #if defined (_MSC_VER) || defined(__BORLANDC__)
28 # include "config_win32.h"
34 # define _CRT_NONSTDC_NO_DEPRECATE 1
35 # define _CRT_SECURE_NO_DEPRECATE 1
38 #include <shibsp/Application.h>
39 #include <shibsp/exceptions.h>
40 #include <shibsp/SPConfig.h>
41 #include <shibsp/ServiceProvider.h>
42 #include <shibsp/metadata/MetadataProviderCriteria.h>
43 #include <shibsp/util/SPConstants.h>
44 #include <saml/saml2/metadata/Metadata.h>
45 #include <xmltooling/logging.h>
47 using namespace shibsp;
48 using namespace opensaml::saml2md;
49 using namespace opensaml;
50 using namespace xmltooling::logging;
51 using namespace xmltooling;
54 using xercesc::XMLString;
58 cerr << "usage: mdquery -e <entityID> [-a <app id> -nostrict]" << endl;
59 cerr << " mdquery -e <entityID> -r <role> -p <protocol> [-a <app id> -ns <namespace> -nostrict]" << endl;
62 int main(int argc,char* argv[])
64 char* entityID = nullptr;
65 char* appID = "default";
68 const XMLCh* protocol = nullptr;
69 char* rname = nullptr;
72 for (int i=1; i<argc; i++) {
73 if (!strcmp(argv[i],"-e") && i+1<argc)
75 else if (!strcmp(argv[i],"-a") && i+1<argc)
77 else if (!strcmp(argv[i],"-p") && i+1<argc)
79 else if (!strcmp(argv[i],"-r") && i+1<argc)
81 else if (!strcmp(argv[i],"-ns") && i+1<argc)
83 else if (!strcmp(argv[i],"-saml10"))
84 protocol=samlconstants::SAML10_PROTOCOL_ENUM;
85 else if (!strcmp(argv[i],"-saml11"))
86 protocol=samlconstants::SAML11_PROTOCOL_ENUM;
87 else if (!strcmp(argv[i],"-saml2"))
88 protocol=samlconstants::SAML20P_NS;
89 else if (!strcmp(argv[i],"-idp"))
90 rname="IDPSSODescriptor";
91 else if (!strcmp(argv[i],"-aa"))
92 rname="AttributeAuthorityDescriptor";
93 else if (!strcmp(argv[i],"-pdp"))
94 rname="PDPDescriptor";
95 else if (!strcmp(argv[i],"-sp"))
96 rname="SPSSODescriptor";
97 else if (!strcmp(argv[i],"-nostrict"))
106 SPConfig& conf=SPConfig::getConfig();
107 conf.setFeatures(SPConfig::Metadata | SPConfig::Trust | SPConfig::OutOfProcess | SPConfig::Credentials);
114 protocol = XMLString::transcode(prot);
123 if (!conf.instantiate()) {
128 ServiceProvider* sp=conf.getServiceProvider();
131 Category& log = Category::getInstance(SHIBSP_LOGCAT".Utility.MDQuery");
133 const Application* app = sp->getApplication(appID);
135 log.error("unknown application ID (%s)", appID);
141 app->getMetadataProvider()->lock();
142 MetadataProviderCriteria mc(*app, entityID, nullptr, nullptr, strict);
144 const XMLCh* ns = rns ? XMLString::transcode(rns) : samlconstants::SAML20MD_NS;
145 auto_ptr_XMLCh n(rname);
146 QName q(ns, n.get());
148 mc.protocol = protocol;
149 const RoleDescriptor* role = app->getMetadataProvider()->getEntityDescriptor(mc).second;
151 XMLHelper::serialize(role->marshall(), cout, true);
153 log.error("compatible role %s not found for (%s)", q.toString().c_str(), entityID);
156 const EntityDescriptor* entity = app->getMetadataProvider()->getEntityDescriptor(mc).first;
158 XMLHelper::serialize(entity->marshall(), cout, true);
160 log.error("no metadata found for (%s)", entityID);
163 app->getMetadataProvider()->unlock();