Imported Upstream version 2.2.1+dfsg
[shibboleth/sp.git] / shibsp / Application.h
1 /*
2  *  Copyright 2001-2009 Internet2
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file shibsp/Application.h
19  *
20  * Interface to a Shibboleth Application instance.
21  */
22
23 #ifndef __shibsp_app_h__
24 #define __shibsp_app_h__
25
26 #include <shibsp/util/PropertySet.h>
27
28 #include <set>
29 #ifndef SHIBSP_LITE
30 # include <saml/binding/MessageEncoder.h>
31 # include <saml/saml2/metadata/MetadataProvider.h>
32 # include <xmltooling/security/CredentialResolver.h>
33 # include <xmltooling/security/TrustEngine.h>
34 #endif
35 #include <xmltooling/io/HTTPRequest.h>
36 #include <xmltooling/util/Threads.h>
37
38 namespace shibsp {
39
40 #ifndef SHIBSP_LITE
41     class SHIBSP_API AttributeExtractor;
42     class SHIBSP_API AttributeFilter;
43     class SHIBSP_API AttributeResolver;
44 #endif
45     class SHIBSP_API Attribute;
46     class SHIBSP_API Handler;
47     class SHIBSP_API ServiceProvider;
48     class SHIBSP_API SessionInitiator;
49     class SHIBSP_API SPRequest;
50
51 #if defined (_MSC_VER)
52     #pragma warning( push )
53     #pragma warning( disable : 4251 )
54 #endif
55
56     /**
57      * Interface to a Shibboleth Application instance.
58      *
59      * <p>An Application is a logical set of resources that act as a unit
60      * of session management and policy.
61      */
62     class SHIBSP_API Application : public virtual PropertySet
63 #ifndef SHIBSP_LITE
64         ,public virtual opensaml::MessageEncoder::ArtifactGenerator
65 #endif
66     {
67         MAKE_NONCOPYABLE(Application);
68     protected:
69         /**
70          * Constructor.
71          *
72          * @param sp    parent ServiceProvider instance
73          */
74         Application(const ServiceProvider* sp);
75
76         /** Pointer to parent SP instance. */
77         const ServiceProvider* m_sp;
78
79         /** Shared lock for manipulating application state. */
80         mutable xmltooling::RWLock* m_lock;
81
82         /** Pairs of raw and normalized CGI header names to clear. */
83         mutable std::vector< std::pair<std::string,std::string> > m_unsetHeaders;
84
85     public:
86         virtual ~Application();
87
88         /**
89          * Returns the owning ServiceProvider instance.
90          *
91          * @return a locked ServiceProvider
92          */
93         const ServiceProvider& getServiceProvider() const {
94             return *m_sp;
95         }
96
97         /**
98          * Returns the Application's ID.
99          *
100          * @return  the ID
101          */
102         virtual const char* getId() const {
103             return getString("id").second;
104         }
105
106         /**
107          * Returns a unique hash for the Application.
108          *
109          * @return a value resulting from a computation over the Application's configuration
110          */
111         virtual const char* getHash() const=0;
112
113         /**
114          * Returns the name and cookie properties to use for this Application.
115          *
116          * @param prefix    a value to prepend to the base cookie name
117          * @param lifetime  if non-null, will be populated with a suggested lifetime for the cookie, or 0 if session-bound
118          * @return  a pair containing the cookie name and the string to append to the cookie value
119          */
120         virtual std::pair<std::string,const char*> getCookieNameProps(const char* prefix, time_t* lifetime=NULL) const;
121
122 #ifndef SHIBSP_LITE
123         /**
124          * Returns a MetadataProvider for use with this Application.
125          *
126          * @param required  true iff an exception should be thrown if no MetadataProvider is available
127          * @return  a MetadataProvider instance, or NULL
128          */
129         virtual opensaml::saml2md::MetadataProvider* getMetadataProvider(bool required=true) const=0;
130
131         /**
132          * Returns a TrustEngine for use with this Application.
133          *
134          * @param required  true iff an exception should be thrown if no TrustEngine is available
135          * @return  a TrustEngine instance, or NULL
136          */
137         virtual xmltooling::TrustEngine* getTrustEngine(bool required=true) const=0;
138
139         /**
140          * Returns an AttributeExtractor for use with this Application.
141          *
142          * @return  an AttributeExtractor, or NULL
143          */
144         virtual AttributeExtractor* getAttributeExtractor() const=0;
145
146         /**
147          * Returns an AttributeFilter for use with this Application.
148          *
149          * @return  an AttributeFilter, or NULL
150          */
151         virtual AttributeFilter* getAttributeFilter() const=0;
152
153         /**
154          * Returns an AttributeResolver for use with this Application.
155          *
156          * @return  an AttributeResolver, or NULL
157          */
158         virtual AttributeResolver* getAttributeResolver() const=0;
159
160         /**
161          * Returns the CredentialResolver instance associated with this Application.
162          *
163          * @return  a CredentialResolver, or NULL
164          */
165         virtual xmltooling::CredentialResolver* getCredentialResolver() const=0;
166
167         /**
168          * Returns configuration properties governing security interactions with a peer.
169          *
170          * @param provider  a peer entity's metadata
171          * @return  the applicable PropertySet
172          */
173         virtual const PropertySet* getRelyingParty(const opensaml::saml2md::EntityDescriptor* provider) const=0;
174
175         /**
176          * Returns configuration properties governing security interactions with a named peer.
177          *
178          * @param entityID  a peer name
179          * @return  the applicable PropertySet
180          */
181         virtual const PropertySet* getRelyingParty(const XMLCh* entityID) const=0;
182
183         /**
184          * @deprecated
185          * Returns any additional audience values associated with this Application.
186          *
187          * @return additional audience values associated with the Application, or NULL
188          */
189         virtual const std::vector<const XMLCh*>* getAudiences() const=0;
190 #endif
191
192         /**
193          * Returns the designated notification URL, or an empty string if no more locations are specified.
194          *
195          * @param request   requested URL to use to fill in missing pieces of notification URL
196          * @param front     true iff front channel notification is desired, false iff back channel is desired
197          * @param index     zero-based index of URL to return
198          * @return  the designated URL, or an empty string
199          */
200         virtual std::string getNotificationURL(const char* request, bool front, unsigned int index) const=0;
201
202         /**
203          * Returns an array of attribute IDs to use as a REMOTE_USER value, in order of preference.
204          *
205          * @return  an array of attribute IDs, possibly empty
206          */
207         virtual const std::vector<std::string>& getRemoteUserAttributeIds() const=0;
208
209         /**
210          * Ensures no value exists for a request header, allowing for application-specific customization.
211          *
212          * @param request  SP request to modify
213          * @param rawname  raw name of header to clear
214          * @param cginame  CGI-equivalent name of header, <strong>MUST</strong> begin with "HTTP_".
215          */
216         virtual void clearHeader(SPRequest& request, const char* rawname, const char* cginame) const;
217
218         /**
219          * Sets a value for a request header allowing for application-specific customization.
220          *
221          * @param request   SP request to modify
222          * @param name      name of header to set
223          * @param value     value to set
224          */
225         virtual void setHeader(SPRequest& request, const char* name, const char* value) const;
226
227         /**
228          * Returns a non-spoofable request header value allowing for application-specific customization.
229          *
230          * @param request   SP request to access
231          * @param name      the name of the secure header to return
232          * @return  the header's value, or an empty string
233          */
234         virtual std::string getSecureHeader(const SPRequest& request, const char* name) const;
235
236         /**
237          * Clears any headers that may be used to hold attributes after export.
238          *
239          * @param request   SP request to clear
240          */
241         virtual void clearAttributeHeaders(SPRequest& request) const;
242
243         /**
244          * Returns the default SessionInitiator when automatically requesting a session.
245          *
246          * @return the default SessionInitiator, or NULL
247          */
248         virtual const SessionInitiator* getDefaultSessionInitiator() const=0;
249
250         /**
251          * Returns a SessionInitiator with a particular ID when automatically requesting a session.
252          *
253          * @param id    an identifier unique to the Application
254          * @return the designated SessionInitiator, or NULL
255          */
256         virtual const SessionInitiator* getSessionInitiatorById(const char* id) const=0;
257
258         /**
259          * Returns the default AssertionConsumerService Handler
260          * for use in AuthnRequest messages.
261          *
262          * @return the default AssertionConsumerService, or NULL
263          */
264         virtual const Handler* getDefaultAssertionConsumerService() const=0;
265
266         /**
267          * Returns an AssertionConsumerService Handler with a particular index
268          * for use in AuthnRequest messages.
269          *
270          * @param index an index unique to an application
271          * @return the designated AssertionConsumerService, or NULL
272          */
273         virtual const Handler* getAssertionConsumerServiceByIndex(unsigned short index) const=0;
274
275         /**
276          * Returns one or more AssertionConsumerService Handlers that support
277          * a particular protocol binding.
278          *
279          * @param binding   a protocol binding identifier
280          * @return a set of qualifying AssertionConsumerServices
281          */
282         virtual const std::vector<const Handler*>& getAssertionConsumerServicesByBinding(const XMLCh* binding) const=0;
283
284         /**
285          * Returns the Handler associated with a particular path/location.
286          *
287          * @param path  the PATH_INFO appended to the end of a base Handler location
288          *              that invokes the Handler
289          * @return the mapped Handler, or NULL
290          */
291         virtual const Handler* getHandler(const char* path) const=0;
292
293         /**
294          * Returns all registered Handlers.
295          *
296          * @param handlers  array to populate
297          */
298         virtual void getHandlers(std::vector<const Handler*>& handlers) const=0;
299     };
300
301 #if defined (_MSC_VER)
302     #pragma warning( pop )
303 #endif
304
305 };
306
307 #endif /* __shibsp_app_h__ */