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