2 * Copyright 2001-2005 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 IConfig* ini=ShibTargetConfig::getConfig().getINI();
85 xmltooling::Locker locker(ini);
88 const IApplication* app=dynamic_cast<const IApplication*>(ini->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
108 app->getAttributeDesignators().clone()
113 MetadataProvider* m=app->getMetadataProvider();
114 xmltooling::Locker locker(m);
115 const EntityDescriptor* site=m->getEntityDescriptor(domain.get());
117 throw MetadataException("Unable to locate specified origin site's metadata.");
119 // Try to locate an AA role.
120 const AttributeAuthorityDescriptor* AA=site->getAttributeAuthorityDescriptor(saml::XML::SAML11_PROTOCOL_ENUM);
122 throw MetadataException("Unable to locate metadata for origin site's Attribute Authority.");
124 ShibHTTPHook::ShibHTTPHookCallContext ctx(app->getCredentialUse(site),AA);
126 SAMLResponse* response=NULL;
127 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
128 for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !response && ep!=endpoints.end(); ++ep) {
130 // Get a binding object for this protocol.
131 const SAMLBinding* binding = app->getBinding((*ep)->getBinding());
135 response=binding->send((*ep)->getLocation(), *(req.get()), &ctx);
142 throw opensaml::BindingException("unable to successfully query for attributes");
144 // Run it through the AAP. Note that we could end up with an empty response!
145 Iterator<SAMLAssertion*> a=response->getAssertions();
146 for (unsigned long c=0; c < a.size();) {
148 shibboleth::AAP::apply(app->getAAPProviders(),*(a[c]),AA);
151 catch (SAMLException&) {
152 response->removeAssertion(c);
156 Iterator<SAMLAssertion*> i=response->getAssertions();
159 SAMLAssertion* a=i.next();
160 cout << "Issuer: "; xmlout(cout,a->getIssuer()); cout << endl;
161 const SAMLDateTime* exp=a->getNotOnOrAfter();
164 xmlout(cout,exp->getRawData());
169 Iterator<SAMLStatement*> j=a->getStatements();
172 SAMLAttributeStatement* s=dynamic_cast<SAMLAttributeStatement*>(j.next());
175 const SAMLNameIdentifier* sub=s->getSubject()->getNameIdentifier();
176 cout << "Format: "; xmlout(cout,sub->getFormat()); cout << endl;
177 cout << "Domain: "; xmlout(cout,sub->getNameQualifier()); cout << endl;
178 cout << "Handle: "; xmlout(cout,sub->getName()); cout << endl;
180 Iterator<SAMLAttribute*> attrs=s->getAttributes();
181 while (attrs.hasNext())
183 SAMLAttribute* attr=attrs.next();
184 cout << "Attribute Name: "; xmlout(cout,attr->getName()); cout << endl;
185 Iterator<const XMLCh*> vals=attr->getValues();
186 while (vals.hasNext())
188 cout << "Attribute Value: ";
189 xmlout(cout,vals.next());
199 cerr << "caught an exception: " << e.what() << endl;