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