Fix catalog usage, checked in resolver schema.
[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 #include <xmltooling/PluginManager.h>
28 #include <xercesc/dom/DOM.hpp>
29
30 /**
31  * @namespace shibsp
32  * Shibboleth Service Provider Library
33  */
34 namespace shibsp {
35
36     class SHIBSP_API AccessControl;
37     class SHIBSP_API AttributeDecoder;
38     class SHIBSP_API Handler;
39     class SHIBSP_API ListenerService;
40     class SHIBSP_API RequestMapper;
41     class SHIBSP_API ServiceProvider;
42     class SHIBSP_API SessionCache;
43
44 #if defined (_MSC_VER)
45     #pragma warning( push )
46     #pragma warning( disable : 4250 4251 )
47 #endif
48
49     /**
50      * Singleton object that manages library startup/shutdown.
51      */
52     class SHIBSP_API SPConfig
53     {
54     MAKE_NONCOPYABLE(SPConfig);
55     public:
56         virtual ~SPConfig() {}
57
58         /**
59          * Returns the global configuration object for the library.
60          * 
61          * @return reference to the global library configuration object
62          */
63         static SPConfig& getConfig();
64
65         /**
66          * Bitmask values representing subsystems of the library.
67          */
68         enum components_t {
69             Listener = 1,
70             Caching = 2,
71             Metadata = 4,
72             Trust = 8,
73             Credentials = 16,
74             AttributeResolver = 32,
75             RequestMapping = 64,
76             OutOfProcess = 128,
77             InProcess = 256,
78             Logging = 512
79         };
80         
81         /**
82          * Set a bitmask of subsystems to activate.
83          * 
84          * @param enabled   bitmask of component constants
85          */
86         void setFeatures(unsigned long enabled) {
87             m_features = enabled;
88         }
89
90         /**
91          * Test whether a subsystem is enabled.
92          * 
93          * @param feature   subsystem/component to test
94          * @return true iff feature is enabled
95          */
96         bool isEnabled(components_t feature) {
97             return (m_features & feature)>0;
98         }
99         
100         /**
101          * Initializes library
102          * 
103          * Each process using the library MUST call this function exactly once
104          * before using any library classes.
105          * 
106          * @param catalog_path  delimited set of schema catalog files to load
107          * @return true iff initialization was successful 
108          */
109         virtual bool init(const char* catalog_path)=0;
110         
111         /**
112          * Shuts down library
113          * 
114          * Each process using the library SHOULD call this function exactly once
115          * before terminating itself.
116          */
117         virtual void term()=0;
118         
119         /**
120          * Sets the global ServiceProvider instance.
121          * This method must be externally synchronized with any code that uses the object.
122          * Any previously set object is destroyed.
123          * 
124          * @param serviceProvider   new ServiceProvider instance to store
125          */
126         void setServiceProvider(ServiceProvider* serviceProvider);
127         
128         /**
129          * Returns the global ServiceProvider instance.
130          * 
131          * @return  global ServiceProvider or NULL
132          */
133         ServiceProvider* getServiceProvider() const {
134             return m_serviceProvider;
135         }
136
137         /** Separator for serialized values of multi-valued attributes. */
138         char attribute_value_delimeter;
139         
140         /**
141          * Manages factories for AccessControl plugins.
142          */
143         xmltooling::PluginManager<AccessControl,const xercesc::DOMElement*> AccessControlManager;
144
145         /**
146          * Manages factories for AttributeDecoder plugins.
147          */
148         xmltooling::PluginManager<AttributeDecoder,const xercesc::DOMElement*> AttributeDecoderManager;
149
150         /**
151          * Manages factories for Handler plugins that implement AssertionConsumerService functionality.
152          */
153         xmltooling::PluginManager<Handler,const xercesc::DOMElement*> AssertionConsumerServiceManager;
154
155         /**
156          * Manages factories for Handler plugins that implement customized functionality.
157          */
158         xmltooling::PluginManager<Handler,const xercesc::DOMElement*> HandlerManager;
159
160         /**
161          * Manages factories for ListenerService plugins.
162          */
163         xmltooling::PluginManager<ListenerService,const xercesc::DOMElement*> ListenerServiceManager;
164
165         /**
166          * Manages factories for Handler plugins that implement ManageNameIDService functionality.
167          */
168         xmltooling::PluginManager<Handler,const xercesc::DOMElement*> ManageNameIDServiceManager;
169
170         /**
171          * Manages factories for RequestMapper plugins.
172          */
173         xmltooling::PluginManager<RequestMapper,const xercesc::DOMElement*> RequestMapperManager;
174
175         /**
176          * Manages factories for ServiceProvider plugins.
177          */
178         xmltooling::PluginManager<ServiceProvider,const xercesc::DOMElement*> ServiceProviderManager;
179
180         /**
181          * Manages factories for SessionCache plugins.
182          */
183         xmltooling::PluginManager<SessionCache,const xercesc::DOMElement*> SessionCacheManager;
184
185         /**
186          * Manages factories for Handler plugins that implement SessionInitiator functionality.
187          */
188         xmltooling::PluginManager<Handler,const xercesc::DOMElement*> SessionInitiatorManager;
189
190         /**
191          * Manages factories for Handler plugins that implement SingleLogoutService functionality.
192          */
193         xmltooling::PluginManager<Handler,const xercesc::DOMElement*> SingleLogoutServiceManager;
194
195     protected:
196         SPConfig() : attribute_value_delimeter(';'), m_serviceProvider(NULL), m_features(0) {}
197         
198         /** Global ServiceProvider instance. */
199         ServiceProvider* m_serviceProvider;
200
201     private:
202         unsigned long m_features;
203     };
204
205 #if defined (_MSC_VER)
206     #pragma warning( pop )
207 #endif
208
209 };
210
211 #endif /* __shibsp_config_h__ */