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"
28 #include "RequestMapper.h"
29 #include "ServiceProvider.h"
30 #include "SessionCache.h"
32 #include "attribute/AttributeDecoder.h"
33 #include "metadata/MetadataExt.h"
34 #include "remoting/ListenerService.h"
35 #include "security/PKIXTrustEngine.h"
37 #include <log4cpp/Category.hh>
38 #include <saml/SAMLConfig.h>
39 #include <xmltooling/util/NDC.h>
40 #include <xmltooling/util/TemplateEngine.h>
42 using namespace shibsp;
43 using namespace opensaml;
44 using namespace xmltooling;
45 using namespace log4cpp;
47 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
48 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
51 SPInternalConfig g_config;
54 SPConfig& SPConfig::getConfig()
59 SPInternalConfig& SPInternalConfig::getInternalConfig()
64 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
66 delete m_serviceProvider;
67 m_serviceProvider = serviceProvider;
70 bool SPInternalConfig::init(const char* catalog_path)
75 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
76 log.debug("library initialization started");
78 const char* loglevel=getenv("SHIBSP_LOGGING");
80 loglevel = SHIBSP_LOGGING;
81 XMLToolingConfig::getConfig().log_config(loglevel);
84 catalog_path = getenv("SHIBSP_SCHEMAS");
86 catalog_path = SHIBSP_SCHEMAS;
87 XMLToolingConfig::getConfig().catalog_path = catalog_path;
89 if (!SAMLConfig::getConfig().init()) {
90 log.fatal("failed to initialize OpenSAML library");
94 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
95 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
97 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
98 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
100 registerMetadataExtClasses();
101 registerPKIXTrustEngine();
102 registerAccessControls();
103 registerListenerServices();
104 registerRequestMappers();
105 registerSessionCaches();
106 registerServiceProviders();
107 registerAttributeFactories();
108 registerAttributeDecoders();
110 log.info("library initialization complete");
114 void SPInternalConfig::term()
119 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
120 log.info("shutting down the library");
122 delete m_serviceProvider;
123 m_serviceProvider = NULL;
125 SingleLogoutServiceManager.deregisterFactories();
126 SessionInitiatorManager.deregisterFactories();
127 SessionCacheManager.deregisterFactories();
128 ServiceProviderManager.deregisterFactories();
129 RequestMapperManager.deregisterFactories();
130 ManageNameIDServiceManager.deregisterFactories();
131 ListenerServiceManager.deregisterFactories();
132 HandlerManager.deregisterFactories();
133 Attribute::deregisterFactories();
134 AttributeDecoderManager.deregisterFactories();
135 AssertionConsumerServiceManager.deregisterFactories();
136 AccessControlManager.deregisterFactories();
138 SAMLConfig::getConfig().term();
139 log.info("library shutdown complete");