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