dfcd19c425201f1e5a89ab6dec19db139262e24e
[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 #include <saml/binding/MessageDecoder.h>
28 #include <xmltooling/PluginManager.h>
29 #include <xercesc/dom/DOM.hpp>
30
31 /**
32  * @namespace shibsp
33  * Shibboleth Service Provider Library
34  */
35 namespace shibsp {
36
37     class SHIBSP_API AccessControl;
38     class SHIBSP_API AttributeDecoder;
39     class SHIBSP_API AttributeResolver;
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
46 #if defined (_MSC_VER)
47     #pragma warning( push )
48     #pragma warning( disable : 4250 4251 )
49 #endif
50
51     /**
52      * Singleton object that manages library startup/shutdown.
53      */
54     class SHIBSP_API SPConfig
55     {
56     MAKE_NONCOPYABLE(SPConfig);
57     public:
58         virtual ~SPConfig() {}
59
60         /**
61          * Returns the global configuration object for the library.
62          * 
63          * @return reference to the global library configuration object
64          */
65         static SPConfig& getConfig();
66
67         /**
68          * Bitmask values representing subsystems of the library.
69          */
70         enum components_t {
71             Listener = 1,
72             Caching = 2,
73             Metadata = 4,
74             Trust = 8,
75             Credentials = 16,
76             AttributeResolution = 32,
77             RequestMapping = 64,
78             OutOfProcess = 128,
79             InProcess = 256,
80             Logging = 512
81         };
82         
83         /**
84          * Set a bitmask of subsystems to activate.
85          * 
86          * @param enabled   bitmask of component constants
87          */
88         void setFeatures(unsigned long enabled) {
89             m_features = enabled;
90         }
91
92         /**
93          * Test whether a subsystem is enabled.
94          * 
95          * @param feature   subsystem/component to test
96          * @return true iff feature is enabled
97          */
98         bool isEnabled(components_t feature) {
99             return (m_features & feature)>0;
100         }
101         
102         /**
103          * Initializes library
104          * 
105          * Each process using the library MUST call this function exactly once
106          * before using any library classes.
107          * 
108          * @param catalog_path  delimited set of schema catalog files to load
109          * @return true iff initialization was successful 
110          */
111         virtual bool init(const char* catalog_path)=0;
112         
113         /**
114          * Shuts down library
115          * 
116          * Each process using the library SHOULD call this function exactly once
117          * before terminating itself.
118          */
119         virtual void term()=0;
120         
121         /**
122          * Sets the global ServiceProvider instance.
123          * This method must be externally synchronized with any code that uses the object.
124          * Any previously set object is destroyed.
125          * 
126          * @param serviceProvider   new ServiceProvider instance to store
127          */
128         void setServiceProvider(ServiceProvider* serviceProvider);
129         
130         /**
131          * Returns the global ServiceProvider instance.
132          * 
133          * @return  global ServiceProvider or NULL
134          */
135         ServiceProvider* getServiceProvider() const {
136             return m_serviceProvider;
137         }
138
139         /**
140          * Sets the global ArtifactResolver instance.
141          *
142          * <p>This method must be externally synchronized with any code that uses the object.
143          * Any previously set object is destroyed.
144          * 
145          * @param artifactResolver   new ArtifactResolver instance to store
146          */
147         void setArtifactResolver(opensaml::MessageDecoder::ArtifactResolver* artifactResolver) {
148             delete m_artifactResolver;
149             m_artifactResolver = artifactResolver;
150         }
151         
152         /**
153          * Returns the global ArtifactResolver instance.
154          * 
155          * @return  global ArtifactResolver or NULL
156          */
157         opensaml::MessageDecoder::ArtifactResolver* getArtifactResolver() const {
158             return m_artifactResolver;
159         }
160
161         /** Separator for serialized values of multi-valued attributes. */
162         char attribute_value_delimeter;
163         
164         /**
165          * Manages factories for AccessControl plugins.
166          */
167         xmltooling::PluginManager<AccessControl,const xercesc::DOMElement*> AccessControlManager;
168
169         /**
170          * Manages factories for AttributeDecoder plugins.
171          */
172         xmltooling::PluginManager<AttributeDecoder,const xercesc::DOMElement*> AttributeDecoderManager;
173
174         /**
175          * Manages factories for AttributeResolver plugins.
176          */
177         xmltooling::PluginManager<AttributeResolver,const xercesc::DOMElement*> AttributeResolverManager;
178
179         /**
180          * Manages factories for Handler plugins that implement AssertionConsumerService functionality.
181          */
182         xmltooling::PluginManager< Handler,std::pair<const xercesc::DOMElement*,const char*> > AssertionConsumerServiceManager;
183
184         /**
185          * Manages factories for Handler plugins that implement customized functionality.
186          */
187         xmltooling::PluginManager< Handler,std::pair<const xercesc::DOMElement*,const char*> > HandlerManager;
188
189         /**
190          * Manages factories for ListenerService plugins.
191          */
192         xmltooling::PluginManager<ListenerService,const xercesc::DOMElement*> ListenerServiceManager;
193
194         /**
195          * Manages factories for Handler plugins that implement ManageNameIDService functionality.
196          */
197         xmltooling::PluginManager< Handler,std::pair<const xercesc::DOMElement*,const char*> > ManageNameIDServiceManager;
198
199         /**
200          * Manages factories for RequestMapper plugins.
201          */
202         xmltooling::PluginManager<RequestMapper,const xercesc::DOMElement*> RequestMapperManager;
203
204         /**
205          * Manages factories for ServiceProvider plugins.
206          */
207         xmltooling::PluginManager<ServiceProvider,const xercesc::DOMElement*> ServiceProviderManager;
208
209         /**
210          * Manages factories for SessionCache plugins.
211          */
212         xmltooling::PluginManager<SessionCache,const xercesc::DOMElement*> SessionCacheManager;
213
214         /**
215          * Manages factories for Handler plugins that implement SessionInitiator functionality.
216          */
217         xmltooling::PluginManager< Handler,std::pair<const xercesc::DOMElement*,const char*> > SessionInitiatorManager;
218
219         /**
220          * Manages factories for Handler plugins that implement SingleLogoutService functionality.
221          */
222         xmltooling::PluginManager< Handler,std::pair<const xercesc::DOMElement*,const char*> > SingleLogoutServiceManager;
223
224     protected:
225         SPConfig() : attribute_value_delimeter(';'), m_serviceProvider(NULL), m_artifactResolver(NULL), m_features(0) {}
226         
227         /** Global ServiceProvider instance. */
228         ServiceProvider* m_serviceProvider;
229
230         /** Global ArtifactResolver instance. */
231         opensaml::MessageDecoder::ArtifactResolver* m_artifactResolver;
232
233     private:
234         unsigned long m_features;
235     };
236
237 #if defined (_MSC_VER)
238     #pragma warning( pop )
239 #endif
240
241 };
242
243 #endif /* __shibsp_config_h__ */