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