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