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