118467fe9cfaf5040658b2fdf9fa1ea756957ade
[shibboleth/sp.git] / shibsp / Application.h
1 /*
2  *  Copyright 2001-2007 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
37 namespace shibsp {
38     
39 #ifndef SHIBSP_LITE
40     class SHIBSP_API AttributeExtractor;
41     class SHIBSP_API AttributeFilter;
42     class SHIBSP_API AttributeResolver;
43 #endif
44     class SHIBSP_API Handler;
45     class SHIBSP_API ServiceProvider;
46     class SHIBSP_API SessionInitiator;
47     class SHIBSP_API SPRequest;
48
49     /**
50      * Interface to a Shibboleth Application instance.
51      * 
52      * <p>An Application is a logical set of resources that act as a unit
53      * of session management and policy.
54      */
55     class SHIBSP_API Application : public virtual PropertySet
56 #ifndef SHIBSP_LITE
57         ,public virtual opensaml::MessageEncoder::ArtifactGenerator
58 #endif
59     {
60         MAKE_NONCOPYABLE(Application);
61     protected:
62         Application() {}
63     public:
64         virtual ~Application() {}
65
66         /**
67          * Returns the owning ServiceProvider instance.
68          *
69          * @return a locked ServiceProvider
70          */
71         virtual const ServiceProvider& getServiceProvider() const=0;
72
73         /**
74          * Returns the Application's ID.
75          * 
76          * @return  the ID
77          */        
78         virtual const char* getId() const=0;
79
80         /**
81          * Returns a unique hash for the Application.
82          * 
83          * @return a value resulting from a computation over the Application's configuration
84          */
85         virtual const char* getHash() const=0;
86
87         /**
88          * Returns the name and cookie properties to use for this Application.
89          * 
90          * @param prefix    a value to prepend to the base cookie name
91          * @return  a pair containing the cookie name and the string to append to the cookie value
92          */
93         virtual std::pair<std::string,const char*> getCookieNameProps(const char* prefix) const;
94
95 #ifndef SHIBSP_LITE
96         /**
97          * Returns a MetadataProvider for use with this Application.
98          * 
99          * @param required  true iff an exception should be thrown if no MetadataProvider is available
100          * @return  a MetadataProvider instance, or NULL
101          */
102         virtual opensaml::saml2md::MetadataProvider* getMetadataProvider(bool required=true) const=0;
103         
104         /**
105          * Returns a TrustEngine for use with this Application.
106          * 
107          * @param required  true iff an exception should be thrown if no TrustEngine is available
108          * @return  a TrustEngine instance, or NULL
109          */
110         virtual xmltooling::TrustEngine* getTrustEngine(bool required=true) const=0;
111
112         /**
113          * Returns an AttributeExtractor for use with this Application.
114          * 
115          * @return  an AttributeExtractor, or NULL
116          */
117         virtual AttributeExtractor* getAttributeExtractor() const=0;
118
119         /**
120          * Returns an AttributeFilter for use with this Application.
121          * 
122          * @return  an AttributeFilter, or NULL
123          */
124         virtual AttributeFilter* getAttributeFilter() const=0;
125
126         /**
127          * Returns an AttributeResolver for use with this Application.
128          * 
129          * @return  an AttributeResolver, or NULL
130          */
131         virtual AttributeResolver* getAttributeResolver() const=0;
132
133         /**
134          * Returns the CredentialResolver instance associated with this Application.
135          * 
136          * @return  a CredentialResolver, or NULL
137          */
138         virtual xmltooling::CredentialResolver* getCredentialResolver() const=0;
139
140         /**
141          * Returns configuration properties governing security interactions with a peer.
142          * 
143          * @param provider  a peer entity's metadata
144          * @return  the applicable PropertySet
145          */
146         virtual const PropertySet* getRelyingParty(const opensaml::saml2md::EntityDescriptor* provider) const=0;
147
148         /**
149          * Returns the set of audience values associated with this Application.
150          * 
151          * @return set of audience values associated with the Application
152          */
153         virtual const std::vector<const XMLCh*>& getAudiences() const=0;
154 #endif
155
156         /**
157          * Returns the designated notification URL, or an empty string if no more locations are specified.
158          *
159          * @param request   requested URL to use to fill in missing pieces of notification URL
160          * @param front     true iff front channel notification is desired, false iff back channel is desired
161          * @param index     zero-based index of URL to return
162          * @return  the designated URL, or an empty string
163          */
164         virtual std::string getNotificationURL(const char* request, bool front, unsigned int index) const=0;
165
166         /**
167          * Returns a set of attribute IDs to use as a REMOTE_USER value.
168          * <p>The first attribute with a value (and only a single value) will be used.
169          *
170          * @return  a set of attribute IDs, or an empty set
171          */
172         virtual const std::set<std::string>& getRemoteUserAttributeIds() const=0;
173
174         /**
175          * Clears any headers that may be used to hold attributes after export.
176          *
177          * @param request   SP request to clear
178          */
179         virtual void clearAttributeHeaders(SPRequest& request) const=0;
180
181         /**
182          * Returns the default SessionInitiator when automatically requesting a session.
183          * 
184          * @return the default SessionInitiator, or NULL
185          */
186         virtual const SessionInitiator* getDefaultSessionInitiator() const=0;
187         
188         /**
189          * Returns a SessionInitiator with a particular ID when automatically requesting a session.
190          * 
191          * @param id    an identifier unique to the Application
192          * @return the designated SessionInitiator, or NULL
193          */
194         virtual const SessionInitiator* getSessionInitiatorById(const char* id) const=0;
195
196         /**
197          * Returns the default AssertionConsumerService Handler
198          * for use in AuthnRequest messages.
199          * 
200          * @return the default AssertionConsumerService, or NULL
201          */
202         virtual const Handler* getDefaultAssertionConsumerService() const=0;
203
204         /**
205          * Returns an AssertionConsumerService Handler with a particular index
206          * for use in AuthnRequest messages.
207          * 
208          * @param index an index unique to an application
209          * @return the designated AssertionConsumerService, or NULL
210          */
211         virtual const Handler* getAssertionConsumerServiceByIndex(unsigned short index) const=0;
212
213         /**
214          * Returns one or more AssertionConsumerService Handlers that support
215          * a particular protocol binding.
216          * 
217          * @param binding   a protocol binding identifier
218          * @return a set of qualifying AssertionConsumerServices
219          */
220         virtual const std::vector<const Handler*>& getAssertionConsumerServicesByBinding(const XMLCh* binding) const=0;
221         
222         /**
223          * Returns the Handler associated with a particular path/location.
224          * 
225          * @param path  the PATH_INFO appended to the end of a base Handler location
226          *              that invokes the Handler
227          * @return the mapped Handler, or NULL 
228          */
229         virtual const Handler* getHandler(const char* path) const=0;
230     };
231 };
232
233 #endif /* __shibsp_app_h__ */