X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=util%2Fmdquery.cpp;h=56f988e597609d362f30131a9b6cc5e5696493c6;hb=c51bfd77603cf0ddb0b5e374c35586a8435895d6;hp=f0f918c8057ab6a421f678660c2619b901bc9fd3;hpb=ad28adb148162be3e333707879f7064f8b2709f9;p=shibboleth%2Fcpp-sp.git diff --git a/util/mdquery.cpp b/util/mdquery.cpp index f0f918c..56f988e 100644 --- a/util/mdquery.cpp +++ b/util/mdquery.cpp @@ -1,111 +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 - -using namespace shibsp; -using namespace opensaml::saml2md; -using namespace opensaml; -using namespace xmltooling; -using namespace std; - -int main(int argc,char* argv[]) -{ - /* - char* n_param=NULL; - char* q_param=NULL; - char* f_param=NULL; - char* a_param=NULL; - - for (int i=1; i -q [-f -a ]" << endl; - exit(0); - } - if (!a_param) - a_param="default"; - */ - - char* path=getenv("SHIBSP_SCHEMAS"); - if (!path) - path=SHIBSP_SCHEMAS; - char* config=getenv("SHIBSP_CONFIG"); - if (!config) - config=SHIBSP_CONFIG; - - XMLToolingConfig::getConfig().log_config(getenv("SHIBSP_LOGGING") ? getenv("SHIBSP_LOGGING") : SHIBSP_LOGGING); - - SPConfig& conf=SPConfig::getConfig(); - conf.setFeatures(SPConfig::Metadata | SPConfig::OutOfProcess); - if (!conf.init(path)) - return -10; - - try { - static const XMLCh _path[] = UNICODE_LITERAL_4(p,a,t,h); - static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e); - xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); - XercesJanitor 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 -20; - } - - ServiceProvider* sp=conf.getServiceProvider(); - sp->lock(); - - 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; +}