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