Large reorg of shibsp lib, new SPRequest API, ported modules, shifted code out of...
[shibboleth/cpp-sp.git] / shibsp / SPConfig.h
1 /*
2  *  Copyright 2001-2006 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 #include <xmltooling/PluginManager.h>
28 #include <xercesc/dom/DOM.hpp>
29
30 /**
31  * @namespace shibsp
32  * Shibboleth Service Provider Library
33  */
34 namespace shibsp {
35
36     class SHIBSP_API AccessControl;
37     class SHIBSP_API ListenerService;
38     class SHIBSP_API RequestMapper;
39     class SHIBSP_API ServiceProvider;
40
41 #if defined (_MSC_VER)
42     #pragma warning( push )
43     #pragma warning( disable : 4250 4251 )
44 #endif
45
46     /**
47      * Singleton object that manages library startup/shutdown.
48      */
49     class SHIBSP_API SPConfig
50     {
51     MAKE_NONCOPYABLE(SPConfig);
52     public:
53         virtual ~SPConfig() {}
54
55         /**
56          * Returns the global configuration object for the library.
57          * 
58          * @return reference to the global library configuration object
59          */
60         static SPConfig& getConfig();
61
62         /**
63          * Bitmask values representing subsystems of the library.
64          */
65         enum components_t {
66             Listener = 1,
67             Caching = 2,
68             Metadata = 4,
69             Trust = 8,
70             Credentials = 16,
71             AAP = 32,
72             RequestMapping = 64,
73             OutOfProcess = 128,
74             InProcess = 256,
75             Logging = 512
76         };
77         
78         /**
79          * Set a bitmask of subsystems to activate.
80          * 
81          * @param enabled   bitmask of component constants
82          */
83         void setFeatures(unsigned long enabled) {
84             m_features = enabled;
85         }
86
87         /**
88          * Test whether a subsystem is enabled.
89          * 
90          * @param feature   subsystem/component to test
91          * @return true iff feature is enabled
92          */
93         bool isEnabled(components_t feature) {
94             return (m_features & feature)>0;
95         }
96         
97         /**
98          * Initializes library
99          * 
100          * Each process using the library MUST call this function exactly once
101          * before using any library classes.
102          * 
103          * @param catalog_path  delimited set of schema catalog files to load
104          * @return true iff initialization was successful 
105          */
106         virtual bool init(const char* catalog_path)=0;
107         
108         /**
109          * Shuts down library
110          * 
111          * Each process using the library SHOULD call this function exactly once
112          * before terminating itself.
113          */
114         virtual void term()=0;
115         
116         /**
117          * Sets the global ServiceProvider instance.
118          * This method must be externally synchronized with any code that uses the object.
119          * Any previously set object is destroyed.
120          * 
121          * @param serviceProvider   new ServiceProvider instance to store
122          */
123         void setServiceProvider(ServiceProvider* serviceProvider);
124         
125         /**
126          * Returns the global ServiceProvider instance.
127          * 
128          * @return  global ServiceProvider or NULL
129          */
130         ServiceProvider* getServiceProvider() const {
131             return m_serviceProvider;
132         }
133
134         /**
135          * Manages factories for AccessControl plugins.
136          */
137         xmltooling::PluginManager<AccessControl,const xercesc::DOMElement*> AccessControlManager;
138
139         /**
140          * Manages factories for ListenerService plugins.
141          */
142         xmltooling::PluginManager<ListenerService,const xercesc::DOMElement*> ListenerServiceManager;
143
144         /**
145          * Manages factories for RequestMapper plugins.
146          */
147         xmltooling::PluginManager<RequestMapper,const xercesc::DOMElement*> RequestMapperManager;
148
149         /**
150          * Manages factories for ServiceProvider plugins.
151          */
152         xmltooling::PluginManager<ServiceProvider,const xercesc::DOMElement*> ServiceProviderManager;
153
154     protected:
155         SPConfig() : m_serviceProvider(NULL) {}
156         
157         /** Global ServiceProvider instance. */
158         ServiceProvider* m_serviceProvider;
159
160     private:
161         unsigned long m_features;
162     };
163
164 #if defined (_MSC_VER)
165     #pragma warning( pop )
166 #endif
167
168 };
169
170 #endif /* __shibsp_config_h__ */