X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=util%2Fmdquery.cpp;h=56f988e597609d362f30131a9b6cc5e5696493c6;hb=c51bfd77603cf0ddb0b5e374c35586a8435895d6;hp=33435ccfb95e442297dc45b95912f36292757887;hpb=57cc54a45a0e202855575c5bdfad1d0aab3e82bb;p=shibboleth%2Fcpp-sp.git diff --git a/util/mdquery.cpp b/util/mdquery.cpp index 33435cc..56f988e 100644 --- a/util/mdquery.cpp +++ b/util/mdquery.cpp @@ -1,183 +1,168 @@ -/* - * Copyright 2001-2007 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * mdquery.cpp - * - * SAML Metadata Query tool layered on SP configuration - */ - -#if defined (_MSC_VER) || defined(__BORLANDC__) -# include "config_win32.h" -#else -# include "config.h" -#endif - -#ifdef WIN32 -# define _CRT_NONSTDC_NO_DEPRECATE 1 -# define _CRT_SECURE_NO_DEPRECATE 1 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace shibsp; -using namespace opensaml::saml2md; -using namespace opensaml; -using namespace xmltooling::logging; -using namespace xmltooling; -using namespace std; - -void usage() -{ - cerr << "usage: mdquery -e [-a -nostrict]" << endl; - cerr << " mdquery -e -r -p [-a -ns -nostrict]" << endl; -} - -int main(int argc,char* argv[]) -{ - char* entityID = NULL; - char* appID = "default"; - bool strict = true; - char* prot = NULL; - const XMLCh* protocol = NULL; - char* rname = NULL; - char* rns = NULL; - - for (int i=1; i docjanitor(dummydoc); - xercesc::DOMElement* dummy = dummydoc->createElementNS(NULL,_path); - auto_ptr_XMLCh src(config); - dummy->setAttributeNS(NULL,_path,src.get()); - dummy->setAttributeNS(NULL,validate,xmlconstants::XML_ONE); - conf.setServiceProvider(conf.ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy)); - conf.getServiceProvider()->init(); - } - catch (exception&) { - conf.term(); - return -2; - } - - ServiceProvider* sp=conf.getServiceProvider(); - sp->lock(); - - Category& log = Category::getInstance(SHIBSP_LOGCAT".Utility.MDQuery"); - - const Application* app = sp->getApplication(appID); - if (!app) { - log.error("unknown application ID (%s)", appID); - sp->unlock(); - conf.term(); - return -3; - } - - app->getMetadataProvider()->lock(); - MetadataProviderCriteria mc(*app, entityID, NULL, NULL, strict); - if (rname) { - const XMLCh* ns = rns ? XMLString::transcode(rns) : samlconstants::SAML20MD_NS; - auto_ptr_XMLCh n(rname); - QName q(ns, n.get()); - mc.role = &q; - mc.protocol = protocol; - const RoleDescriptor* role = app->getMetadataProvider()->getEntityDescriptor(mc).second; - if (role) - XMLHelper::serialize(role->marshall(), cout, true); - else - log.error("compatible role %s not found for (%s)", q.toString().c_str(), entityID); - } - else { - const EntityDescriptor* entity = app->getMetadataProvider()->getEntityDescriptor(mc).first; - if (entity) - XMLHelper::serialize(entity->marshall(), cout, true); - else - log.error("no metadata found for (%s)", entityID); - } - - app->getMetadataProvider()->unlock(); - - sp->unlock(); - conf.term(); - return 0; -} +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + */ + +/** + * mdquery.cpp + * + * SAML Metadata Query tool layered on SP configuration. + */ + +#if defined (_MSC_VER) || defined(__BORLANDC__) +# include "config_win32.h" +#else +# include "config.h" +#endif + +#ifdef WIN32 +# define _CRT_NONSTDC_NO_DEPRECATE 1 +# define _CRT_SECURE_NO_DEPRECATE 1 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace shibsp; +using namespace opensaml::saml2md; +using namespace opensaml; +using namespace xmltooling::logging; +using namespace xmltooling; +using namespace std; + +using xercesc::XMLString; + +void usage() +{ + cerr << "usage: mdquery -e [-a -nostrict]" << endl; + cerr << " mdquery -e -r -p [-a -ns -nostrict]" << endl; +} + +int main(int argc,char* argv[]) +{ + char* entityID = nullptr; + char* appID = "default"; + bool strict = true; + char* prot = nullptr; + const XMLCh* protocol = nullptr; + char* rname = nullptr; + char* rns = nullptr; + + for (int i=1; ilock(); + + Category& log = Category::getInstance(SHIBSP_LOGCAT ".Utility.MDQuery"); + + const Application* app = sp->getApplication(appID); + if (!app) { + log.error("unknown application ID (%s)", appID); + sp->unlock(); + conf.term(); + return -3; + } + + app->getMetadataProvider()->lock(); + MetadataProviderCriteria mc(*app, entityID, nullptr, nullptr, strict); + if (rname) { + const XMLCh* ns = rns ? XMLString::transcode(rns) : samlconstants::SAML20MD_NS; + auto_ptr_XMLCh n(rname); + QName q(ns, n.get()); + mc.role = &q; + mc.protocol = protocol; + const RoleDescriptor* role = app->getMetadataProvider()->getEntityDescriptor(mc).second; + if (role) + XMLHelper::serialize(role->marshall(), cout, true); + else + log.error("compatible role %s not found for (%s)", q.toString().c_str(), entityID); + } + else { + const EntityDescriptor* entity = app->getMetadataProvider()->getEntityDescriptor(mc).first; + if (entity) + XMLHelper::serialize(entity->marshall(), cout, true); + else + log.error("no metadata found for (%s)", entityID); + } + + app->getMetadataProvider()->unlock(); + + sp->unlock(); + conf.term(); + return 0; +}