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>
64 #include <xmltooling/util/NDC.h>
65 #include <xmltooling/util/PathResolver.h>
66 #include <xmltooling/util/TemplateEngine.h>
68 using namespace shibsp;
69 using namespace opensaml;
70 using namespace xmltooling;
72 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
73 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
74 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
75 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
76 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
77 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
80 DECL_XMLTOOLING_EXCEPTION_FACTORY(BindingException,opensaml);
81 DECL_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
82 DECL_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
83 DECL_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
84 DECL_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
85 DECL_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
92 SPConfig& SPConfig::getConfig()
97 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
99 delete m_serviceProvider;
100 m_serviceProvider = serviceProvider;
103 bool SPConfig::init(const char* catalog_path, const char* inst_prefix)
109 inst_prefix = getenv("SHIBSP_PREFIX");
111 inst_prefix = SHIBSP_PREFIX;
112 std::string inst_prefix2;
113 while (*inst_prefix) {
114 inst_prefix2.push_back((*inst_prefix=='\\') ? ('/') : (*inst_prefix));
118 const char* loglevel=getenv("SHIBSP_LOGGING");
120 loglevel = SHIBSP_LOGGING;
121 std::string ll(loglevel);
122 PathResolver localpr;
123 localpr.setDefaultPrefix(inst_prefix2.c_str());
124 XMLToolingConfig::getConfig().log_config(localpr.resolve(ll, PathResolver::XMLTOOLING_CFG_FILE, PACKAGE_NAME).c_str());
126 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
127 log.debug("%s library initialization started", PACKAGE_STRING);
130 catalog_path = getenv("SHIBSP_SCHEMAS");
132 catalog_path = SHIBSP_SCHEMAS;
133 XMLToolingConfig::getConfig().catalog_path = catalog_path;
136 if (!SAMLConfig::getConfig().init()) {
137 log.fatal("failed to initialize OpenSAML library");
140 XMLPlatformUtils::fgNetAccessor = new CurlNetAccessor();
142 if (!XMLToolingConfig::getConfig().init()) {
143 log.fatal("failed to initialize XMLTooling library");
147 XMLToolingConfig::getConfig().getPathResolver()->setDefaultPackageName(PACKAGE_NAME);
148 XMLToolingConfig::getConfig().getPathResolver()->setDefaultPrefix(inst_prefix2.c_str());
149 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
150 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
152 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
153 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
154 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
155 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
156 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
157 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
160 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(BindingException,opensaml);
161 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
162 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
163 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
164 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
165 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
169 if (isEnabled(Metadata))
170 registerMetadataExtClasses();
171 if (isEnabled(Trust))
172 registerPKIXTrustEngine();
175 registerAttributeFactories();
177 registerSessionInitiators();
178 registerServiceProviders();
181 if (isEnabled(AttributeResolution)) {
182 registerAttributeExtractors();
183 registerAttributeDecoders();
184 registerAttributeResolvers();
185 registerAttributeFilters();
186 registerMatchFunctors();
190 if (isEnabled(Listener))
191 registerListenerServices();
193 if (isEnabled(RequestMapping)) {
194 registerAccessControls();
195 registerRequestMappers();
198 if (isEnabled(Caching))
199 registerSessionCaches();
202 if (isEnabled(OutOfProcess))
203 m_artifactResolver = new ArtifactResolver();
205 srand(static_cast<unsigned int>(std::time(NULL)));
207 log.info("%s library initialization complete", PACKAGE_STRING);
211 void SPConfig::term()
216 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
217 log.info("%s library shutting down", PACKAGE_STRING);
219 setServiceProvider(NULL);
221 setArtifactResolver(NULL);
224 ArtifactResolutionServiceManager.deregisterFactories();
225 AssertionConsumerServiceManager.deregisterFactories();
226 LogoutInitiatorManager.deregisterFactories();
227 ManageNameIDServiceManager.deregisterFactories();
228 SessionInitiatorManager.deregisterFactories();
229 SingleLogoutServiceManager.deregisterFactories();
230 HandlerManager.deregisterFactories();
231 ServiceProviderManager.deregisterFactories();
232 Attribute::deregisterFactories();
235 if (isEnabled(AttributeResolution)) {
236 MatchFunctorManager.deregisterFactories();
237 AttributeFilterManager.deregisterFactories();
238 AttributeDecoderManager.deregisterFactories();
239 AttributeExtractorManager.deregisterFactories();
240 AttributeResolverManager.deregisterFactories();
244 if (isEnabled(Listener))
245 ListenerServiceManager.deregisterFactories();
247 if (isEnabled(RequestMapping)) {
248 AccessControlManager.deregisterFactories();
249 RequestMapperManager.deregisterFactories();
252 if (isEnabled(Caching))
253 SessionCacheManager.deregisterFactories();
256 SAMLConfig::getConfig().term();
258 XMLToolingConfig::getConfig().term();
260 log.info("%s library shutdown complete", PACKAGE_STRING);