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