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