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>
59 # include <xmltooling/XMLToolingConfig.h>
62 #include <xmltooling/util/NDC.h>
63 #include <xmltooling/util/TemplateEngine.h>
65 using namespace shibsp;
66 using namespace opensaml;
67 using namespace xmltooling;
69 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
70 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
71 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
72 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
73 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
74 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
77 DECL_XMLTOOLING_EXCEPTION_FACTORY(BindingException,opensaml);
78 DECL_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
79 DECL_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
80 DECL_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
81 DECL_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
82 DECL_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
86 SPInternalConfig g_config;
89 SPConfig& SPConfig::getConfig()
94 SPInternalConfig& SPInternalConfig::getInternalConfig()
99 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
101 delete m_serviceProvider;
102 m_serviceProvider = serviceProvider;
105 bool SPInternalConfig::init(const char* catalog_path)
110 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
111 log.debug("library initialization started");
113 const char* loglevel=getenv("SHIBSP_LOGGING");
115 loglevel = SHIBSP_LOGGING;
116 XMLToolingConfig::getConfig().log_config(loglevel);
119 catalog_path = getenv("SHIBSP_SCHEMAS");
121 catalog_path = SHIBSP_SCHEMAS;
122 XMLToolingConfig::getConfig().catalog_path = catalog_path;
125 if (!SAMLConfig::getConfig().init()) {
126 log.fatal("failed to initialize OpenSAML library");
130 if (!XMLToolingConfig::getConfig().init()) {
131 log.fatal("failed to initialize XMLTooling library");
136 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
137 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
139 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
140 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
141 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
142 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
143 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
144 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
147 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(BindingException,opensaml);
148 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
149 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
150 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
151 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
152 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
156 if (isEnabled(Metadata))
157 registerMetadataExtClasses();
158 if (isEnabled(Trust))
159 registerPKIXTrustEngine();
162 registerAttributeFactories();
164 registerSessionInitiators();
165 registerServiceProviders();
168 if (isEnabled(AttributeResolution)) {
169 registerAttributeExtractors();
170 registerAttributeDecoders();
171 registerAttributeResolvers();
172 registerAttributeFilters();
173 registerMatchFunctors();
177 if (isEnabled(Listener))
178 registerListenerServices();
180 if (isEnabled(RequestMapping)) {
181 registerAccessControls();
182 registerRequestMappers();
185 if (isEnabled(Caching))
186 registerSessionCaches();
189 if (isEnabled(OutOfProcess))
190 m_artifactResolver = new ArtifactResolver();
193 log.info("library initialization complete");
197 void SPInternalConfig::term()
202 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
203 log.info("shutting down the library");
205 setServiceProvider(NULL);
207 setArtifactResolver(NULL);
210 ArtifactResolutionServiceManager.deregisterFactories();
211 AssertionConsumerServiceManager.deregisterFactories();
212 LogoutInitiatorManager.deregisterFactories();
213 ManageNameIDServiceManager.deregisterFactories();
214 SessionInitiatorManager.deregisterFactories();
215 SingleLogoutServiceManager.deregisterFactories();
216 HandlerManager.deregisterFactories();
217 ServiceProviderManager.deregisterFactories();
218 Attribute::deregisterFactories();
221 if (isEnabled(AttributeResolution)) {
222 MatchFunctorManager.deregisterFactories();
223 AttributeFilterManager.deregisterFactories();
224 AttributeDecoderManager.deregisterFactories();
225 AttributeExtractorManager.deregisterFactories();
226 AttributeResolverManager.deregisterFactories();
230 if (isEnabled(Listener))
231 ListenerServiceManager.deregisterFactories();
233 if (isEnabled(RequestMapping)) {
234 AccessControlManager.deregisterFactories();
235 RequestMapperManager.deregisterFactories();
238 if (isEnabled(Caching))
239 SessionCacheManager.deregisterFactories();
242 SAMLConfig::getConfig().term();
244 XMLToolingConfig::getConfig().term();
246 log.info("library shutdown complete");