Add accessor for feature bitmask.
[shibboleth/sp.git] / shibsp / SPConfig.h
1 /*
2  *  Copyright 2001-2010 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 #include <string>
29 #ifndef SHIBSP_LITE
30 # include <saml/binding/MessageDecoder.h>
31 # include <saml/binding/MessageEncoder.h>
32 #endif
33 #include <xmltooling/PluginManager.h>
34 #include <xmltooling/QName.h>
35 #include <xercesc/dom/DOM.hpp>
36
37 /**
38  * @namespace shibsp
39  * Shibboleth Service Provider Library
40  */
41 namespace shibsp {
42
43     class SHIBSP_API AccessControl;
44     class SHIBSP_API Handler;
45     class SHIBSP_API ListenerService;
46     class SHIBSP_API RequestMapper;
47     class SHIBSP_API ProtocolProvider;
48     class SHIBSP_API ServiceProvider;
49     class SHIBSP_API SessionCache;
50     class SHIBSP_API SessionInitiator;
51
52 #ifndef SHIBSP_LITE
53     class SHIBSP_API AttributeDecoder;
54     class SHIBSP_API AttributeExtractor;
55     class SHIBSP_API AttributeFilter;
56     class SHIBSP_API AttributeResolver;
57     class SHIBSP_API FilterPolicyContext;
58     class SHIBSP_API MatchFunctor;
59     class SHIBSP_API SecurityPolicyProvider;
60 #endif
61
62 #if defined (_MSC_VER)
63     #pragma warning( push )
64     #pragma warning( disable : 4250 4251 )
65 #endif
66
67     /**
68      * Singleton object that manages library startup/shutdown.
69      */
70     class SHIBSP_API SPConfig
71     {
72         MAKE_NONCOPYABLE(SPConfig);
73     public:
74         SPConfig();
75
76         virtual ~SPConfig();
77
78         /**
79          * Returns the global configuration object for the library.
80          *
81          * @return reference to the global library configuration object
82          */
83         static SPConfig& getConfig();
84
85         /**
86          * Bitmask values representing subsystems of the library.
87          */
88         enum components_t {
89             Listener = 1,
90             Caching = 2,
91 #ifndef SHIBSP_LITE
92             Metadata = 4,
93             Trust = 8,
94             Credentials = 16,
95             AttributeResolution = 32,
96 #endif
97             RequestMapping = 64,
98             OutOfProcess = 128,
99             InProcess = 256,
100             Logging = 512,
101             Handlers = 1024
102         };
103
104         /**
105          * Set a bitmask of subsystems to activate.
106          *
107          * @param enabled   bitmask of component constants
108          */
109         void setFeatures(unsigned long enabled);
110
111
112         /**
113          * Gets the bitmask of subsystems being activated.
114          *
115          * @return bitmask of component constants
116          */
117         unsigned long getFeatures() const;
118
119         /**
120          * Test whether a subsystem is enabled.
121          *
122          * @param feature   subsystem/component to test
123          * @return true iff feature is enabled
124          */
125         bool isEnabled(components_t feature) const;
126
127         /**
128          * Initializes library
129          *
130          * Each process using the library MUST call this function exactly once
131          * before using any library classes.
132          *
133          * @param catalog_path  delimited set of schema catalog files to load
134          * @param inst_prefix   installation prefix for software
135          * @return true iff initialization was successful
136          */
137         virtual bool init(const char* catalog_path=nullptr, const char* inst_prefix=nullptr);
138
139         /**
140          * Shuts down library
141          *
142          * Each process using the library SHOULD call this function exactly once
143          * before terminating itself.
144          */
145         virtual void term();
146
147         /**
148          * Sets the global ServiceProvider instance.
149          * This method must be externally synchronized with any code that uses the object.
150          * Any previously set object is destroyed.
151          *
152          * @param serviceProvider   new ServiceProvider instance to store
153          */
154         void setServiceProvider(ServiceProvider* serviceProvider);
155
156         /**
157          * Returns the global ServiceProvider instance.
158          *
159          * @return  global ServiceProvider or nullptr
160          */
161         ServiceProvider* getServiceProvider() const;
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=nullptr, 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
184         /**
185          * Returns the global ArtifactResolver instance.
186          *
187          * @return  global ArtifactResolver or nullptr
188          */
189         const opensaml::MessageDecoder::ArtifactResolver* getArtifactResolver() const;
190 #endif
191
192         /** Separator for serialized values of multi-valued attributes. */
193         char attribute_value_delimeter;
194
195         /**
196          * Manages factories for AccessControl plugins.
197          */
198         xmltooling::PluginManager<AccessControl,std::string,const xercesc::DOMElement*> AccessControlManager;
199
200 #ifndef SHIBSP_LITE
201         /**
202          * Manages factories for AttributeDecoder plugins.
203          */
204         xmltooling::PluginManager<AttributeDecoder,xmltooling::QName,const xercesc::DOMElement*> AttributeDecoderManager;
205
206         /**
207          * Manages factories for AttributeExtractor plugins.
208          */
209         xmltooling::PluginManager<AttributeExtractor,std::string,const xercesc::DOMElement*> AttributeExtractorManager;
210
211         /**
212          * Manages factories for AttributeFilter plugins.
213          */
214         xmltooling::PluginManager<AttributeFilter,std::string,const xercesc::DOMElement*> AttributeFilterManager;
215
216         /**
217          * Manages factories for AttributeResolver plugins.
218          */
219         xmltooling::PluginManager<AttributeResolver,std::string,const xercesc::DOMElement*> AttributeResolverManager;
220
221         /**
222          * Manages factories for MatchFunctor plugins.
223          */
224         xmltooling::PluginManager< MatchFunctor,xmltooling::QName,std::pair<const FilterPolicyContext*,const xercesc::DOMElement*> > MatchFunctorManager;
225
226         /**
227          * Manages factories for SecurityPolicyProvider plugins.
228          */
229         xmltooling::PluginManager<SecurityPolicyProvider,std::string,const xercesc::DOMElement*> SecurityPolicyProviderManager;
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 ProtocolProvider plugins.
264          */
265         xmltooling::PluginManager<ProtocolProvider,std::string,const xercesc::DOMElement*> ProtocolProviderManager;
266
267         /**
268          * Manages factories for RequestMapper plugins.
269          */
270         xmltooling::PluginManager<RequestMapper,std::string,const xercesc::DOMElement*> RequestMapperManager;
271
272         /**
273          * Manages factories for ServiceProvider plugins.
274          */
275         xmltooling::PluginManager<ServiceProvider,std::string,const xercesc::DOMElement*> ServiceProviderManager;
276
277         /**
278          * Manages factories for SessionCache plugins.
279          */
280         xmltooling::PluginManager<SessionCache,std::string,const xercesc::DOMElement*> SessionCacheManager;
281
282         /**
283          * Manages factories for Handler plugins that implement SessionInitiator functionality.
284          */
285         xmltooling::PluginManager< SessionInitiator,std::string,std::pair<const xercesc::DOMElement*,const char*> > SessionInitiatorManager;
286
287         /**
288          * Manages factories for Handler plugins that implement SingleLogoutService functionality.
289          */
290         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > SingleLogoutServiceManager;
291
292     protected:
293         /** Global ServiceProvider instance. */
294         ServiceProvider* m_serviceProvider;
295
296 #ifndef SHIBSP_LITE
297         /** Global ArtifactResolver instance. */
298         opensaml::MessageDecoder::ArtifactResolver* m_artifactResolver;
299 #endif
300
301     private:
302         unsigned long m_features;
303         xercesc::DOMDocument* m_configDoc;
304     };
305
306 #if defined (_MSC_VER)
307     #pragma warning( pop )
308 #endif
309
310 };
311
312 #endif /* __shibsp_config_h__ */