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/resolver/AttributeResolver.h"
33 #include "binding/ArtifactResolver.h"
34 #include "handler/Handler.h"
35 #include "metadata/MetadataExt.h"
36 #include "remoting/ListenerService.h"
37 #include "security/PKIXTrustEngine.h"
39 #include <log4cpp/Category.hh>
40 #include <saml/SAMLConfig.h>
41 #include <xmltooling/util/NDC.h>
42 #include <xmltooling/util/TemplateEngine.h>
44 using namespace shibsp;
45 using namespace opensaml;
46 using namespace xmltooling;
47 using namespace log4cpp;
49 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
50 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
51 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
52 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
55 SPInternalConfig g_config;
58 SPConfig& SPConfig::getConfig()
63 SPInternalConfig& SPInternalConfig::getInternalConfig()
68 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
70 delete m_serviceProvider;
71 m_serviceProvider = serviceProvider;
74 bool SPInternalConfig::init(const char* catalog_path)
79 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
80 log.debug("library initialization started");
82 const char* loglevel=getenv("SHIBSP_LOGGING");
84 loglevel = SHIBSP_LOGGING;
85 XMLToolingConfig::getConfig().log_config(loglevel);
88 catalog_path = getenv("SHIBSP_SCHEMAS");
90 catalog_path = SHIBSP_SCHEMAS;
91 XMLToolingConfig::getConfig().catalog_path = catalog_path;
93 if (!SAMLConfig::getConfig().init()) {
94 log.fatal("failed to initialize OpenSAML library");
98 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
99 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
101 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
102 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
103 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
104 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
106 registerMetadataExtClasses();
107 registerPKIXTrustEngine();
109 registerAccessControls();
110 registerAttributeDecoders();
111 registerAttributeFactories();
112 registerAttributeResolvers();
114 registerListenerServices();
115 registerRequestMappers();
116 registerSessionCaches();
117 registerServiceProviders();
119 if (isEnabled(OutOfProcess))
120 m_artifactResolver = new ArtifactResolver();
122 log.info("library initialization complete");
126 void SPInternalConfig::term()
131 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
132 log.info("shutting down the library");
134 setServiceProvider(NULL);
135 setArtifactResolver(NULL);
137 AssertionConsumerServiceManager.deregisterFactories();
138 ManageNameIDServiceManager.deregisterFactories();
139 SessionInitiatorManager.deregisterFactories();
140 SingleLogoutServiceManager.deregisterFactories();
142 ServiceProviderManager.deregisterFactories();
143 SessionCacheManager.deregisterFactories();
144 RequestMapperManager.deregisterFactories();
145 ListenerServiceManager.deregisterFactories();
146 HandlerManager.deregisterFactories();
147 AttributeResolverManager.deregisterFactories();
148 AttributeDecoderManager.deregisterFactories();
149 Attribute::deregisterFactories();
150 AccessControlManager.deregisterFactories();
152 SAMLConfig::getConfig().term();
153 log.info("library shutdown complete");