3 * Copyright 2001-2007 Internet2
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 * Library configuration
26 #if defined(XMLTOOLING_LOG4SHIB)
27 # ifndef SHIBSP_LOG4SHIB
28 # error "Logging library mismatch (XMLTooling is using log4shib)."
30 #elif defined(XMLTOOLING_LOG4CPP)
31 # ifndef SHIBSP_LOG4CPP
32 # error "Logging library mismatch (XMLTooling is using log4cpp)."
35 # error "No supported logging library."
38 #include "AccessControl.h"
39 #include "exceptions.h"
40 #include "RequestMapper.h"
41 #include "ServiceProvider.h"
42 #include "SessionCache.h"
44 #include "attribute/Attribute.h"
45 #include "handler/SessionInitiator.h"
46 #include "remoting/ListenerService.h"
49 # include "attribute/AttributeDecoder.h"
50 # include "attribute/filtering/AttributeFilter.h"
51 # include "attribute/filtering/MatchFunctor.h"
52 # include "attribute/resolver/AttributeExtractor.h"
53 # include "attribute/resolver/AttributeResolver.h"
54 # include "binding/ArtifactResolver.h"
55 # include "metadata/MetadataExt.h"
56 # include "security/PKIXTrustEngine.h"
57 # include <saml/SAMLConfig.h>
58 # include <xmltooling/util/CurlNetAccessor.hpp>
60 # include <xmltooling/XMLToolingConfig.h>
63 #include <xmltooling/util/NDC.h>
64 #include <xmltooling/util/TemplateEngine.h>
66 using namespace shibsp;
67 using namespace opensaml;
68 using namespace xmltooling;
70 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
71 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
72 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
73 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
74 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
75 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
78 DECL_XMLTOOLING_EXCEPTION_FACTORY(BindingException,opensaml);
79 DECL_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
80 DECL_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
81 DECL_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
82 DECL_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
83 DECL_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
87 SPInternalConfig g_config;
90 SPConfig& SPConfig::getConfig()
95 SPInternalConfig& SPInternalConfig::getInternalConfig()
100 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
102 delete m_serviceProvider;
103 m_serviceProvider = serviceProvider;
106 bool SPInternalConfig::init(const char* catalog_path)
111 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
112 log.debug("%s library initialization started", PACKAGE_STRING);
114 const char* loglevel=getenv("SHIBSP_LOGGING");
116 loglevel = SHIBSP_LOGGING;
117 XMLToolingConfig::getConfig().log_config(loglevel);
120 catalog_path = getenv("SHIBSP_SCHEMAS");
122 catalog_path = SHIBSP_SCHEMAS;
123 XMLToolingConfig::getConfig().catalog_path = catalog_path;
126 if (!SAMLConfig::getConfig().init()) {
127 log.fatal("failed to initialize OpenSAML library");
130 XMLPlatformUtils::fgNetAccessor = new CurlNetAccessor();
132 if (!XMLToolingConfig::getConfig().init()) {
133 log.fatal("failed to initialize XMLTooling library");
138 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
139 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
141 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
142 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
143 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
144 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
145 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
146 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
149 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(BindingException,opensaml);
150 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
151 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
152 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
153 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
154 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
158 if (isEnabled(Metadata))
159 registerMetadataExtClasses();
160 if (isEnabled(Trust))
161 registerPKIXTrustEngine();
164 registerAttributeFactories();
166 registerSessionInitiators();
167 registerServiceProviders();
170 if (isEnabled(AttributeResolution)) {
171 registerAttributeExtractors();
172 registerAttributeDecoders();
173 registerAttributeResolvers();
174 registerAttributeFilters();
175 registerMatchFunctors();
179 if (isEnabled(Listener))
180 registerListenerServices();
182 if (isEnabled(RequestMapping)) {
183 registerAccessControls();
184 registerRequestMappers();
187 if (isEnabled(Caching))
188 registerSessionCaches();
191 if (isEnabled(OutOfProcess))
192 m_artifactResolver = new ArtifactResolver();
195 log.info("%s library initialization complete", PACKAGE_STRING);
199 void SPInternalConfig::term()
204 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
205 log.info("%s library shutting down", PACKAGE_STRING);
207 setServiceProvider(NULL);
209 setArtifactResolver(NULL);
212 ArtifactResolutionServiceManager.deregisterFactories();
213 AssertionConsumerServiceManager.deregisterFactories();
214 LogoutInitiatorManager.deregisterFactories();
215 ManageNameIDServiceManager.deregisterFactories();
216 SessionInitiatorManager.deregisterFactories();
217 SingleLogoutServiceManager.deregisterFactories();
218 HandlerManager.deregisterFactories();
219 ServiceProviderManager.deregisterFactories();
220 Attribute::deregisterFactories();
223 if (isEnabled(AttributeResolution)) {
224 MatchFunctorManager.deregisterFactories();
225 AttributeFilterManager.deregisterFactories();
226 AttributeDecoderManager.deregisterFactories();
227 AttributeExtractorManager.deregisterFactories();
228 AttributeResolverManager.deregisterFactories();
232 if (isEnabled(Listener))
233 ListenerServiceManager.deregisterFactories();
235 if (isEnabled(RequestMapping)) {
236 AccessControlManager.deregisterFactories();
237 RequestMapperManager.deregisterFactories();
240 if (isEnabled(Caching))
241 SessionCacheManager.deregisterFactories();
244 SAMLConfig::getConfig().term();
246 XMLToolingConfig::getConfig().term();
248 log.info("%s library shutdown complete", PACKAGE_STRING);