Added ASCII metadata lookup.
[shibboleth/cpp-sp.git] / shib / shib.h
1 /*
2  * The Shibboleth License, Version 1.
3  * Copyright (c) 2002
4  * University Corporation for Advanced Internet Development, Inc.
5  * All rights reserved
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution, if any, must include
17  * the following acknowledgment: "This product includes software developed by
18  * the University Corporation for Advanced Internet Development
19  * <http://www.ucaid.edu>Internet2 Project. Alternately, this acknowledegement
20  * may appear in the software itself, if and wherever such third-party
21  * acknowledgments normally appear.
22  *
23  * Neither the name of Shibboleth nor the names of its contributors, nor
24  * Internet2, nor the University Corporation for Advanced Internet Development,
25  * Inc., nor UCAID may be used to endorse or promote products derived from this
26  * software without specific prior written permission. For written permission,
27  * please contact shibboleth@shibboleth.org
28  *
29  * Products derived from this software may not be called Shibboleth, Internet2,
30  * UCAID, or the University Corporation for Advanced Internet Development, nor
31  * may Shibboleth appear in their name, without prior written permission of the
32  * University Corporation for Advanced Internet Development.
33  *
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36  * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
38  * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
39  * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
40  * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
41  * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT,
42  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  */
49
50
51 /* shib.h - Shibboleth header file
52
53    Scott Cantor
54    6/4/02
55
56    $History:$
57 */
58
59 #ifndef __shib_h__
60 #define __shib_h__
61
62 #include <saml/saml.h>
63 #include <shib/shib-threads.h>
64 #include <xsec/xenc/XENCEncryptionMethod.hpp>
65
66 #ifdef WIN32
67 # ifndef SHIB_EXPORTS
68 #  define SHIB_EXPORTS __declspec(dllimport)
69 # endif
70 #else
71 # define SHIB_EXPORTS
72 #endif
73
74 namespace shibboleth
75 {
76     #define DECLARE_SHIB_EXCEPTION(name,base) \
77         class SHIB_EXPORTS name : public saml::base \
78         { \
79         public: \
80             name(const char* msg) : saml::base(msg) {RTTI(name);} \
81             name(const std::string& msg) : saml::base(msg) {RTTI(name);} \
82             name(const saml::Iterator<saml::QName>& codes, const char* msg) : saml::base(codes,msg) {RTTI(name);} \
83             name(const saml::Iterator<saml::QName>& codes, const std::string& msg) : saml::base(codes, msg) {RTTI(name);} \
84             name(const saml::QName& code, const char* msg) : saml::base(code,msg) {RTTI(name);} \
85             name(const saml::QName& code, const std::string& msg) : saml::base(code, msg) {RTTI(name);} \
86             name(DOMElement* e) : saml::base(e) {RTTI(name);} \
87             name(std::istream& in) : saml::base(in) {RTTI(name);} \
88             virtual ~name() throw () {} \
89         }
90
91     DECLARE_SHIB_EXCEPTION(MetadataException,SAMLException);
92     DECLARE_SHIB_EXCEPTION(CredentialException,SAMLException);
93     DECLARE_SHIB_EXCEPTION(InvalidHandleException,RetryableProfileException);
94
95     // Metadata abstract interfaces, based on SAML 2.0
96     
97     struct SHIB_EXPORTS IContactPerson
98     {
99         enum ContactType { technical, support, administrative, billing, other };
100         virtual ContactType getType() const=0;
101         virtual const char* getCompany() const=0;
102         virtual const char* getGivenName() const=0;
103         virtual const char* getSurName() const=0;
104         virtual saml::Iterator<std::string> getEmailAddresses() const=0;
105         virtual saml::Iterator<std::string> getTelephoneNumbers() const=0;
106         virtual const DOMElement* getElement() const=0;
107         virtual ~IContactPerson() {}
108     };
109
110     struct SHIB_EXPORTS IOrganization
111     {
112         virtual const char* getName(const char* lang="en") const=0;
113         virtual const char* getDisplayName(const char* lang="en") const=0;
114         virtual const char* getURL(const char* lang="en") const=0;
115         virtual const DOMElement* getElement() const=0;
116         virtual ~IOrganization() {}
117     };
118     
119     struct SHIB_EXPORTS IKeyDescriptor
120     {
121         enum KeyUse { unspecified, encryption, signing };
122         virtual KeyUse getUse() const=0;
123         virtual DSIGKeyInfoList* getKeyInfo() const=0;
124         virtual saml::Iterator<const XENCEncryptionMethod*> getEncryptionMethods() const=0;
125         virtual ~IKeyDescriptor() {}
126     };
127
128     struct SHIB_EXPORTS IEndpoint
129     {
130         virtual const XMLCh* getBinding() const=0;
131         virtual const XMLCh* getLocation() const=0;
132         virtual const XMLCh* getResponseLocation() const=0;
133         virtual const DOMElement* getElement() const=0;
134         virtual ~IEndpoint() {}
135     };
136
137     struct SHIB_EXPORTS IIndexedEndpoint : public virtual IEndpoint
138     {
139         virtual unsigned short getIndex() const=0;
140         virtual ~IIndexedEndpoint() {}
141     };
142     
143     struct SHIB_EXPORTS IEndpointManager
144     {
145         virtual saml::Iterator<const IEndpoint*> getEndpoints() const=0;
146         virtual const IEndpoint* getDefaultEndpoint() const=0;
147         virtual const IEndpoint* getEndpointByIndex(unsigned short index) const=0;
148         virtual const IEndpoint* getEndpointByBinding(const XMLCh* binding) const=0;
149         virtual ~IEndpointManager() {}
150     };
151
152     struct SHIB_EXPORTS IEntityDescriptor;
153     struct SHIB_EXPORTS IRoleDescriptor
154     {
155         virtual const IEntityDescriptor* getEntityDescriptor() const=0;
156         virtual saml::Iterator<const XMLCh*> getProtocolSupportEnumeration() const=0;
157         virtual bool hasSupport(const XMLCh* protocol) const=0;
158         virtual bool isValid() const=0;
159         virtual const char* getErrorURL() const=0;
160         virtual saml::Iterator<const IKeyDescriptor*> getKeyDescriptors() const=0;
161         virtual const IOrganization* getOrganization() const=0;
162         virtual saml::Iterator<const IContactPerson*> getContactPersons() const=0;
163         virtual const DOMElement* getElement() const=0;
164         virtual ~IRoleDescriptor() {}
165     };
166
167     struct SHIB_EXPORTS ISSODescriptor : public virtual IRoleDescriptor
168     {
169         virtual const IEndpointManager* getArtifactResolutionServiceManager() const=0;
170         virtual const IEndpointManager* getSingleLogoutServiceManager() const=0;
171         virtual const IEndpointManager* getManageNameIDServiceManager() const=0;
172         virtual saml::Iterator<const XMLCh*> getNameIDFormats() const=0;
173         virtual ~ISSODescriptor() {}
174     };
175     
176     struct SHIB_EXPORTS IIDPSSODescriptor : public virtual ISSODescriptor
177     {
178         virtual bool getWantAuthnRequestsSigned() const=0;
179         virtual const IEndpointManager* getSingleSignOnServiceManager() const=0;
180         virtual const IEndpointManager* getNameIDMappingServiceManager() const=0;
181         virtual const IEndpointManager* getAssertionIDRequestServiceManager() const=0;
182         virtual saml::Iterator<const XMLCh*> getAttributeProfiles() const=0;
183         virtual saml::Iterator<const saml::SAMLAttribute*> getAttributes() const=0;
184         virtual ~IIDPSSODescriptor() {}
185     };
186     
187     struct SHIB_EXPORTS IAttributeConsumingService
188     {
189         virtual const XMLCh* getName(const char* lang="en") const=0;
190         virtual const XMLCh* getDescription(const char* lang="en") const=0;
191         virtual saml::Iterator<std::pair<const saml::SAMLAttribute*,bool> > getRequestedAttributes() const=0;
192         virtual ~IAttributeConsumingService() {}
193     };
194
195     struct SHIB_EXPORTS ISPSSODescriptor : public virtual ISSODescriptor
196     {
197         virtual bool getAuthnRequestsSigned() const=0;
198         virtual bool getWantAssertionsSigned() const=0;
199         virtual const IEndpointManager* getAssertionConsumerServiceManager() const=0;
200         virtual saml::Iterator<const IAttributeConsumingService*> getAttributeConsumingServices() const=0;
201         virtual const IAttributeConsumingService* getDefaultAttributeConsumingService() const=0;
202         virtual const IAttributeConsumingService* getAttributeConsumingServiceByID(const XMLCh* id) const=0;
203         virtual ~ISPSSODescriptor() {}
204     };
205
206     struct SHIB_EXPORTS IAuthnAuthorityDescriptor : public virtual IRoleDescriptor
207     {
208         virtual const IEndpointManager* getAuthnQueryServiceManager() const=0;
209         virtual const IEndpointManager* getAssertionIDRequestServiceManager() const=0;
210         virtual saml::Iterator<const XMLCh*> getNameIDFormats() const=0;
211         virtual ~IAuthnAuthorityDescriptor() {}
212     };
213
214     struct SHIB_EXPORTS IPDPDescriptor : public virtual IRoleDescriptor
215     {
216         virtual const IEndpointManager* getAuthzServiceManager() const=0;
217         virtual const IEndpointManager* getAssertionIDRequestServiceManager() const=0;
218         virtual saml::Iterator<const XMLCh*> getNameIDFormats() const=0;
219         virtual ~IPDPDescriptor() {}
220     };
221
222     struct SHIB_EXPORTS IAttributeAuthorityDescriptor : public virtual IRoleDescriptor
223     {
224         virtual const IEndpointManager* getAttributeServiceManager() const=0;
225         virtual const IEndpointManager* getAssertionIDRequestServiceManager() const=0;
226         virtual saml::Iterator<const XMLCh*> getNameIDFormats() const=0;
227         virtual saml::Iterator<const XMLCh*> getAttributeProfiles() const=0;
228         virtual saml::Iterator<const saml::SAMLAttribute*> getAttributes() const=0;
229         virtual ~IAttributeAuthorityDescriptor() {}
230     };
231     
232     struct SHIB_EXPORTS IAffiliationDescriptor
233     {
234         virtual const IEntityDescriptor* getEntityDescriptor() const=0;
235         virtual const XMLCh* getOwnerID() const=0;
236         virtual bool isValid() const=0;
237         virtual saml::Iterator<const XMLCh*> getMembers() const=0;
238         virtual bool isMember(const XMLCh* id) const=0;
239         virtual saml::Iterator<const IKeyDescriptor*> getKeyDescriptors() const=0;
240         virtual const DOMElement* getElement() const=0;
241         virtual ~IAffiliationDescriptor() {}
242     };
243
244     struct SHIB_EXPORTS IEntitiesDescriptor;
245     struct SHIB_EXPORTS IEntityDescriptor
246     {
247         virtual const XMLCh* getId() const=0;
248         virtual bool isValid() const=0;
249         virtual saml::Iterator<const IRoleDescriptor*> getRoleDescriptors() const=0;
250         virtual const IIDPSSODescriptor* getIDPSSODescriptor(const XMLCh* protocol) const=0;
251         virtual const ISPSSODescriptor* getSPSSODescriptor(const XMLCh* protocol) const=0;
252         virtual const IAuthnAuthorityDescriptor* getAuthnAuthorityDescriptor(const XMLCh* protocol) const=0;
253         virtual const IAttributeAuthorityDescriptor* getAttributeAuthorityDescriptor(const XMLCh* protocol) const=0;
254         virtual const IPDPDescriptor* getPDPDescriptor(const XMLCh* protocol) const=0;
255         virtual const IAffiliationDescriptor* getAffiliationDescriptor() const=0;
256         virtual const IOrganization* getOrganization() const=0;
257         virtual saml::Iterator<const IContactPerson*> getContactPersons() const=0;
258         virtual saml::Iterator<std::pair<const XMLCh*,const XMLCh*> > getAdditionalMetadataLocations() const=0;
259         virtual const IEntitiesDescriptor* getEntitiesDescriptor() const=0;
260         virtual const DOMElement* getElement() const=0;
261         virtual ~IEntityDescriptor() {}
262     };
263     
264     struct SHIB_EXPORTS IEntitiesDescriptor
265     {
266         virtual const XMLCh* getName() const=0;
267         virtual bool isValid() const=0;
268         virtual const IEntitiesDescriptor* getEntitiesDescriptor() const=0;
269         virtual saml::Iterator<const IEntitiesDescriptor*> getEntitiesDescriptors() const=0;
270         virtual saml::Iterator<const IEntityDescriptor*> getEntityDescriptors() const=0;
271         virtual const DOMElement* getElement() const=0;
272         virtual ~IEntitiesDescriptor() {}
273     };
274     
275     // Supports Shib role extension describing attribute scoping rules
276     struct SHIB_EXPORTS IScopedRoleDescriptor : public virtual IRoleDescriptor
277     {
278         virtual saml::Iterator<std::pair<const XMLCh*,bool> > getScopes() const=0;
279         virtual ~IScopedRoleDescriptor() {}
280     };
281        
282     struct SHIB_EXPORTS IMetadata : public virtual saml::ILockable, public virtual saml::IPlugIn
283     {
284         virtual const IEntityDescriptor* lookup(const char* id) const=0;
285         virtual const IEntityDescriptor* lookup(const XMLCh* id) const=0;
286         virtual const IEntityDescriptor* lookup(const saml::SAMLArtifact* artifact) const=0;
287         virtual ~IMetadata() {}
288     };
289
290     struct SHIB_EXPORTS IRevocation : public virtual saml::ILockable, public virtual saml::IPlugIn
291     {
292         virtual saml::Iterator<void*> getRevocationLists(const IEntityDescriptor* provider, const IRoleDescriptor* role=NULL) const=0;
293         virtual ~IRevocation() {}
294     };
295
296     // Trust interface hides *all* details of signature and SSL validation.
297     // Pluggable providers can fully override the Shibboleth trust model here.
298     
299     struct SHIB_EXPORTS ITrust : public virtual saml::IPlugIn
300     {
301         virtual bool validate(
302             const saml::Iterator<IRevocation*>& revocations,
303             const IRoleDescriptor* role, const saml::SAMLSignedObject& token,
304             const saml::Iterator<IMetadata*>& metadatas=EMPTY(IMetadata*)
305             )=0;
306         virtual bool attach(const saml::Iterator<IRevocation*>& revocations, const IRoleDescriptor* role, void* ctx)=0;
307         virtual ~ITrust() {}
308     };
309
310     // Credentials interface abstracts access to "owned" keys and certificates.
311     
312     struct SHIB_EXPORTS ICredResolver : public virtual saml::IPlugIn
313     {
314         virtual void attach(void* ctx) const=0;
315         virtual XSECCryptoKey* getKey() const=0;
316         virtual saml::Iterator<XSECCryptoX509*> getCertificates() const=0;
317         virtual void dump(FILE* f) const=0;
318         virtual void dump() const { dump(stdout); }
319         virtual ~ICredResolver() {}
320     };
321
322     struct SHIB_EXPORTS ICredentials : public virtual saml::ILockable, public virtual saml::IPlugIn
323     {
324         virtual const ICredResolver* lookup(const char* id) const=0;
325         virtual ~ICredentials() {}
326     };
327     
328     // Attribute acceptance processing interfaces, applied to incoming attributes.
329
330     struct SHIB_EXPORTS IAttributeRule
331     {
332         virtual const XMLCh* getName() const=0;
333         virtual const XMLCh* getNamespace() const=0;
334         virtual const char* getFactory() const=0;
335         virtual const char* getAlias() const=0;
336         virtual const char* getHeader() const=0;
337         virtual bool getCaseSensitive() const=0;
338         virtual void apply(saml::SAMLAttribute& attribute, const IRoleDescriptor* role=NULL) const=0;
339         virtual ~IAttributeRule() {}
340     };
341     
342     struct SHIB_EXPORTS IAAP : public virtual saml::ILockable, public virtual saml::IPlugIn
343     {
344         virtual bool anyAttribute() const=0;
345         virtual const IAttributeRule* lookup(const XMLCh* attrName, const XMLCh* attrNamespace=NULL) const=0;
346         virtual const IAttributeRule* lookup(const char* alias) const=0;
347         virtual saml::Iterator<const IAttributeRule*> getAttributeRules() const=0;
348         virtual ~IAAP() {}
349     };
350
351 #ifdef SHIB_INSTANTIATE
352     template class SHIB_EXPORTS saml::Iterator<const IContactPerson*>;
353     template class SHIB_EXPORTS saml::Iterator<const XENCEncryptionMethod*>;
354     template class SHIB_EXPORTS saml::Iterator<const IKeyDescriptor*>;
355     template class SHIB_EXPORTS saml::Iterator<const IAttributeConsumingService*>;
356     template class SHIB_EXPORTS saml::Iterator<const IRoleDescriptor*>;
357     template class SHIB_EXPORTS saml::Iterator<const IEntityDescriptor*>;
358     template class SHIB_EXPORTS saml::Iterator<const IEntitiesDescriptor*>;
359     template class SHIB_EXPORTS saml::Iterator<const IEndpoint*>;
360     template class SHIB_EXPORTS saml::Iterator<const IAttributeRule*>;
361     template class SHIB_EXPORTS saml::Iterator<IMetadata*>;
362     template class SHIB_EXPORTS saml::ArrayIterator<IMetadata*>;
363     template class SHIB_EXPORTS saml::Iterator<ITrust*>;
364     template class SHIB_EXPORTS saml::ArrayIterator<ITrust*>;
365     template class SHIB_EXPORTS saml::Iterator<IRevocation*>;
366     template class SHIB_EXPORTS saml::ArrayIterator<IRevocation*>;
367     template class SHIB_EXPORTS saml::Iterator<ICredentials*>;
368     template class SHIB_EXPORTS saml::ArrayIterator<ICredentials*>;
369     template class SHIB_EXPORTS saml::Iterator<IAAP*>;
370     template class SHIB_EXPORTS saml::ArrayIterator<IAAP*>;
371 #endif
372
373     struct SHIB_EXPORTS Constants
374     {
375         static const XMLCh SHIB_ATTRIBUTE_NAMESPACE_URI[];
376         static const XMLCh SHIB_NAMEID_FORMAT_URI[];
377         static const XMLCh SHIB_AUTHNREQUEST_PROFILE_URI[];
378         static const XMLCh SHIB_NS[];
379         static const XMLCh InvalidHandle[];
380     };
381
382     // Glue classes between abstract metadata and concrete providers
383     
384     class SHIB_EXPORTS Metadata
385     {
386     public:
387         Metadata(const saml::Iterator<IMetadata*>& metadatas) : m_metadatas(metadatas), m_mapper(NULL) {}
388         ~Metadata();
389
390         const IEntityDescriptor* lookup(const char* id);
391         const IEntityDescriptor* lookup(const XMLCh* id);
392         const IEntityDescriptor* lookup(const saml::SAMLArtifact* artifact);
393
394     private:
395         Metadata(const Metadata&);
396         void operator=(const Metadata&);
397         IMetadata* m_mapper;
398         const saml::Iterator<IMetadata*>& m_metadatas;
399     };
400
401     class SHIB_EXPORTS Revocation
402     {
403     public:
404         Revocation(const saml::Iterator<IRevocation*>& revocations) : m_revocations(revocations), m_mapper(NULL) {}
405         ~Revocation();
406
407         saml::Iterator<void*> getRevocationLists(const IEntityDescriptor* provider, const IRoleDescriptor* role=NULL);
408
409     private:
410         Revocation(const Revocation&);
411         void operator=(const Revocation&);
412         IRevocation* m_mapper;
413         const saml::Iterator<IRevocation*>& m_revocations;
414     };
415
416     class SHIB_EXPORTS Trust
417     {
418     public:
419         Trust(const saml::Iterator<ITrust*>& trusts) : m_trusts(trusts) {}
420         ~Trust() {}
421
422         bool validate(
423             const saml::Iterator<IRevocation*>& revocations,
424             const IRoleDescriptor* role, const saml::SAMLSignedObject& token,
425             const saml::Iterator<IMetadata*>& metadatas=EMPTY(IMetadata*)
426             ) const;
427         bool attach(const saml::Iterator<IRevocation*>& revocations, const IRoleDescriptor* role, void* ctx) const;
428         
429     private:
430         Trust(const Trust&);
431         void operator=(const Trust&);
432         const saml::Iterator<ITrust*>& m_trusts;
433     };
434     
435     class SHIB_EXPORTS Credentials
436     {
437     public:
438         Credentials(const saml::Iterator<ICredentials*>& creds) : m_creds(creds), m_mapper(NULL) {}
439         ~Credentials();
440
441         const ICredResolver* lookup(const char* id);
442
443     private:
444         Credentials(const Credentials&);
445         void operator=(const Credentials&);
446         ICredentials* m_mapper;
447         const saml::Iterator<ICredentials*>& m_creds;
448     };
449
450     class SHIB_EXPORTS AAP
451     {
452     public:
453         AAP(const saml::Iterator<IAAP*>& aaps, const XMLCh* attrName, const XMLCh* attrNamespace=NULL);
454         AAP(const saml::Iterator<IAAP*>& aaps, const char* alias);
455         ~AAP();
456         bool fail() const {return m_mapper==NULL;}
457         const IAttributeRule* operator->() const {return m_rule;}
458         operator const IAttributeRule*() const {return m_rule;}
459         
460         static void apply(const saml::Iterator<IAAP*>& aaps, saml::SAMLAssertion& assertion, const IRoleDescriptor* role=NULL);
461         
462     private:
463         AAP(const AAP&);
464         void operator=(const AAP&);
465         IAAP* m_mapper;
466         const IAttributeRule* m_rule;
467     };
468
469     // Subclass around the OpenSAML browser profile interface,
470     // incoporates additional functionality using Shib-defined APIs.
471     class SHIB_EXPORTS ShibBrowserProfile : virtual public saml::SAMLBrowserProfile
472     {
473     public:
474         ShibBrowserProfile(
475             const saml::Iterator<IMetadata*>& metadatas=EMPTY(IMetadata*),
476             const saml::Iterator<IRevocation*>& revocations=EMPTY(IRevocation*),
477             const saml::Iterator<ITrust*>& trusts=EMPTY(ITrust*)
478             );
479         virtual ~ShibBrowserProfile();
480
481         virtual void setVersion(int major, int minor);
482         virtual saml::SAMLBrowserProfile::BrowserProfileResponse receive(
483             XMLCh** pIssuer,
484             const char* packet,
485             const XMLCh* recipient,
486             int supportedProfiles,
487             saml::IReplayCache* replayCache=NULL,
488             saml::SAMLBrowserProfile::ArtifactMapper* callback=NULL
489             ) const;
490
491     private:
492         saml::SAMLBrowserProfile* m_profile;
493         saml::Iterator<IMetadata*> m_metadatas;
494         saml::Iterator<IRevocation*> m_revocations;
495         saml::Iterator<ITrust*> m_trusts;
496     };
497
498     // Instead of wrapping the binding to deal with mutual authentication, we
499     // just use the HTTP hook functionality offered by OpenSAML. The hook will
500     // register "itself" as a globalCtx pointer with the SAML binding and the caller
501     // will declare and pass the embedded struct as callCtx for use by the hook.
502     class SHIB_EXPORTS ShibHTTPHook : virtual public saml::SAMLSOAPHTTPBinding::HTTPHook
503     {
504     public:
505         ShibHTTPHook(
506             const saml::Iterator<IRevocation*>& revocations,
507             const saml::Iterator<ITrust*>& trusts,
508             const saml::Iterator<ICredentials*>& creds
509             ) : m_revocations(revocations), m_trusts(trusts), m_creds(creds) {}
510         virtual ~ShibHTTPHook() {}
511         
512         // Only hook we need here is for outgoing connection to server.
513         virtual bool outgoing(saml::HTTPClient* conn, void* globalCtx=NULL, void* callCtx=NULL);
514
515         // Client declares a context object and pass as callCtx to send() method.
516         class SHIB_EXPORTS ShibHTTPHookCallContext {
517         public:
518             ShibHTTPHookCallContext(const char* credResolverId, const IRoleDescriptor* role)
519                 : m_credResolverId(credResolverId), m_role(role), m_hook(NULL) {}
520         private:
521             const char* m_credResolverId;
522             const IRoleDescriptor* m_role;
523             ShibHTTPHook* m_hook;
524             friend class ShibHTTPHook;
525             friend bool ssl_ctx_callback(void* ssl_ctx, void* userptr);
526         };
527     private:
528         friend bool ssl_ctx_callback(void* ssl_ctx, void* userptr);
529         saml::Iterator<IRevocation*> m_revocations;
530         saml::Iterator<ITrust*> m_trusts;
531         saml::Iterator<ICredentials*> m_creds;
532     };
533
534     class SHIB_EXPORTS ShibConfig
535     {
536     public:
537         ShibConfig() {}
538         virtual ~ShibConfig() {}
539
540         // global per-process setup and shutdown of Shibboleth runtime
541         virtual bool init();
542         virtual void term();
543
544         // enables runtime and clients to access configuration
545         static ShibConfig& getConfig();
546     };
547
548     /* Helper classes for implementing reloadable XML-based config files
549        The ILockable interface will usually be inherited twice, once as
550        part of the external interface to clients and once as an implementation
551        detail of the reloading class below.
552      */
553     
554     class SHIB_EXPORTS ReloadableXMLFileImpl
555     {
556     public:
557         ReloadableXMLFileImpl(const char* pathname);
558         ReloadableXMLFileImpl(const DOMElement* pathname);
559         virtual ~ReloadableXMLFileImpl();
560         
561     protected:
562         DOMDocument* m_doc;
563         const DOMElement* m_root;
564     };
565
566     class SHIB_EXPORTS ReloadableXMLFile : protected virtual saml::ILockable
567     {
568     public:
569         ReloadableXMLFile(const DOMElement* e);
570         ~ReloadableXMLFile() { delete m_lock; delete m_impl; }
571
572         virtual void lock();
573         virtual void unlock() { if (m_lock) m_lock->unlock(); }
574
575         ReloadableXMLFileImpl* getImplementation() const;
576
577     protected:
578         virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const=0;
579         virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const=0;
580         mutable ReloadableXMLFileImpl* m_impl;
581         
582     private:
583         const DOMElement* m_root;
584         std::string m_source;
585         time_t m_filestamp;
586         RWLock* m_lock;
587     };
588 }
589
590 #endif