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/PathResolver.h>
65 #include <xmltooling/util/TemplateEngine.h>
67 using namespace shibsp;
68 using namespace opensaml;
69 using namespace xmltooling;
71 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
72 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
73 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
74 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
75 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
76 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
79 DECL_XMLTOOLING_EXCEPTION_FACTORY(BindingException,opensaml);
80 DECL_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
81 DECL_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
82 DECL_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
83 DECL_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
84 DECL_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
91 SPConfig& SPConfig::getConfig()
96 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
98 delete m_serviceProvider;
99 m_serviceProvider = serviceProvider;
102 bool SPConfig::init(const char* catalog_path, const char* inst_prefix)
107 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
108 log.debug("%s library initialization started", PACKAGE_STRING);
110 const char* loglevel=getenv("SHIBSP_LOGGING");
112 loglevel = SHIBSP_LOGGING;
113 XMLToolingConfig::getConfig().log_config(loglevel);
116 inst_prefix = getenv("SHIBSP_PREFIX");
118 inst_prefix = SHIBSP_PREFIX;
121 catalog_path = getenv("SHIBSP_SCHEMAS");
123 catalog_path = SHIBSP_SCHEMAS;
124 XMLToolingConfig::getConfig().catalog_path = catalog_path;
127 if (!SAMLConfig::getConfig().init()) {
128 log.fatal("failed to initialize OpenSAML library");
131 XMLPlatformUtils::fgNetAccessor = new CurlNetAccessor();
133 if (!XMLToolingConfig::getConfig().init()) {
134 log.fatal("failed to initialize XMLTooling library");
138 XMLToolingConfig::getConfig().getPathResolver()->setDefaultPackageName(PACKAGE_NAME);
139 XMLToolingConfig::getConfig().getPathResolver()->setDefaultPrefix(inst_prefix);
140 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
141 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
143 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
144 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
145 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
146 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
147 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
148 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
151 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(BindingException,opensaml);
152 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
153 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
154 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
155 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
156 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
160 if (isEnabled(Metadata))
161 registerMetadataExtClasses();
162 if (isEnabled(Trust))
163 registerPKIXTrustEngine();
166 registerAttributeFactories();
168 registerSessionInitiators();
169 registerServiceProviders();
172 if (isEnabled(AttributeResolution)) {
173 registerAttributeExtractors();
174 registerAttributeDecoders();
175 registerAttributeResolvers();
176 registerAttributeFilters();
177 registerMatchFunctors();
181 if (isEnabled(Listener))
182 registerListenerServices();
184 if (isEnabled(RequestMapping)) {
185 registerAccessControls();
186 registerRequestMappers();
189 if (isEnabled(Caching))
190 registerSessionCaches();
193 if (isEnabled(OutOfProcess))
194 m_artifactResolver = new ArtifactResolver();
197 log.info("%s library initialization complete", PACKAGE_STRING);
201 void SPConfig::term()
206 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
207 log.info("%s library shutting down", PACKAGE_STRING);
209 setServiceProvider(NULL);
211 setArtifactResolver(NULL);
214 ArtifactResolutionServiceManager.deregisterFactories();
215 AssertionConsumerServiceManager.deregisterFactories();
216 LogoutInitiatorManager.deregisterFactories();
217 ManageNameIDServiceManager.deregisterFactories();
218 SessionInitiatorManager.deregisterFactories();
219 SingleLogoutServiceManager.deregisterFactories();
220 HandlerManager.deregisterFactories();
221 ServiceProviderManager.deregisterFactories();
222 Attribute::deregisterFactories();
225 if (isEnabled(AttributeResolution)) {
226 MatchFunctorManager.deregisterFactories();
227 AttributeFilterManager.deregisterFactories();
228 AttributeDecoderManager.deregisterFactories();
229 AttributeExtractorManager.deregisterFactories();
230 AttributeResolverManager.deregisterFactories();
234 if (isEnabled(Listener))
235 ListenerServiceManager.deregisterFactories();
237 if (isEnabled(RequestMapping)) {
238 AccessControlManager.deregisterFactories();
239 RequestMapperManager.deregisterFactories();
242 if (isEnabled(Caching))
243 SessionCacheManager.deregisterFactories();
246 SAMLConfig::getConfig().term();
248 XMLToolingConfig::getConfig().term();
250 log.info("%s library shutdown complete", PACKAGE_STRING);