{81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6}
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "samlquery", "util\samlquery.vcproj", "{F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}"
- ProjectSection(WebsiteProperties) = preProject
- Debug.AspNetCompiler.Debug = "True"
- Release.AspNetCompiler.Debug = "False"
- EndProjectSection
- ProjectSection(ProjectDependencies) = postProject
- {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6}
- EndProjectSection
-EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shibsp-lite", "shibsp\shibsp-lite.vcproj", "{81F0F7A6-DC36-46EF-957F-F9E81D4403F7}"
ProjectSection(WebsiteProperties) = preProject
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.Debug = "False"
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "siterefresh", "util\siterefresh.vcproj", "{4D02F36E-D2CD-4FD1-AC50-2941E27BB3FB}"
- ProjectSection(WebsiteProperties) = preProject
- Debug.AspNetCompiler.Debug = "True"
- Release.AspNetCompiler.Debug = "False"
- EndProjectSection
-EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "adfs", "adfs\adfs.vcproj", "{26D4FABF-ACDE-4947-9C4A-7AE1B50CD83A}"
ProjectSection(WebsiteProperties) = preProject
Debug.AspNetCompiler.Debug = "True"
{81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6}
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "resolvertest", "util\resolvertest.vcproj", "{F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}"
+ ProjectSection(WebsiteProperties) = preProject
+ Debug.AspNetCompiler.Debug = "True"
+ Release.AspNetCompiler.Debug = "False"
+ EndProjectSection
+ ProjectSection(ProjectDependencies) = postProject
+ {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6}
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
{F13141B5-6C87-40BB-8D4E-5CC56EBB4C59}.Debug|Win32.Build.0 = Debug|Win32
{F13141B5-6C87-40BB-8D4E-5CC56EBB4C59}.Release|Win32.ActiveCfg = Release|Win32
{F13141B5-6C87-40BB-8D4E-5CC56EBB4C59}.Release|Win32.Build.0 = Release|Win32
- {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}.Debug|Win32.ActiveCfg = Debug|Win32
- {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}.Debug|Win32.Build.0 = Debug|Win32
- {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}.Release|Win32.ActiveCfg = Release|Win32
- {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}.Release|Win32.Build.0 = Release|Win32
{81F0F7A6-DC36-46EF-957F-F9E81D4403F7}.Debug|Win32.ActiveCfg = Debug|Win32
{81F0F7A6-DC36-46EF-957F-F9E81D4403F7}.Debug|Win32.Build.0 = Debug|Win32
{81F0F7A6-DC36-46EF-957F-F9E81D4403F7}.Release|Win32.ActiveCfg = Release|Win32
{81F0F7A6-DC36-46EF-957F-F9E81D4403F7}.Release|Win32.Build.0 = Release|Win32
- {4D02F36E-D2CD-4FD1-AC50-2941E27BB3FB}.Debug|Win32.ActiveCfg = Debug|Win32
- {4D02F36E-D2CD-4FD1-AC50-2941E27BB3FB}.Debug|Win32.Build.0 = Debug|Win32
- {4D02F36E-D2CD-4FD1-AC50-2941E27BB3FB}.Release|Win32.ActiveCfg = Release|Win32
- {4D02F36E-D2CD-4FD1-AC50-2941E27BB3FB}.Release|Win32.Build.0 = Release|Win32
{26D4FABF-ACDE-4947-9C4A-7AE1B50CD83A}.Debug|Win32.ActiveCfg = Debug|Win32
{26D4FABF-ACDE-4947-9C4A-7AE1B50CD83A}.Debug|Win32.Build.0 = Debug|Win32
{26D4FABF-ACDE-4947-9C4A-7AE1B50CD83A}.Release|Win32.ActiveCfg = Release|Win32
{F13141B6-6C87-40BB-8D4E-5CC56EBB4C5A}.Debug|Win32.Build.0 = Debug|Win32
{F13141B6-6C87-40BB-8D4E-5CC56EBB4C5A}.Release|Win32.ActiveCfg = Release|Win32
{F13141B6-6C87-40BB-8D4E-5CC56EBB4C5A}.Release|Win32.Build.0 = Release|Win32
+ {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}.Debug|Win32.ActiveCfg = Debug|Win32
+ {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}.Debug|Win32.Build.0 = Debug|Win32
+ {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}.Release|Win32.ActiveCfg = Release|Win32
+ {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
{666A63A7-983F-4C19-8411-207F24305197} = {96AE4FC9-45EF-4C18-9F3B-EDA439E26E4C}
{26D4FABF-ACDE-4947-9C4A-7AE1B50CD83A} = {96AE4FC9-45EF-4C18-9F3B-EDA439E26E4C}
{26D4FABF-ACDE-4947-9C4A-7AE1B50CD83B} = {96AE4FC9-45EF-4C18-9F3B-EDA439E26E4C}
- {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59} = {FED80230-119E-4B2F-9F53-D2660A5F022B}
- {4D02F36E-D2CD-4FD1-AC50-2941E27BB3FB} = {FED80230-119E-4B2F-9F53-D2660A5F022B}
{F13141B6-6C87-40BB-8D4E-5CC56EBB4C5A} = {FED80230-119E-4B2F-9F53-D2660A5F022B}
+ {F13141B6-6C87-40BB-8D4E-5CC56EBB4C59} = {FED80230-119E-4B2F-9F53-D2660A5F022B}
EndGlobalSection
EndGlobal
,m_decoder(NULL), m_role(samlconstants::SAML20MD_NS, opensaml::saml2md::IDPSSODescriptor::LOCAL_NAME)
#endif
{
+ if (!e)
+ return;
string address(appId);
address += getString("Location").second;
setAddress(address.c_str());
#ifdef _DEBUG
NDC ndc("load");
#endif
+ if (!e)
+ return;
m_root=e;
// Process each attribute as a property.
AUTOMAKE_OPTIONS = foreign
-bin_PROGRAMS = samlquery mdquery
+bin_PROGRAMS = mdquery resolvertest
-samlquery_SOURCES = samlquery.cpp
+resolvertest_SOURCES = resolvertest.cpp
-samlquery_LDADD = \
+resolvertest_LDADD = \
$(top_builddir)/shibsp/libshibsp.la
-samlquery_LDFLAGS = $(XMLSEC_LIBS)
+resolvertest_LDFLAGS = $(XMLSEC_LIBS)
mdquery_SOURCES = mdquery.cpp
mdquery_LDFLAGS = $(XMLSEC_LIBS)
-EXTRA_DIST = mdquery.vcproj samlquery.vcproj
+EXTRA_DIST = mdquery.vcproj resolvertest.vcproj
--- /dev/null
+/*\r
+ * Copyright 2001-2007 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/**\r
+ * resolvertest.cpp\r
+ * \r
+ * Tool to exercise SP attribute subsystems.\r
+ */\r
+\r
+#if defined (_MSC_VER) || defined(__BORLANDC__)\r
+# include "config_win32.h"\r
+#else\r
+# include "config.h"\r
+#endif\r
+\r
+#ifdef WIN32\r
+# define _CRT_NONSTDC_NO_DEPRECATE 1\r
+# define _CRT_SECURE_NO_DEPRECATE 1\r
+#endif\r
+\r
+#include <shibsp/Application.h>\r
+#include <shibsp/exceptions.h>\r
+#include <shibsp/SPConfig.h>\r
+#include <shibsp/ServiceProvider.h>\r
+#include <shibsp/attribute/Attribute.h>
+#include <shibsp/attribute/resolver/ResolutionContext.h>
+#include <shibsp/handler/AssertionConsumerService.h>
+#include <shibsp/util/SPConstants.h>\r
+\r
+#include <saml/saml1/core/Assertions.h>\r
+#include <saml/saml2/core/Assertions.h>\r
+#include <saml/saml2/metadata/Metadata.h>\r
+#include <xercesc/util/XMLUniDefs.hpp>\r
+#include <xmltooling/XMLToolingConfig.h>\r
+#include <xmltooling/util/XMLHelper.h>\r
+\r
+using namespace shibsp;\r
+using namespace opensaml::saml2md;\r
+using namespace opensaml;\r
+using namespace xmltooling::logging;\r
+using namespace xmltooling;\r
+using namespace xercesc;\r
+using namespace std;\r
+\r
+#if defined (_MSC_VER)
+ #pragma warning( push )
+ #pragma warning( disable : 4250 )
+#endif
+\r
+class ResolverTest : public shibsp::AssertionConsumerService
+{
+public:
+ ResolverTest(const DOMElement* e, const char* appId)
+ : shibsp::AssertionConsumerService(e, appId, Category::getInstance(SHIBSP_LOGCAT".Utilities.ResolverTest")) {
+ }
+ virtual ~ResolverTest() {}
+
+ ResolutionContext* resolveAttributes (
+ const Application& application,
+ const RoleDescriptor* issuer,
+ const XMLCh* protocol,
+ const saml1::NameIdentifier* v1nameid,
+ const saml2::NameID* nameid,
+ const XMLCh* authncontext_class,
+ const XMLCh* authncontext_decl,
+ const vector<const Assertion*>* tokens
+ ) const {
+ return shibsp::AssertionConsumerService::resolveAttributes(
+ application, issuer, protocol, v1nameid, nameid, authncontext_class, authncontext_decl, tokens
+ );
+ }
+
+private:
+ string implementProtocol(
+ const Application& application,
+ const HTTPRequest& httpRequest,
+ SecurityPolicy& policy,
+ const PropertySet* settings,
+ const XMLObject& xmlObject
+ ) const {
+ throw FatalProfileException("Should never be called.");
+ }
+};
+\r
+#if defined (_MSC_VER)
+ #pragma warning( pop )
+#endif
+\r
+void usage()\r
+{\r
+ cerr << "usage: resolvertest -n <name> -i <IdP> -p <protocol> [-f <format URI> -a <application id>]" << endl;\r
+ cerr << " resolvertest [-a <application id>] < assertion.xml" << endl;\r
+}\r
+\r
+int main(int argc,char* argv[])\r
+{\r
+ char* a_param=NULL;\r
+ char* n_param=NULL;\r
+ char* f_param=NULL;\r
+ char* i_param=NULL;\r
+ char* prot = NULL;\r
+ const XMLCh* protocol = NULL;\r
+ char* path=NULL;\r
+ char* config=NULL;\r
+\r
+ for (int i=1; i<argc; i++) {\r
+ if (!strcmp(argv[i],"-n") && i+1<argc)\r
+ n_param=argv[++i];\r
+ else if (!strcmp(argv[i],"-f") && i+1<argc)\r
+ f_param=argv[++i];\r
+ else if (!strcmp(argv[i],"-i") && i+1<argc)\r
+ i_param=argv[++i];\r
+ else if (!strcmp(argv[i],"-p") && i+1<argc)\r
+ prot=argv[++i];\r
+ else if (!strcmp(argv[i],"-saml10"))\r
+ protocol=samlconstants::SAML10_PROTOCOL_ENUM;\r
+ else if (!strcmp(argv[i],"-saml11"))\r
+ protocol=samlconstants::SAML11_PROTOCOL_ENUM;\r
+ else if (!strcmp(argv[i],"-saml2"))\r
+ protocol=samlconstants::SAML20P_NS;\r
+ else if (!strcmp(argv[i],"-a") && i+1<argc)\r
+ a_param=argv[++i];\r
+ }\r
+\r
+ if (n_param && !i_param) {\r
+ usage();\r
+ exit(-10);\r
+ }\r
+\r
+ path=getenv("SHIBSP_SCHEMAS");\r
+ if (!path)\r
+ path=SHIBSP_SCHEMAS;\r
+ config=getenv("SHIBSP_CONFIG");\r
+ if (!config)\r
+ config=SHIBSP_CONFIG;\r
+ if (!a_param)\r
+ a_param="default";\r
+\r
+ XMLToolingConfig::getConfig().log_config(getenv("SHIBSP_LOGGING") ? getenv("SHIBSP_LOGGING") : SHIBSP_LOGGING);\r
+\r
+ SPConfig& conf=SPConfig::getConfig();\r
+ conf.setFeatures(\r
+ SPConfig::Metadata |\r
+ SPConfig::Trust |\r
+ SPConfig::AttributeResolution |\r
+ SPConfig::Credentials |\r
+ SPConfig::OutOfProcess\r
+ );\r
+ if (!conf.init(path))\r
+ return -1;\r
+\r
+ if (n_param) {\r
+ if (!protocol) {\r
+ if (prot)\r
+ protocol = XMLString::transcode(prot);\r
+ }\r
+ if (!protocol) {\r
+ conf.term();\r
+ usage();\r
+ exit(-10);\r
+ }\r
+ }\r
+ \r
+ try {\r
+ static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);\r
+ static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e);\r
+ xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument();\r
+ XercesJanitor<xercesc::DOMDocument> docjanitor(dummydoc);\r
+ xercesc::DOMElement* dummy = dummydoc->createElementNS(NULL,path);\r
+ auto_ptr_XMLCh src(config);\r
+ dummy->setAttributeNS(NULL,path,src.get());\r
+ dummy->setAttributeNS(NULL,validate,xmlconstants::XML_ONE);\r
+\r
+ conf.setServiceProvider(conf.ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));\r
+ conf.getServiceProvider()->init();\r
+ }\r
+ catch (exception&) {\r
+ conf.term();\r
+ return -2;\r
+ }\r
+\r
+ ServiceProvider* sp=conf.getServiceProvider();\r
+ sp->lock();\r
+\r
+ Category& log = Category::getInstance(SHIBSP_LOGCAT".Utility.ResolverTest");\r
+\r
+ const Application* app = sp->getApplication(a_param);\r
+ if (!app) {\r
+ log.error("unknown application ID (%s)", a_param);\r
+ sp->unlock();\r
+ conf.term();\r
+ return -3;\r
+ }\r
+\r
+ try {\r
+ ResolutionContext* ctx;\r
+\r
+ if (n_param) {\r
+ auto_ptr_XMLCh issuer(i_param);\r
+ auto_ptr_XMLCh name(n_param);\r
+ auto_ptr_XMLCh format(f_param);\r
+\r
+ MetadataProvider* m=app->getMetadataProvider();\r
+ xmltooling::Locker mlocker(m);\r
+ const EntityDescriptor* site=m->getEntityDescriptor(issuer.get());\r
+ if (!site)\r
+ throw MetadataException("Unable to locate metadata for IdP ($1).", params(1,i_param));\r
+\r
+ // Build NameID(s).\r
+ auto_ptr<saml2::NameID> v2name(saml2::NameIDBuilder::buildNameID());\r
+ v2name->setName(name.get());
+ v2name->setFormat(format.get());
+ saml1::NameIdentifier* v1name = NULL;\r
+ if (!XMLString::equals(protocol, samlconstants::SAML20P_NS)) {
+ v1name = saml1::NameIdentifierBuilder::buildNameIdentifier();
+ v1name->setName(name.get());
+ v1name->setFormat(format.get());
+ v1name->setNameQualifier(issuer.get());
+ }
+\r
+ ResolverTest rt(NULL, a_param);\r
+ try {\r
+ ctx = rt.resolveAttributes(*app, site->getIDPSSODescriptor(protocol), protocol, v1name, v2name.get(), NULL, NULL, NULL);\r
+ }\r
+ catch (...) {\r
+ delete v1name;\r
+ throw;\r
+ }\r
+ }\r
+ else {\r
+ // Try and load assertion from stdin.\r
+ DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(cin);\r
+ XercesJanitor<DOMDocument> docjan(doc);\r
+ auto_ptr<XMLObject> token(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true));\r
+ docjan.release();\r
+\r
+ // Get the issuer and protocol and NameIDs.\r
+ const XMLCh* issuer = NULL;\r
+ const saml1::NameIdentifier* v1name = NULL;\r
+ saml2::NameID* v2name = NULL;\r
+ saml2::Assertion* a2 = dynamic_cast<saml2::Assertion*>(token.get());\r
+ saml1::Assertion* a1 = dynamic_cast<saml1::Assertion*>(token.get());\r
+ if (a2) {\r
+ const saml2::Issuer* iss = a2->getIssuer();\r
+ issuer = iss ? iss->getName() : NULL;\r
+ protocol = samlconstants::SAML20P_NS;\r
+ v2name = a2->getSubject() ? a2->getSubject()->getNameID() : NULL;\r
+ }\r
+ else if (a1) {\r
+ issuer = a1->getIssuer();\r
+ if (a1->getMinorVersion().first && a1->getMinorVersion().second == 0)\r
+ protocol = samlconstants::SAML10_PROTOCOL_ENUM;\r
+ else\r
+ protocol = samlconstants::SAML11_PROTOCOL_ENUM;\r
+ v1name = a1->getAuthenticationStatements().size() ?\r
+ a1->getAuthenticationStatements().front()->getSubject()->getNameIdentifier() : NULL;\r
+ // Normalize the SAML 1.x NameIdentifier...
+ v2name = saml2::NameIDBuilder::buildNameID();
+ v2name->setName(v1name->getName());
+ v2name->setFormat(v1name->getFormat());
+ v2name->setNameQualifier(v1name->getNameQualifier());
+ }\r
+ else {\r
+ throw FatalProfileException("Unknown assertion type.");\r
+ }\r
+\r
+ if (!issuer) {\r
+ if (v1name)\r
+ delete v2name;\r
+ throw FatalProfileException("Unable to determine issuer.");\r
+ }\r
+\r
+ MetadataProvider* m=app->getMetadataProvider();\r
+ xmltooling::Locker mlocker(m);\r
+ const EntityDescriptor* site=m->getEntityDescriptor(issuer);\r
+ if (!site) {\r
+ auto_ptr_char temp(issuer);\r
+ throw MetadataException("Unable to locate metadata for IdP ($1).", params(1,temp.get()));\r
+ }\r
+ \r
+ vector<const Assertion*> tokens(1, dynamic_cast<Assertion*>(token.get()));\r
+ ResolverTest rt(NULL, a_param);\r
+ try {\r
+ ctx = rt.resolveAttributes(*app, site->getIDPSSODescriptor(protocol), protocol, v1name, v2name, NULL, NULL, &tokens);\r
+ }\r
+ catch (...) {\r
+ if (v1name)\r
+ delete v2name;\r
+ throw;\r
+ }\r
+ }\r
+\r
+ auto_ptr<ResolutionContext> wrapper(ctx);\r
+ for (vector<Attribute*>::const_iterator a = ctx->getResolvedAttributes().begin(); a != ctx->getResolvedAttributes().end(); ++a) {\r
+ cout << endl;\r
+ for (vector<string>::const_iterator s = (*a)->getAliases().begin(); s != (*a)->getAliases().end(); ++s)\r
+ cout << "ID: " << *s << endl;\r
+ for (vector<string>::const_iterator s = (*a)->getSerializedValues().begin(); s != (*a)->getSerializedValues().end(); ++s)\r
+ cout << "Value: " << *s << endl;\r
+ }\r
+ cout << endl;\r
+ }\r
+ catch(exception& ex) {\r
+ log.error(ex.what());\r
+ sp->unlock();\r
+ conf.term();\r
+ return -10;\r
+ }\r
+\r
+ sp->unlock();\r
+ conf.term();\r
+ return 0;\r
+}\r
<VisualStudioProject\r
ProjectType="Visual C++"\r
Version="8.00"\r
- Name="samlquery"\r
+ Name="resolvertest"\r
ProjectGUID="{F13141B6-6C87-40BB-8D4E-5CC56EBB4C59}"\r
- RootNamespace="samlquery"\r
+ RootNamespace="resolvertest"\r
>\r
<Platforms>\r
<Platform\r
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalDependencies="wsock32.lib log4shib1.lib saml2.lib xmltooling1.lib xerces-c_2.lib"\r
+ AdditionalDependencies="log4shib1.lib saml2.lib xmltooling1.lib xerces-c_2.lib"\r
LinkIncremental="1"\r
SuppressStartupBanner="true"\r
AdditionalLibraryDirectories="..\..\cpp-opensaml2\$(ConfigurationName);..\..\cpp-xmltooling\$(ConfigurationName)"\r
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalDependencies="wsock32.lib log4shib1D.lib saml2D.lib xmltooling1D.lib xerces-c_2D.lib"\r
+ AdditionalDependencies="log4shib1D.lib saml2D.lib xmltooling1D.lib xerces-c_2D.lib"\r
LinkIncremental="2"\r
SuppressStartupBanner="true"\r
AdditionalLibraryDirectories="..\..\cpp-opensaml2\$(ConfigurationName);..\..\cpp-xmltooling\$(ConfigurationName)"\r
</References>\r
<Files>\r
<File\r
- RelativePath=".\samlquery.cpp"\r
+ RelativePath=".\resolvertest.cpp"\r
>\r
</File>\r
</Files>\r
+++ /dev/null
-/*\r
- * Copyright 2001-2007 Internet2\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * samlquery.cpp\r
- * \r
- * SAML Attribute Query tool layered on SP configuration\r
- */\r
-\r
-#if defined (_MSC_VER) || defined(__BORLANDC__)\r
-# include "config_win32.h"\r
-#else\r
-# include "config.h"\r
-#endif\r
-\r
-#ifdef WIN32\r
-# define _CRT_NONSTDC_NO_DEPRECATE 1\r
-# define _CRT_SECURE_NO_DEPRECATE 1\r
-#endif\r
-\r
-#include <shibsp/Application.h>\r
-#include <shibsp/exceptions.h>\r
-#include <shibsp/SPConfig.h>\r
-#include <shibsp/ServiceProvider.h>\r
-#include <shibsp/attribute/resolver/AttributeResolver.h>\r
-#include <shibsp/binding/SOAPClient.h>\r
-#include <shibsp/util/SPConstants.h>\r
-\r
-#include <saml/binding/SecurityPolicy.h>\r
-#include <saml/saml1/binding/SAML1SOAPClient.h>\r
-#include <saml/saml1/core/Assertions.h>\r
-#include <saml/saml1/core/Protocols.h>\r
-#include <saml/saml2/binding/SAML2SOAPClient.h>\r
-#include <saml/saml2/core/Protocols.h>\r
-#include <saml/saml2/metadata/Metadata.h>\r
-#include <xercesc/util/XMLUniDefs.hpp>\r
-#include <xmltooling/XMLToolingConfig.h>\r
-#include <xmltooling/util/XMLHelper.h>\r
-\r
-using namespace shibsp;\r
-using namespace opensaml::saml1;\r
-using namespace opensaml::saml1p;\r
-using namespace opensaml::saml2;\r
-using namespace opensaml::saml2p;\r
-using namespace opensaml::saml2md;\r
-using namespace opensaml;\r
-using namespace xmltooling;\r
-using namespace std;\r
-\r
-enum samlversion {\r
- v10, v11, v20\r
-};\r
-\r
-int main(int argc,char* argv[])\r
-{\r
- char* n_param=NULL;\r
- char* q_param=NULL;\r
- char* f_param=NULL;\r
- char* a_param=NULL;\r
- char* path=NULL;\r
- char* config=NULL;\r
-\r
- for (int i=1; i<argc; i++) {\r
- if (!strcmp(argv[i],"-n") && i+1<argc)\r
- n_param=argv[++i];\r
- else if (!strcmp(argv[i],"-q") && i+1<argc)\r
- q_param=argv[++i];\r
- else if (!strcmp(argv[i],"-f") && i+1<argc)\r
- f_param=argv[++i];\r
- else if (!strcmp(argv[i],"-a") && i+1<argc)\r
- a_param=argv[++i];\r
- }\r
-\r
- if (!n_param || !q_param) {\r
- cerr << "usage: samlquery -n <name> -q <IdP> [-f <format URI> -a <application id>]" << endl;\r
- exit(0);\r
- }\r
- \r
- path=getenv("SHIBSP_SCHEMAS");\r
- if (!path)\r
- path=SHIBSP_SCHEMAS;\r
- config=getenv("SHIBSP_CONFIG");\r
- if (!config)\r
- config=SHIBSP_CONFIG;\r
- if (!a_param)\r
- a_param="default";\r
-\r
- XMLToolingConfig::getConfig().log_config(getenv("SHIBSP_LOGGING") ? getenv("SHIBSP_LOGGING") : SHIBSP_LOGGING);\r
-\r
- SPConfig& conf=SPConfig::getConfig();\r
- conf.setFeatures(\r
- SPConfig::Metadata |\r
- SPConfig::Trust |\r
- SPConfig::Credentials |\r
- SPConfig::OutOfProcess\r
- );\r
- if (!conf.init(path))\r
- return -10;\r
-\r
- try {\r
- static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);\r
- static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e);\r
- xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument();\r
- XercesJanitor<xercesc::DOMDocument> docjanitor(dummydoc);\r
- xercesc::DOMElement* dummy = dummydoc->createElementNS(NULL,path);\r
- auto_ptr_XMLCh src(config);\r
- dummy->setAttributeNS(NULL,path,src.get());\r
- dummy->setAttributeNS(NULL,validate,xmlconstants::XML_ONE);\r
-\r
- conf.setServiceProvider(conf.ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));\r
- conf.getServiceProvider()->init();\r
- }\r
- catch (exception&) {\r
- conf.term();\r
- return -20;\r
- }\r
-\r
- ServiceProvider* sp=conf.getServiceProvider();\r
- sp->lock();\r
-\r
- try {\r
- const Application* app=sp->getApplication(a_param);\r
- if (!app)\r
- throw ConfigurationException("Application ($1) not found in configuration.", params(1,a_param));\r
-\r
- auto_ptr_XMLCh domain(q_param);\r
- auto_ptr_XMLCh name(n_param);\r
- auto_ptr_XMLCh format(f_param);\r
- auto_ptr_XMLCh issuer(app->getString("entityID").second);\r
-\r
- MetadataProvider* m=app->getMetadataProvider();\r
- xmltooling::Locker mlocker(m);\r
- const EntityDescriptor* site=m->getEntityDescriptor(domain.get());\r
- if (!site)\r
- throw MetadataException("Unable to locate metadata for IdP ($1).", params(1,q_param));\r
-\r
- // Try to locate an AA role.\r
- samlversion ver;\r
- const AttributeAuthorityDescriptor* AA=NULL;\r
- if (AA=site->getAttributeAuthorityDescriptor(samlconstants::SAML20P_NS))\r
- ver = v20;\r
- else if (AA=site->getAttributeAuthorityDescriptor(samlconstants::SAML11_PROTOCOL_ENUM))\r
- ver = v11;\r
- else if (AA=site->getAttributeAuthorityDescriptor(samlconstants::SAML10_PROTOCOL_ENUM))\r
- ver = v10;\r
- else\r
- throw MetadataException("No AttributeAuthority role found in metadata.");\r
-\r
- shibsp::SecurityPolicy policy(*app);\r
- shibsp::SOAPClient soaper(policy);\r
- MetadataCredentialCriteria mcc(*AA);\r
-\r
- if (ver == v20) {\r
- auto_ptr_XMLCh binding(samlconstants::SAML20_BINDING_SOAP);\r
- opensaml::saml2p::StatusResponseType* srt=NULL;\r
- const vector<AttributeService*>& endpoints=AA->getAttributeServices();\r
- for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !srt && ep!=endpoints.end(); ++ep) {\r
- try {\r
- if (!XMLString::equals((*ep)->getBinding(),binding.get()))\r
- continue;\r
- auto_ptr_char loc((*ep)->getLocation());\r
- NameID* nameid = NameIDBuilder::buildNameID();\r
- opensaml::saml2::Subject* subject = opensaml::saml2::SubjectBuilder::buildSubject();\r
- subject->setNameID(nameid);\r
- opensaml::saml2p::AttributeQuery* query = opensaml::saml2p::AttributeQueryBuilder::buildAttributeQuery();\r
- query->setSubject(subject);\r
- Issuer* iss = IssuerBuilder::buildIssuer();\r
- query->setIssuer(iss);\r
- nameid->setName(name.get());\r
- nameid->setFormat(format.get() ? format.get() : NameID::TRANSIENT);\r
- nameid->setNameQualifier(domain.get());\r
- iss->setName(issuer.get());\r
- SAML2SOAPClient client(soaper, false);\r
- client.sendSAML(query, app->getId(), mcc, loc.get());\r
- srt = client.receiveSAML();\r
- }\r
- catch (exception& ex) {\r
- cerr << "Caught exception: " << ex.what() << endl << endl;\r
- soaper.reset();\r
- }\r
- }\r
-\r
- if (!srt)\r
- throw BindingException("Unable to obtain a SAML response from attribute authority.");\r
- else if (!XMLString::equals(srt->getStatus()->getStatusCode()->getValue(), saml2p::StatusCode::SUCCESS)) {\r
- delete srt;\r
- throw BindingException("Attribute authority returned a SAML error.");\r
- }\r
- const opensaml::saml2p::Response* response = dynamic_cast<opensaml::saml2p::Response*>(srt);\r
-\r
- const vector<opensaml::saml2::Assertion*>& assertions = response->getAssertions();\r
- if (assertions.size())\r
- cout << *assertions.front();\r
- else\r
- cout << "No assertions found.";\r
-\r
- delete response;\r
- }\r
- else {\r
- auto_ptr_XMLCh binding(samlconstants::SAML1_BINDING_SOAP);\r
- const opensaml::saml1p::Response* response=NULL;\r
- const vector<AttributeService*>& endpoints=AA->getAttributeServices();\r
- for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !response && ep!=endpoints.end(); ++ep) {\r
- try {\r
- if (!XMLString::equals((*ep)->getBinding(),binding.get()))\r
- continue;\r
- auto_ptr_char loc((*ep)->getLocation());\r
- NameIdentifier* nameid = NameIdentifierBuilder::buildNameIdentifier();\r
- opensaml::saml1::Subject* subject = opensaml::saml1::SubjectBuilder::buildSubject();\r
- subject->setNameIdentifier(nameid);\r
- opensaml::saml1p::AttributeQuery* query = opensaml::saml1p::AttributeQueryBuilder::buildAttributeQuery();\r
- query->setSubject(subject);\r
- Request* request = RequestBuilder::buildRequest();\r
- request->setAttributeQuery(query);\r
- nameid->setName(name.get());\r
- nameid->setFormat(format.get() ? format.get() : shibspconstants::SHIB1_NAMEID_FORMAT_URI);\r
- nameid->setNameQualifier(domain.get());\r
- query->setResource(issuer.get());\r
- request->setMinorVersion(ver==v11 ? 1 : 0);\r
- SAML1SOAPClient client(soaper, false);\r
- client.sendSAML(request, app->getId(), mcc, loc.get());\r
- response = client.receiveSAML();\r
- }\r
- catch (exception& ex) {\r
- cerr << "Caught exception: " << ex.what() << endl << endl;\r
- soaper.reset();\r
- }\r
- }\r
-\r
- if (!response)\r
- throw BindingException("Unable to obtain a SAML response from attribute authority.");\r
- else if (*(response->getStatus()->getStatusCode()->getValue()) != saml1p::StatusCode::SUCCESS) {\r
- delete const_cast<opensaml::saml1p::Response*>(response);\r
- throw BindingException("Attribute authority returned a SAML error.");\r
- }\r
-\r
- const vector<opensaml::saml1::Assertion*>& assertions = response->getAssertions();\r
- if (assertions.size())\r
- cout << *assertions.front();\r
- else\r
- cout << "No assertions found.";\r
-\r
- delete const_cast<opensaml::saml1p::Response*>(response);\r
- }\r
- }\r
- catch(exception& ex) {\r
- cerr << ex.what() << endl;\r
- }\r
-\r
- sp->unlock();\r
- conf.term();\r
- return 0;\r
-}\r