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