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