2 * Copyright 2001-2007 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.
18 # define _CRT_NONSTDC_NO_DEPRECATE 1
19 # define _CRT_SECURE_NO_DEPRECATE 1
22 #include <shib-target/shib-target.h>
23 #include <shibsp/SPConfig.h>
24 #include <shibsp/util/SPConstants.h>
26 using namespace shibsp;
27 using namespace shibtarget;
28 using namespace opensaml::saml2md;
32 int main(int argc,char* argv[])
41 for (int i=1; i<argc; i++) {
42 if (!strcmp(argv[i],"-c") && i+1<argc)
44 else if (!strcmp(argv[i],"-d") && i+1<argc)
46 else if (!strcmp(argv[i],"-h") && i+1<argc)
48 else if (!strcmp(argv[i],"-q") && i+1<argc)
50 else if (!strcmp(argv[i],"-f") && i+1<argc)
52 else if (!strcmp(argv[i],"-a") && i+1<argc)
56 if (!h_param || !q_param) {
57 cerr << "usage: shibtest -h <handle> -q <origin_site> [-f <format URI> -a <application_id> -d <schema path> -c <config>]" << endl;
62 path=getenv("SHIBSCHEMAS");
66 config=getenv("SHIBCONFIG");
72 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
73 SPConfig::getConfig().setFeatures(
76 SPConfig::Credentials |
78 SPConfig::OutOfProcess |
81 if (!conf.init(path) || !conf.load(config))
84 ServiceProvider* sp=SPConfig::getConfig().getServiceProvider();
85 xmltooling::Locker locker(sp);
88 const IApplication* app=dynamic_cast<const IApplication*>(sp->getApplication(a_param));
90 throw SAMLException("specified <Application> section not found in configuration");
92 auto_ptr_XMLCh domain(q_param);
93 auto_ptr_XMLCh handle(h_param);
94 auto_ptr_XMLCh format(f_param);
95 auto_ptr_XMLCh resource(app->getString("providerId").second);
97 auto_ptr<SAMLRequest> req(
99 new SAMLAttributeQuery(
101 new SAMLNameIdentifier(
104 format.get() ? format.get() : shibspconstants::SHIB1_NAMEID_FORMAT_URI
112 MetadataProvider* m=app->getMetadataProvider();
113 xmltooling::Locker locker(m);
114 const EntityDescriptor* site=m->getEntityDescriptor(domain.get());
116 throw MetadataException("Unable to locate specified origin site's metadata.");
118 // Try to locate an AA role.
119 const AttributeAuthorityDescriptor* AA=site->getAttributeAuthorityDescriptor(saml::XML::SAML11_PROTOCOL_ENUM);
121 throw MetadataException("Unable to locate metadata for origin site's Attribute Authority.");
123 ShibHTTPHook::ShibHTTPHookCallContext ctx(app->getCredentialUse(site),AA);
125 SAMLResponse* response=NULL;
126 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
127 for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !response && ep!=endpoints.end(); ++ep) {
129 // Get a binding object for this protocol.
130 const SAMLBinding* binding = app->getBinding((*ep)->getBinding());
134 response=binding->send((*ep)->getLocation(), *(req.get()), &ctx);
141 throw opensaml::BindingException("unable to successfully query for attributes");
143 // Run it through the AAP. Note that we could end up with an empty response!
144 Iterator<SAMLAssertion*> a=response->getAssertions();
145 for (unsigned long c=0; c < a.size();) {
147 shibboleth::AAP::apply(app->getAAPProviders(),*(a[c]),AA);
150 catch (SAMLException&) {
151 response->removeAssertion(c);
155 Iterator<SAMLAssertion*> i=response->getAssertions();
158 SAMLAssertion* a=i.next();
159 cout << "Issuer: "; xmlout(cout,a->getIssuer()); cout << endl;
160 const SAMLDateTime* exp=a->getNotOnOrAfter();
163 xmlout(cout,exp->getRawData());
168 Iterator<SAMLStatement*> j=a->getStatements();
171 SAMLAttributeStatement* s=dynamic_cast<SAMLAttributeStatement*>(j.next());
174 const SAMLNameIdentifier* sub=s->getSubject()->getNameIdentifier();
175 cout << "Format: "; xmlout(cout,sub->getFormat()); cout << endl;
176 cout << "Domain: "; xmlout(cout,sub->getNameQualifier()); cout << endl;
177 cout << "Handle: "; xmlout(cout,sub->getName()); cout << endl;
179 Iterator<SAMLAttribute*> attrs=s->getAttributes();
180 while (attrs.hasNext())
182 SAMLAttribute* attr=attrs.next();
183 cout << "Attribute Name: "; xmlout(cout,attr->getName()); cout << endl;
184 Iterator<const XMLCh*> vals=attr->getValues();
185 while (vals.hasNext())
187 cout << "Attribute Value: ";
188 xmlout(cout,vals.next());
198 cerr << "caught an exception: " << e.what() << endl;