Move to a "prefixed" model for metadata attributes and separate from session.
[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 #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         /** Cache of entity attributes. */
83         mutable std::map< std::string,std::multimap<std::string,const Attribute*> > m_entityAttributes;
84
85         /** Pairs of raw and normalized CGI header names to clear. */
86         mutable std::vector< std::pair<std::string,std::string> > m_unsetHeaders;
87
88     public:
89         virtual ~Application();
90
91         /**
92          * Returns the owning ServiceProvider instance.
93          *
94          * @return a locked ServiceProvider
95          */
96         const ServiceProvider& getServiceProvider() const {
97             return *m_sp;
98         }
99
100         /**
101          * Returns the Application's ID.
102          * 
103          * @return  the ID
104          */        
105         virtual const char* getId() const {
106             return getString("id").second;
107         }
108
109         /**
110          * Returns a unique hash for the Application.
111          * 
112          * @return a value resulting from a computation over the Application's configuration
113          */
114         virtual const char* getHash() const=0;
115
116         /**
117          * Returns the name and cookie properties to use for this Application.
118          * 
119          * @param prefix    a value to prepend to the base cookie name
120          * @return  a pair containing the cookie name and the string to append to the cookie value
121          */
122         virtual std::pair<std::string,const char*> getCookieNameProps(const char* prefix) const;
123
124 #ifndef SHIBSP_LITE
125         /**
126          * Returns a MetadataProvider for use with this Application.
127          * 
128          * @param required  true iff an exception should be thrown if no MetadataProvider is available
129          * @return  a MetadataProvider instance, or NULL
130          */
131         virtual opensaml::saml2md::MetadataProvider* getMetadataProvider(bool required=true) const=0;
132         
133         /**
134          * Returns a TrustEngine for use with this Application.
135          * 
136          * @param required  true iff an exception should be thrown if no TrustEngine is available
137          * @return  a TrustEngine instance, or NULL
138          */
139         virtual xmltooling::TrustEngine* getTrustEngine(bool required=true) const=0;
140
141         /**
142          * Returns an AttributeExtractor for use with this Application.
143          * 
144          * @return  an AttributeExtractor, or NULL
145          */
146         virtual AttributeExtractor* getAttributeExtractor() const=0;
147
148         /**
149          * Returns an AttributeFilter for use with this Application.
150          * 
151          * @return  an AttributeFilter, or NULL
152          */
153         virtual AttributeFilter* getAttributeFilter() const=0;
154
155         /**
156          * Returns an AttributeResolver for use with this Application.
157          * 
158          * @return  an AttributeResolver, or NULL
159          */
160         virtual AttributeResolver* getAttributeResolver() const=0;
161
162         /**
163          * Returns the CredentialResolver instance associated with this Application.
164          * 
165          * @return  a CredentialResolver, or NULL
166          */
167         virtual xmltooling::CredentialResolver* getCredentialResolver() const=0;
168
169         /**
170          * Returns configuration properties governing security interactions with a peer.
171          * 
172          * @param provider  a peer entity's metadata
173          * @return  the applicable PropertySet
174          */
175         virtual const PropertySet* getRelyingParty(const opensaml::saml2md::EntityDescriptor* provider) const=0;
176
177         /**
178          * Returns the set of audience values associated with this Application.
179          * 
180          * @return set of audience values associated with the Application
181          */
182         virtual const std::vector<const XMLCh*>& getAudiences() const=0;
183 #endif
184
185         /**
186          * Returns the designated notification URL, or an empty string if no more locations are specified.
187          *
188          * @param request   requested URL to use to fill in missing pieces of notification URL
189          * @param front     true iff front channel notification is desired, false iff back channel is desired
190          * @param index     zero-based index of URL to return
191          * @return  the designated URL, or an empty string
192          */
193         virtual std::string getNotificationURL(const char* request, bool front, unsigned int index) const=0;
194
195         /**
196          * Returns a set of attribute IDs to use as a REMOTE_USER value.
197          * <p>The first attribute with a value (and only a single value) will be used.
198          *
199          * @return  a set of attribute IDs, or an empty set
200          */
201         virtual const std::set<std::string>& getRemoteUserAttributeIds() const=0;
202
203         /**
204          * Clears any headers that may be used to hold attributes after export.
205          *
206          * @param request   SP request to clear
207          */
208         virtual void clearAttributeHeaders(SPRequest& request) const;
209
210         /**
211          * Returns an indexed set of attributes associated with an entity (as opposed to a user).
212          *
213          * @param entityID  unique ID of entity
214          * @return a map of attributes keyed by their ID
215          */
216         virtual const std::multimap<std::string,const Attribute*>& getEntityAttributes(const char* entityID) const;
217
218         /**
219          * Returns the default SessionInitiator when automatically requesting a session.
220          * 
221          * @return the default SessionInitiator, or NULL
222          */
223         virtual const SessionInitiator* getDefaultSessionInitiator() const=0;
224         
225         /**
226          * Returns a SessionInitiator with a particular ID when automatically requesting a session.
227          * 
228          * @param id    an identifier unique to the Application
229          * @return the designated SessionInitiator, or NULL
230          */
231         virtual const SessionInitiator* getSessionInitiatorById(const char* id) const=0;
232
233         /**
234          * Returns the default AssertionConsumerService Handler
235          * for use in AuthnRequest messages.
236          * 
237          * @return the default AssertionConsumerService, or NULL
238          */
239         virtual const Handler* getDefaultAssertionConsumerService() const=0;
240
241         /**
242          * Returns an AssertionConsumerService Handler with a particular index
243          * for use in AuthnRequest messages.
244          * 
245          * @param index an index unique to an application
246          * @return the designated AssertionConsumerService, or NULL
247          */
248         virtual const Handler* getAssertionConsumerServiceByIndex(unsigned short index) const=0;
249
250         /**
251          * Returns one or more AssertionConsumerService Handlers that support
252          * a particular protocol binding.
253          * 
254          * @param binding   a protocol binding identifier
255          * @return a set of qualifying AssertionConsumerServices
256          */
257         virtual const std::vector<const Handler*>& getAssertionConsumerServicesByBinding(const XMLCh* binding) const=0;
258         
259         /**
260          * Returns the Handler associated with a particular path/location.
261          * 
262          * @param path  the PATH_INFO appended to the end of a base Handler location
263          *              that invokes the Handler
264          * @return the mapped Handler, or NULL 
265          */
266         virtual const Handler* getHandler(const char* path) const=0;
267     };
268
269 #if defined (_MSC_VER)
270     #pragma warning( pop )
271 #endif
272
273 };
274
275 #endif /* __shibsp_app_h__ */