Use shibboleth-sp as package name for compatibility.
[shibboleth/cpp-sp.git] / shibsp / SPConfig.h
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * @file shibsp/SPConfig.h
23  *
24  * Library configuration.
25  */
26
27 #ifndef __shibsp_config_h__
28 #define __shibsp_config_h__
29
30 #include <shibsp/base.h>
31
32 #include <string>
33 #ifndef SHIBSP_LITE
34 # include <shibsp/TransactionLog.h>
35 # include <saml/binding/MessageDecoder.h>
36 # include <saml/binding/MessageEncoder.h>
37 #endif
38 #include <xmltooling/PluginManager.h>
39 #include <xmltooling/QName.h>
40 #include <xercesc/dom/DOM.hpp>
41
42 /**
43  * @namespace shibsp
44  * Shibboleth Service Provider Library
45  */
46 namespace shibsp {
47
48     class SHIBSP_API AccessControl;
49     class SHIBSP_API Handler;
50     class SHIBSP_API ListenerService;
51     class SHIBSP_API RequestMapper;
52     class SHIBSP_API ProtocolProvider;
53     class SHIBSP_API ServiceProvider;
54     class SHIBSP_API SessionCache;
55     class SHIBSP_API SessionInitiator;
56
57 #ifndef SHIBSP_LITE
58     class SHIBSP_API AttributeDecoder;
59     class SHIBSP_API AttributeExtractor;
60     class SHIBSP_API AttributeFilter;
61     class SHIBSP_API AttributeResolver;
62     class SHIBSP_API FilterPolicyContext;
63     class SHIBSP_API MatchFunctor;
64     class SHIBSP_API SecurityPolicyProvider;
65 #endif
66
67 #if defined (_MSC_VER)
68     #pragma warning( push )
69     #pragma warning( disable : 4250 4251 )
70 #endif
71
72     /**
73      * Singleton object that manages library startup/shutdown.
74      */
75     class SHIBSP_API SPConfig
76     {
77         MAKE_NONCOPYABLE(SPConfig);
78     public:
79         SPConfig();
80
81         virtual ~SPConfig();
82
83         /**
84          * Returns the global configuration object for the library.
85          *
86          * @return reference to the global library configuration object
87          */
88         static SPConfig& getConfig();
89
90         /**
91          * Bitmask values representing subsystems of the library.
92          */
93         enum components_t {
94             Listener = 1,
95             Caching = 2,
96 #ifndef SHIBSP_LITE
97             Metadata = 4,
98             Trust = 8,
99             Credentials = 16,
100             AttributeResolution = 32,
101 #endif
102             RequestMapping = 64,
103             OutOfProcess = 128,
104             InProcess = 256,
105             Logging = 512,
106             Handlers = 1024
107         };
108
109         /**
110          * Set a bitmask of subsystems to activate.
111          *
112          * @param enabled   bitmask of component constants
113          */
114         void setFeatures(unsigned long enabled);
115
116
117         /**
118          * Gets the bitmask of subsystems being activated.
119          *
120          * @return bitmask of component constants
121          */
122         unsigned long getFeatures() const;
123
124         /**
125          * Test whether a subsystem is enabled.
126          *
127          * @param feature   subsystem/component to test
128          * @return true iff feature is enabled
129          */
130         bool isEnabled(components_t feature) const;
131
132         /**
133          * Initializes library
134          *
135          * Each process using the library MUST call this function exactly once
136          * before using any library classes.
137          *
138          * @param catalog_path  delimited set of schema catalog files to load
139          * @param inst_prefix   installation prefix for software
140          * @return true iff initialization was successful
141          */
142         virtual bool init(const char* catalog_path=nullptr, const char* inst_prefix=nullptr);
143
144         /**
145          * Shuts down library
146          *
147          * Each process using the library SHOULD call this function exactly once
148          * before terminating itself.
149          */
150         virtual void term();
151
152         /**
153          * Sets the global ServiceProvider instance.
154          * This method must be externally synchronized with any code that uses the object.
155          * Any previously set object is destroyed.
156          *
157          * @param serviceProvider   new ServiceProvider instance to store
158          */
159         void setServiceProvider(ServiceProvider* serviceProvider);
160
161         /**
162          * Returns the global ServiceProvider instance.
163          *
164          * @return  global ServiceProvider or nullptr
165          */
166         ServiceProvider* getServiceProvider() const;
167
168         /**
169          * Instantiates and installs a ServiceProvider instance based on an XML configuration string
170          * or a configuration pathname.
171          *
172          * @param config    a snippet of XML to parse (it <strong>MUST</strong> contain a type attribute) or a pathname
173          * @param rethrow   true iff caught exceptions should be rethrown instead of just returning the status
174          * @return true iff instantiation was successful
175          */
176         virtual bool instantiate(const char* config=nullptr, bool rethrow=false);
177
178 #ifndef SHIBSP_LITE
179         /**
180          * Sets the global ArtifactResolver instance.
181          *
182          * <p>This method must be externally synchronized with any code that uses the object.
183          * Any previously set object is destroyed.
184          *
185          * @param artifactResolver   new ArtifactResolver instance to store
186          */
187         void setArtifactResolver(opensaml::MessageDecoder::ArtifactResolver* artifactResolver);
188
189         /**
190          * Returns the global ArtifactResolver instance.
191          *
192          * @return  global ArtifactResolver or nullptr
193          */
194         const opensaml::MessageDecoder::ArtifactResolver* getArtifactResolver() const;
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 Event plugins.
228          */
229         xmltooling::PluginManager<TransactionLog::Event,std::string,void*> EventManager;
230
231         /**
232          * Manages factories for MatchFunctor plugins.
233          */
234         xmltooling::PluginManager< MatchFunctor,xmltooling::QName,std::pair<const FilterPolicyContext*,const xercesc::DOMElement*> > MatchFunctorManager;
235
236         /**
237          * Manages factories for SecurityPolicyProvider plugins.
238          */
239         xmltooling::PluginManager<SecurityPolicyProvider,std::string,const xercesc::DOMElement*> SecurityPolicyProviderManager;
240 #endif
241
242         /**
243          * Manages factories for Handler plugins that implement ArtifactResolutionService functionality.
244          */
245         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > ArtifactResolutionServiceManager;
246
247         /**
248          * Manages factories for Handler plugins that implement AssertionConsumerService functionality.
249          */
250         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > AssertionConsumerServiceManager;
251
252         /**
253          * Manages factories for Handler plugins that implement customized functionality.
254          */
255         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > HandlerManager;
256
257         /**
258          * Manages factories for ListenerService plugins.
259          */
260         xmltooling::PluginManager<ListenerService,std::string,const xercesc::DOMElement*> ListenerServiceManager;
261
262         /**
263          * Manages factories for Handler plugins that implement LogoutInitiator functionality.
264          */
265         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > LogoutInitiatorManager;
266
267         /**
268          * Manages factories for Handler plugins that implement ManageNameIDService functionality.
269          */
270         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > ManageNameIDServiceManager;
271
272         /**
273          * Manages factories for ProtocolProvider plugins.
274          */
275         xmltooling::PluginManager<ProtocolProvider,std::string,const xercesc::DOMElement*> ProtocolProviderManager;
276
277         /**
278          * Manages factories for RequestMapper plugins.
279          */
280         xmltooling::PluginManager<RequestMapper,std::string,const xercesc::DOMElement*> RequestMapperManager;
281
282         /**
283          * Manages factories for ServiceProvider plugins.
284          */
285         xmltooling::PluginManager<ServiceProvider,std::string,const xercesc::DOMElement*> ServiceProviderManager;
286
287         /**
288          * Manages factories for SessionCache plugins.
289          */
290         xmltooling::PluginManager<SessionCache,std::string,const xercesc::DOMElement*> SessionCacheManager;
291
292         /**
293          * Manages factories for Handler plugins that implement SessionInitiator functionality.
294          */
295         xmltooling::PluginManager< SessionInitiator,std::string,std::pair<const xercesc::DOMElement*,const char*> > SessionInitiatorManager;
296
297         /**
298          * Manages factories for Handler plugins that implement SingleLogoutService functionality.
299          */
300         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > SingleLogoutServiceManager;
301
302     protected:
303         /** Global ServiceProvider instance. */
304         ServiceProvider* m_serviceProvider;
305
306 #ifndef SHIBSP_LITE
307         /** Global ArtifactResolver instance. */
308         opensaml::MessageDecoder::ArtifactResolver* m_artifactResolver;
309 #endif
310
311     private:
312         unsigned long m_features;
313         xercesc::DOMDocument* m_configDoc;
314     };
315
316 #if defined (_MSC_VER)
317     #pragma warning( pop )
318 #endif
319
320 };
321
322 #endif /* __shibsp_config_h__ */