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