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