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
25 #include "AccessControl.h"
26 #include "exceptions.h"
27 #include "RequestMapper.h"
28 #include "ServiceProvider.h"
29 #include "SessionCache.h"
31 #include "attribute/AttributeDecoder.h"
32 #include "attribute/filtering/AttributeFilter.h"
33 #include "attribute/filtering/MatchFunctor.h"
34 #include "attribute/resolver/AttributeExtractor.h"
35 #include "attribute/resolver/AttributeResolver.h"
36 #include "binding/ArtifactResolver.h"
37 #include "handler/SessionInitiator.h"
38 #include "metadata/MetadataExt.h"
39 #include "remoting/ListenerService.h"
40 #include "security/PKIXTrustEngine.h"
42 #include <log4cpp/Category.hh>
43 #include <saml/SAMLConfig.h>
44 #include <xmltooling/util/NDC.h>
45 #include <xmltooling/util/TemplateEngine.h>
47 using namespace shibsp;
48 using namespace opensaml;
49 using namespace xmltooling;
50 using namespace log4cpp;
52 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
53 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
54 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
55 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
56 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
57 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
60 SPInternalConfig g_config;
63 SPConfig& SPConfig::getConfig()
68 SPInternalConfig& SPInternalConfig::getInternalConfig()
73 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
75 delete m_serviceProvider;
76 m_serviceProvider = serviceProvider;
79 bool SPInternalConfig::init(const char* catalog_path)
84 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
85 log.debug("library initialization started");
87 const char* loglevel=getenv("SHIBSP_LOGGING");
89 loglevel = SHIBSP_LOGGING;
90 XMLToolingConfig::getConfig().log_config(loglevel);
93 catalog_path = getenv("SHIBSP_SCHEMAS");
95 catalog_path = SHIBSP_SCHEMAS;
96 XMLToolingConfig::getConfig().catalog_path = catalog_path;
98 if (!SAMLConfig::getConfig().init()) {
99 log.fatal("failed to initialize OpenSAML library");
103 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
104 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
106 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
107 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
108 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
109 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
110 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
111 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
113 if (isEnabled(Metadata))
114 registerMetadataExtClasses();
115 if (isEnabled(Trust))
116 registerPKIXTrustEngine();
118 registerAttributeFactories();
120 registerSessionInitiators();
121 registerServiceProviders();
123 if (isEnabled(AttributeResolution)) {
124 registerAttributeDecoders();
125 registerAttributeExtractors();
126 registerAttributeFilters();
127 registerAttributeResolvers();
128 registerMatchFunctors();
131 if (isEnabled(Listener))
132 registerListenerServices();
134 if (isEnabled(RequestMapping)) {
135 registerAccessControls();
136 registerRequestMappers();
139 if (isEnabled(Caching))
140 registerSessionCaches();
142 if (isEnabled(OutOfProcess))
143 m_artifactResolver = new ArtifactResolver();
145 log.info("library initialization complete");
149 void SPInternalConfig::term()
154 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
155 log.info("shutting down the library");
157 setServiceProvider(NULL);
158 setArtifactResolver(NULL);
160 AssertionConsumerServiceManager.deregisterFactories();
161 ManageNameIDServiceManager.deregisterFactories();
162 SessionInitiatorManager.deregisterFactories();
163 SingleLogoutServiceManager.deregisterFactories();
164 HandlerManager.deregisterFactories();
165 ServiceProviderManager.deregisterFactories();
166 Attribute::deregisterFactories();
168 if (isEnabled(AttributeResolution)) {
169 MatchFunctorManager.deregisterFactories();
170 AttributeDecoderManager.deregisterFactories();
171 AttributeFilterManager.deregisterFactories();
172 AttributeExtractorManager.deregisterFactories();
173 AttributeResolverManager.deregisterFactories();
176 if (isEnabled(Listener))
177 ListenerServiceManager.deregisterFactories();
179 if (isEnabled(RequestMapping)) {
180 AccessControlManager.deregisterFactories();
181 RequestMapperManager.deregisterFactories();
184 if (isEnabled(Caching))
185 SessionCacheManager.deregisterFactories();
187 SAMLConfig::getConfig().term();
188 log.info("library shutdown complete");