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/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))
85 const IApplication* app=conf.getINI()->getApplication(a_param);
87 throw SAMLException("specified <Application> section not found in configuration");
89 auto_ptr_XMLCh domain(q_param);
90 auto_ptr_XMLCh handle(h_param);
91 auto_ptr_XMLCh format(f_param);
92 auto_ptr_XMLCh resource(app->getString("providerId").second);
94 auto_ptr<SAMLRequest> req(
96 new SAMLAttributeQuery(
98 new SAMLNameIdentifier(
101 format.get() ? format.get() : shibspconstants::SHIB1_NAMEID_FORMAT_URI
105 app->getAttributeDesignators().clone()
110 MetadataProvider* m=app->getMetadataProvider();
111 xmltooling::Locker locker(m);
112 const EntityDescriptor* site=m->getEntityDescriptor(domain.get());
114 throw MetadataException("Unable to locate specified origin site's metadata.");
116 // Try to locate an AA role.
117 const AttributeAuthorityDescriptor* AA=site->getAttributeAuthorityDescriptor(saml::XML::SAML11_PROTOCOL_ENUM);
119 throw MetadataException("Unable to locate metadata for origin site's Attribute Authority.");
121 ShibHTTPHook::ShibHTTPHookCallContext ctx(app->getCredentialUse(site),AA);
123 SAMLResponse* response=NULL;
124 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
125 for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !response && ep!=endpoints.end(); ++ep) {
127 // Get a binding object for this protocol.
128 const SAMLBinding* binding = app->getBinding((*ep)->getBinding());
132 response=binding->send((*ep)->getLocation(), *(req.get()), &ctx);
139 throw opensaml::BindingException("unable to successfully query for attributes");
141 // Run it through the AAP. Note that we could end up with an empty response!
142 Iterator<SAMLAssertion*> a=response->getAssertions();
143 for (unsigned long c=0; c < a.size();) {
145 shibboleth::AAP::apply(app->getAAPProviders(),*(a[c]),AA);
148 catch (SAMLException&) {
149 response->removeAssertion(c);
153 Iterator<SAMLAssertion*> i=response->getAssertions();
156 SAMLAssertion* a=i.next();
157 cout << "Issuer: "; xmlout(cout,a->getIssuer()); cout << endl;
158 const SAMLDateTime* exp=a->getNotOnOrAfter();
161 xmlout(cout,exp->getRawData());
166 Iterator<SAMLStatement*> j=a->getStatements();
169 SAMLAttributeStatement* s=dynamic_cast<SAMLAttributeStatement*>(j.next());
172 const SAMLNameIdentifier* sub=s->getSubject()->getNameIdentifier();
173 cout << "Format: "; xmlout(cout,sub->getFormat()); cout << endl;
174 cout << "Domain: "; xmlout(cout,sub->getNameQualifier()); cout << endl;
175 cout << "Handle: "; xmlout(cout,sub->getName()); cout << endl;
177 Iterator<SAMLAttribute*> attrs=s->getAttributes();
178 while (attrs.hasNext())
180 SAMLAttribute* attr=attrs.next();
181 cout << "Attribute Name: "; xmlout(cout,attr->getName()); cout << endl;
182 Iterator<const XMLCh*> vals=attr->getValues();
183 while (vals.hasNext())
185 cout << "Attribute Value: ";
186 xmlout(cout,vals.next());
196 cerr << "caught an exception: " << e.what() << endl;