2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file xmltooling/XMLToolingConfig.h
20 * Library configuration
23 #ifndef __xmltooling_config_h__
24 #define __xmltooling_config_h__
26 #include <xmltooling/Lockable.h>
27 #include <xmltooling/PluginManager.h>
28 #include <xmltooling/soap/SOAPTransport.h>
29 #include <xmltooling/util/ParserPool.h>
31 #ifndef XMLTOOLING_NO_XMLSEC
32 namespace xmltooling {
33 class XMLTOOL_API CredentialResolver;
34 class XMLTOOL_API KeyInfoResolver;
35 class XMLTOOL_API TrustEngine;
36 class XMLTOOL_API XSECCryptoX509CRL;
40 #if defined (_MSC_VER)
41 #pragma warning( push )
42 #pragma warning( disable : 4251 )
45 namespace xmltooling {
47 class XMLTOOL_API TemplateEngine;
48 class XMLTOOL_API URLEncoder;
49 #ifndef XMLTOOLING_LITE
50 class XMLTOOL_API ReplayCache;
51 class XMLTOOL_API StorageService;
55 * Singleton object that manages library startup/shutdown.configuration.
57 * A locking interface is supplied as a convenience for code that wants to
58 * obtain a global system lock, but the actual configuration itself is not
61 class XMLTOOL_API XMLToolingConfig : public Lockable
63 MAKE_NONCOPYABLE(XMLToolingConfig);
65 #ifndef XMLTOOLING_NO_XMLSEC
66 XMLToolingConfig() : m_keyInfoResolver(NULL), m_replayCache(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
68 /** Global KeyInfoResolver instance. */
69 KeyInfoResolver* m_keyInfoResolver;
71 /** Global ReplayCache instance. */
72 ReplayCache* m_replayCache;
74 XMLToolingConfig() : m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
77 /** Global TemplateEngine instance. */
78 TemplateEngine* m_templateEngine;
80 /** Global URLEncoder instance for use by URL-related functions. */
81 URLEncoder* m_urlEncoder;
84 virtual ~XMLToolingConfig() {}
87 * Returns the global configuration object for the library.
89 * @return reference to the global library configuration object
91 static XMLToolingConfig& getConfig();
96 * Each process using the library MUST call this function exactly once
97 * before using any library classes except for the LogConfig method.
99 * @return true iff initialization was successful
101 virtual bool init()=0;
106 * Each process using the library SHOULD call this function exactly once
107 * before terminating itself
109 virtual void term()=0;
112 * Loads a shared/dynamic library extension.
114 * Extension libraries are managed using a pair of "C" linkage functions:<br>
115 * extern "C" int xmltooling_extension_init(void* context);<br>
116 * extern "C" void xmltooling_extension_term();
118 * This method is internally synchronized.
120 * @param path pathname of shared library to load into process
121 * @param context arbitrary data to pass to library initialization hook
122 * @return true iff library was loaded successfully
124 virtual bool load_library(const char* path, void* context=NULL)=0;
127 * Configure logging system.
129 * May be called first, before initializing the library. Other calls to it
130 * must be externally synchronized.
132 * @param config either a logging configuration file, or a level from the set
133 * (DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG)
134 * @return true iff configuration was successful
136 virtual bool log_config(const char* config=NULL)=0;
139 * Obtains a non-validating parser pool.
140 * Library must be initialized first.
142 * @return reference to a non-validating parser pool.
144 virtual ParserPool& getParser() const=0;
147 * Obtains a validating parser pool.
148 * Library must be initialized first. Schema/catalog registration must be
149 * externally synchronized.
151 * @return reference to a validating parser pool.
153 virtual ParserPool& getValidatingParser() const=0;
155 #ifndef XMLTOOLING_NO_XMLSEC
157 * Sets the global KeyInfoResolver instance.
158 * This method must be externally synchronized with any code that uses the object.
159 * Any previously set object is destroyed.
161 * @param keyInfoResolver new KeyInfoResolver instance to store
163 void setKeyInfoResolver(KeyInfoResolver* keyInfoResolver);
166 * Returns the global KeyInfoResolver instance.
168 * @return global KeyInfoResolver or NULL
170 const KeyInfoResolver* getKeyInfoResolver() const {
171 return m_keyInfoResolver;
175 * Sets the global ReplayCache instance.
176 * This method must be externally synchronized with any code that uses the object.
177 * Any previously set object is destroyed.
179 * @param replayCache new ReplayCache instance to store
181 void setReplayCache(ReplayCache* replayCache);
184 * Returns the global ReplayCache instance.
186 * @return global ReplayCache or NULL
188 ReplayCache* getReplayCache() const {
189 return m_replayCache;
194 * Sets the global URLEncoder instance.
195 * This method must be externally synchronized with any code that uses the object.
196 * Any previously set object is destroyed.
198 * @param urlEncoder new URLEncoder instance to store
200 void setURLEncoder(URLEncoder* urlEncoder);
203 * Returns the global URLEncoder instance.
205 * @return global URLEncoder or NULL
207 const URLEncoder* getURLEncoder() const {
212 * Sets the global TemplateEngine instance.
213 * This method must be externally synchronized with any code that uses the object.
214 * Any previously set object is destroyed.
216 * @param templateEngine new TemplateEngine instance to store
218 void setTemplateEngine(TemplateEngine* templateEngine);
221 * Returns the global TemplateEngine instance.
223 * @return global TemplateEngine or NULL
225 TemplateEngine* getTemplateEngine() const {
226 return m_templateEngine;
230 * List of catalog files to load into validating parser pool at initialization time.
231 * Like other path settings, the separator depends on the platform
232 * (semicolon on Windows, colon otherwise).
234 std::string catalog_path;
237 * Adjusts any clock comparisons to be more liberal/permissive by the
238 * indicated number of seconds.
240 unsigned int clock_skew_secs;
242 #ifndef XMLTOOLING_NO_XMLSEC
244 * Returns an X.509 CRL implementation object.
246 virtual XSECCryptoX509CRL* X509CRL() const=0;
249 * Manages factories for KeyInfoResolver plugins.
251 PluginManager<KeyInfoResolver,std::string,const xercesc::DOMElement*> KeyInfoResolverManager;
254 * Manages factories for CredentialResolver plugins.
256 PluginManager<CredentialResolver,std::string,const xercesc::DOMElement*> CredentialResolverManager;
259 * Manages factories for TrustEngine plugins.
261 PluginManager<TrustEngine,std::string,const xercesc::DOMElement*> TrustEngineManager;
264 * Manages factories for StorageService plugins.
266 PluginManager<StorageService,std::string,const xercesc::DOMElement*> StorageServiceManager;
269 * Maps an XML Signature/Encryption algorithm identifier to a library-specific
270 * key algorithm and size for use in resolving credentials.
272 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
273 * @return a general key algorithm and key size (or 0 if the size is irrelevant)
275 virtual std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const=0;
278 * Registers an XML Signature/Encryption algorithm identifier against a library-specific
279 * key algorithm and size for use in resolving credentials.
281 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
282 * @param keyAlgorithm a key algorithm
283 * @param size a key size (or 0 if the size is irrelevant)
285 virtual void registerXMLAlgorithm(const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0)=0;
289 * Manages factories for SOAPTransport plugins.
291 * <p>The factory interface takes a peer name/endpoint pair.
293 PluginManager<SOAPTransport,std::string,SOAPTransport::Address> SOAPTransportManager;
298 #if defined (_MSC_VER)
299 #pragma warning( pop )
302 #endif /* __xmltooling_config_h__ */