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