75cac61f6da183e33031ffeaf7c5c97c48d136f1
[shibboleth/sp.git] / shibsp / SPConfig.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/SPConfig.h
19  * 
20  * Library configuration 
21  */
22
23 #ifndef __shibsp_config_h__
24 #define __shibsp_config_h__
25
26 #include <shibsp/base.h>
27 #ifndef SHIBSP_LITE
28 # include <saml/binding/MessageDecoder.h>
29 #endif
30 #include <xmltooling/PluginManager.h>
31 #include <xercesc/dom/DOM.hpp>
32
33 /**
34  * @namespace shibsp
35  * Shibboleth Service Provider Library
36  */
37 namespace shibsp {
38
39     class SHIBSP_API AccessControl;
40     class SHIBSP_API Handler;
41     class SHIBSP_API ListenerService;
42     class SHIBSP_API RequestMapper;
43     class SHIBSP_API ServiceProvider;
44     class SHIBSP_API SessionCache;
45     class SHIBSP_API SessionInitiator;
46
47 #ifndef SHIBSP_LITE
48     class SHIBSP_API AttributeDecoder;
49     class SHIBSP_API AttributeExtractor;
50     class SHIBSP_API AttributeFilter;
51     class SHIBSP_API AttributeResolver;
52     class SHIBSP_API FilterPolicyContext;
53     class SHIBSP_API MatchFunctor;
54 #endif
55
56 #if defined (_MSC_VER)
57     #pragma warning( push )
58     #pragma warning( disable : 4250 4251 )
59 #endif
60
61     /**
62      * Singleton object that manages library startup/shutdown.
63      */
64     class SHIBSP_API SPConfig
65     {
66     MAKE_NONCOPYABLE(SPConfig);
67     public:
68         virtual ~SPConfig() {}
69
70         /**
71          * Returns the global configuration object for the library.
72          * 
73          * @return reference to the global library configuration object
74          */
75         static SPConfig& getConfig();
76
77         /**
78          * Bitmask values representing subsystems of the library.
79          */
80         enum components_t {
81             Listener = 1,
82             Caching = 2,
83 #ifndef SHIBSP_LITE
84             Metadata = 4,
85             Trust = 8,
86             Credentials = 16,
87             AttributeResolution = 32,
88 #endif
89             RequestMapping = 64,
90             OutOfProcess = 128,
91             InProcess = 256,
92             Logging = 512,
93             Handlers = 1024
94         };
95         
96         /**
97          * Set a bitmask of subsystems to activate.
98          * 
99          * @param enabled   bitmask of component constants
100          */
101         void setFeatures(unsigned long enabled) {
102             m_features = enabled;
103         }
104
105         /**
106          * Test whether a subsystem is enabled.
107          * 
108          * @param feature   subsystem/component to test
109          * @return true iff feature is enabled
110          */
111         bool isEnabled(components_t feature) {
112             return (m_features & feature)>0;
113         }
114         
115         /**
116          * Initializes library
117          * 
118          * Each process using the library MUST call this function exactly once
119          * before using any library classes.
120          * 
121          * @param catalog_path  delimited set of schema catalog files to load
122          * @return true iff initialization was successful 
123          */
124         virtual bool init(const char* catalog_path)=0;
125         
126         /**
127          * Shuts down library
128          * 
129          * Each process using the library SHOULD call this function exactly once
130          * before terminating itself.
131          */
132         virtual void term()=0;
133         
134         /**
135          * Sets the global ServiceProvider instance.
136          * This method must be externally synchronized with any code that uses the object.
137          * Any previously set object is destroyed.
138          * 
139          * @param serviceProvider   new ServiceProvider instance to store
140          */
141         void setServiceProvider(ServiceProvider* serviceProvider);
142         
143         /**
144          * Returns the global ServiceProvider instance.
145          * 
146          * @return  global ServiceProvider or NULL
147          */
148         ServiceProvider* getServiceProvider() const {
149             return m_serviceProvider;
150         }
151
152 #ifndef SHIBSP_LITE
153         /**
154          * Sets the global ArtifactResolver instance.
155          *
156          * <p>This method must be externally synchronized with any code that uses the object.
157          * Any previously set object is destroyed.
158          * 
159          * @param artifactResolver   new ArtifactResolver instance to store
160          */
161         void setArtifactResolver(opensaml::MessageDecoder::ArtifactResolver* artifactResolver) {
162             delete m_artifactResolver;
163             m_artifactResolver = artifactResolver;
164         }
165         
166         /**
167          * Returns the global ArtifactResolver instance.
168          * 
169          * @return  global ArtifactResolver or NULL
170          */
171         opensaml::MessageDecoder::ArtifactResolver* getArtifactResolver() const {
172             return m_artifactResolver;
173         }
174 #endif
175
176         /** Separator for serialized values of multi-valued attributes. */
177         char attribute_value_delimeter;
178         
179         /**
180          * Manages factories for AccessControl plugins.
181          */
182         xmltooling::PluginManager<AccessControl,std::string,const xercesc::DOMElement*> AccessControlManager;
183
184 #ifndef SHIBSP_LITE
185         /**
186          * Manages factories for AttributeDecoder plugins.
187          */
188         xmltooling::PluginManager<AttributeDecoder,xmltooling::QName,const xercesc::DOMElement*> AttributeDecoderManager;
189
190         /**
191          * Manages factories for AttributeExtractor plugins.
192          */
193         xmltooling::PluginManager<AttributeExtractor,std::string,const xercesc::DOMElement*> AttributeExtractorManager;
194
195         /**
196          * Manages factories for AttributeFilter plugins.
197          */
198         xmltooling::PluginManager<AttributeFilter,std::string,const xercesc::DOMElement*> AttributeFilterManager;
199
200         /**
201          * Manages factories for AttributeResolver plugins.
202          */
203         xmltooling::PluginManager<AttributeResolver,std::string,const xercesc::DOMElement*> AttributeResolverManager;
204
205         /**
206          * Manages factories for MatchFunctor plugins.
207          */
208         xmltooling::PluginManager< MatchFunctor,xmltooling::QName,std::pair<const FilterPolicyContext*,const xercesc::DOMElement*> > MatchFunctorManager;
209 #endif
210
211         /**
212          * Manages factories for Handler plugins that implement ArtifactResolutionService functionality.
213          */
214         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > ArtifactResolutionServiceManager;
215
216         /**
217          * Manages factories for Handler plugins that implement AssertionConsumerService functionality.
218          */
219         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > AssertionConsumerServiceManager;
220
221         /**
222          * Manages factories for Handler plugins that implement customized functionality.
223          */
224         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > HandlerManager;
225
226         /**
227          * Manages factories for ListenerService plugins.
228          */
229         xmltooling::PluginManager<ListenerService,std::string,const xercesc::DOMElement*> ListenerServiceManager;
230
231         /**
232          * Manages factories for Handler plugins that implement LogoutInitiator functionality.
233          */
234         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > LogoutInitiatorManager;
235
236         /**
237          * Manages factories for Handler plugins that implement ManageNameIDService functionality.
238          */
239         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > ManageNameIDServiceManager;
240
241         /**
242          * Manages factories for RequestMapper plugins.
243          */
244         xmltooling::PluginManager<RequestMapper,std::string,const xercesc::DOMElement*> RequestMapperManager;
245
246         /**
247          * Manages factories for ServiceProvider plugins.
248          */
249         xmltooling::PluginManager<ServiceProvider,std::string,const xercesc::DOMElement*> ServiceProviderManager;
250
251         /**
252          * Manages factories for SessionCache plugins.
253          */
254         xmltooling::PluginManager<SessionCache,std::string,const xercesc::DOMElement*> SessionCacheManager;
255
256         /**
257          * Manages factories for Handler plugins that implement SessionInitiator functionality.
258          */
259         xmltooling::PluginManager< SessionInitiator,std::string,std::pair<const xercesc::DOMElement*,const char*> > SessionInitiatorManager;
260
261         /**
262          * Manages factories for Handler plugins that implement SingleLogoutService functionality.
263          */
264         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > SingleLogoutServiceManager;
265
266     protected:
267         SPConfig() : attribute_value_delimeter(';'), m_serviceProvider(NULL),
268 #ifndef SHIBSP_LITE
269             m_artifactResolver(NULL),
270 #endif
271             m_features(0) {}
272         
273         /** Global ServiceProvider instance. */
274         ServiceProvider* m_serviceProvider;
275
276 #ifndef SHIBSP_LITE
277         /** Global ArtifactResolver instance. */
278         opensaml::MessageDecoder::ArtifactResolver* m_artifactResolver;
279 #endif
280
281     private:
282         unsigned long m_features;
283     };
284
285 #if defined (_MSC_VER)
286     #pragma warning( pop )
287 #endif
288
289 };
290
291 #endif /* __shibsp_config_h__ */