2d0694a2e982b294b6723a0af6fe0475b65255d7
[shibboleth/sp.git] / shibsp / ServiceProvider.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/ServiceProvider.h
19  * 
20  * Interface to a Shibboleth ServiceProvider instance.
21  */
22
23 #ifndef __shibsp_sp_h__
24 #define __shibsp_sp_h__
25
26 #include <shibsp/util/PropertySet.h>
27
28 #include <xmltooling/Lockable.h>
29
30 namespace xmltooling {
31     class XMLTOOL_API SOAPTransport;
32     class XMLTOOL_API StorageService;
33 };
34
35 #ifndef SHIBSP_LITE
36 namespace opensaml {
37     class SAML_API SecurityPolicyRule;
38 };
39 #endif
40
41 namespace shibsp {
42
43     class SHIBSP_API Application;
44     class SHIBSP_API Handler;
45     class SHIBSP_API ListenerService;
46     class SHIBSP_API RequestMapper;
47     class SHIBSP_API SessionCache;
48     class SHIBSP_API SPRequest;
49     class SHIBSP_API TemplateParameters;
50 #ifndef SHIBSP_LITE
51     class SHIBSP_API TransactionLog;
52 #endif
53
54     /**
55      * Interface to a Shibboleth ServiceProvider instance.
56      * 
57      * <p>A ServiceProvider exposes configuration and infrastructure services required
58      * by the SP implementation, allowing a flexible configuration format.
59      */
60         class SHIBSP_API ServiceProvider : public virtual xmltooling::Lockable, public virtual PropertySet
61     {
62         MAKE_NONCOPYABLE(ServiceProvider);
63     protected:
64         ServiceProvider();
65     public:
66         virtual ~ServiceProvider();
67         
68         /**
69          * Loads a configuration and prepares the instance for use.
70          * 
71          * <p>Implemented as a separate method so that services can rely on
72          * other services while they initialize by accessing the ServiceProvider
73          * from the SPConfig singleton.
74          */
75         virtual void init()=0;
76
77 #ifndef SHIBSP_LITE
78         /**
79          * Returns a TransactionLog instance.
80          * 
81          * @return  a TransactionLog instance
82          */
83         virtual TransactionLog* getTransactionLog() const=0;
84
85         /**
86          * Returns a StorageService instance based on an ID.
87          * 
88          * @param id    a NULL-terminated key identifying the StorageService to the configuration 
89          * @return  a StorageService if available, or NULL
90          */
91         virtual xmltooling::StorageService* getStorageService(const char* id) const=0;
92 #endif
93
94         /**
95          * Returns a SessionCache instance.
96          * 
97          * @param required  true iff an exception should be thrown if no SessionCache is available
98          * @return  a SessionCache
99          */
100         virtual SessionCache* getSessionCache(bool required=true) const=0;
101
102         /**
103          * Returns a ListenerService instance.
104          * 
105          * @param required  true iff an exception should be thrown if no ListenerService is available
106          * @return  a ListenerService
107          */
108         virtual ListenerService* getListenerService(bool required=true) const=0;
109         
110 #ifndef SHIBSP_LITE
111         /**
112                  * Returns the security policy settings for an identified policy.
113          *
114                  * @param id    identifies the policy to return
115          * @return a PropertySet
116                  */
117         virtual const PropertySet* getPolicySettings(const char* id) const=0;
118
119         /**
120                  * Returns the security policy rules for an identified policy.
121          *
122                  * @param id    identifies the policy to return
123          * @return an array of policy rules
124                  */
125         virtual const std::vector<const opensaml::SecurityPolicyRule*>& getPolicyRules(const char* id) const=0;
126
127         /**
128          * Sets implementation-specific transport options.
129          *
130          * @param transport a SOAPTransport object
131          * @return  true iff all options were successfully set
132          */
133         virtual bool setTransportOptions(xmltooling::SOAPTransport& transport) const=0;
134 #endif
135
136         /**
137          * Returns a RequestMapper instance.
138          * 
139          * @param required  true iff an exception should be thrown if no RequestMapper is available
140          * @return  a RequestMapper
141          */
142         virtual RequestMapper* getRequestMapper(bool required=true) const=0;
143         
144         /**
145          * Returns an Application instance matching the specified ID.
146          * 
147          * @param applicationId the ID of the application
148          * @return  pointer to the application, or NULL
149          */
150         virtual const Application* getApplication(const char* applicationId) const=0;
151
152         /**
153          * Enforces requirements for an authenticated session.
154          * 
155          * <p>If the return value's first member is true, then request processing should terminate
156          * with the second member as a status value. If false, processing can continue. 
157          * 
158          * @param request   SP request interface
159          * @param handler   true iff a request to a registered Handler location can be directly executed
160          * @return a pair containing a "request completed" indicator and a server-specific response code
161          */
162         virtual std::pair<bool,long> doAuthentication(SPRequest& request, bool handler=false) const;
163         
164         /**
165          * Enforces authorization requirements based on the authenticated session.
166          * 
167          * <p>If the return value's first member is true, then request processing should terminate
168          * with the second member as a status value. If false, processing can continue. 
169          * 
170          * @param request   SP request interface
171          * @return a pair containing a "request completed" indicator and a server-specific response code
172          */
173         virtual std::pair<bool,long> doAuthorization(SPRequest& request) const;
174         
175         /**
176          * Publishes session contents to the request in the form of headers or environment variables.
177          * 
178          * <p>If the return value's first member is true, then request processing should terminate
179          * with the second member as a status value. If false, processing can continue. 
180          * 
181          * @param request   SP request interface
182          * @param requireSession    set to true iff an error should result if no session exists 
183          * @return a pair containing a "request completed" indicator and a server-specific response code
184          */
185         virtual std::pair<bool,long> doExport(SPRequest& request, bool requireSession=true) const;
186
187         /**
188          * Services requests for registered Handler locations. 
189          * 
190          * <p>If the return value's first member is true, then request processing should terminate
191          * with the second member as a status value. If false, processing can continue. 
192          * 
193          * @param request   SP request interface
194          * @return a pair containing a "request completed" indicator and a server-specific response code
195          */
196         virtual std::pair<bool,long> doHandler(SPRequest& request) const;
197     };
198
199     /**
200      * Registers ServiceProvider classes into the runtime.
201      */
202     void SHIBSP_API registerServiceProviders();
203
204     /** SP based on integrated XML and native server configuration. */
205     #define XML_SERVICE_PROVIDER "XML"
206 };
207
208 #endif /* __shibsp_sp_h__ */