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