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