2 * Copyright 2001-2005 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * shib-config.cpp -- ShibTarget initialization and finalization routines
20 * Created By: Derek Atkins <derek@ihtfp.com>
26 #include <shibsp/SPConfig.h>
27 #include <xmltooling/XMLToolingConfig.h>
29 #include <log4cpp/OstreamAppender.hh>
31 using namespace shibsp;
32 using namespace shibtarget;
33 using namespace shibboleth;
35 using namespace log4cpp;
38 using xmltooling::XMLToolingConfig;
39 using xmltooling::PluginManager;
45 // Factories for built-in plugins we can manufacture. Actual definitions
46 // will be with the actual object implementation.
48 PlugManager::Factory UnixListenerFactory;
50 PlugManager::Factory TCPListenerFactory;
51 //PlugManager::Factory MemoryListenerFactory;
53 PluginManager<SessionCache,const DOMElement*>::Factory MemoryCacheFactory;
54 PluginManager<Handler,const DOMElement*>::Factory ShibSessionInitiatorFactory;
55 PluginManager<Handler,const DOMElement*>::Factory SAML1POSTFactory;
56 PluginManager<Handler,const DOMElement*>::Factory SAML1ArtifactFactory;
57 PluginManager<Handler,const DOMElement*>::Factory ShibLogoutFactory;
59 ShibTargetConfig& ShibTargetConfig::getConfig()
64 bool STConfig::init(const char* schemadir)
67 xmltooling::NDC ndc("init");
69 Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
72 log.fatal("XML schema directory not supplied");
76 // This will cause some extra console logging, but for now,
77 // initialize the underlying libraries.
78 SAMLConfig& samlConf=SAMLConfig::getConfig();
80 samlConf.schema_dir = schemadir;
81 if (!samlConf.init()) {
82 log.fatal("failed to initialize OpenSAML1 library");
86 ShibConfig& shibConf=ShibConfig::getConfig();
87 if (!shibConf.init()) {
88 log.fatal("Failed to initialize Shib library");
93 SPConfig& conf=SPConfig::getConfig();
94 if (!SPConfig::getConfig().init(NULL)) {
95 log.fatal("Failed to initialize SP library");
101 // Register built-in plugin types.
102 conf.ServiceProviderManager.registerFactory(XML_SERVICE_PROVIDER, XMLServiceProviderFactory);
104 conf.SessionInitiatorManager.registerFactory(shibspconstants::SHIB1_SESSIONINIT_PROFILE_URI,&ShibSessionInitiatorFactory);
105 conf.AssertionConsumerServiceManager.registerFactory(samlconstants::SAML1_PROFILE_BROWSER_POST,&SAML1POSTFactory);
106 conf.AssertionConsumerServiceManager.registerFactory(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT,&SAML1ArtifactFactory);
107 conf.SingleLogoutServiceManager.registerFactory(shibspconstants::SHIB1_LOGOUT_PROFILE_URI,&ShibLogoutFactory);
109 conf.SessionCacheManager.registerFactory(MEMORY_SESSIONCACHE,&MemoryCacheFactory);
111 log.info("finished initializing");
115 bool STConfig::load(const char* config)
118 xmltooling::NDC ndc("load");
120 Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
123 log.fatal("path to configuration file not supplied");
129 log.info("loading configuration file: %s", config);
130 static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);
131 DOMImplementation* impl=DOMImplementationRegistry::getDOMImplementation(NULL);
132 DOMDocument* dummydoc=impl->createDocument();
133 xmltooling::XercesJanitor<DOMDocument> docjanitor(dummydoc);
134 DOMElement* dummy = dummydoc->createElementNS(NULL,path);
136 auto_ptr_XMLCh src(config);
137 dummy->setAttributeNS(NULL,path,src.get());
139 auto_ptr<ServiceProvider> sp(SPConfig::getConfig().ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));
142 pair<bool,unsigned int> skew=sp->getUnsignedInt("clockSkew");
143 SAMLConfig::getConfig().clock_skew_secs=skew.first ? skew.second : 180;
145 XMLToolingConfig::getConfig().clock_skew_secs=skew.second;
146 SPConfig::getConfig().setServiceProvider(sp.release());
148 m_tranLog=new FixedContextCategory(SHIBTRAN_LOGCAT);
149 m_tranLog->info("opened transaction log");
150 m_tranLogLock = xmltooling::Mutex::create();
152 catch (SAMLException& ex) {
153 log.fatal("caught exception while loading/initializing configuration: %s",ex.what());
159 log.fatal("caught exception while loading/initializing configuration");
165 log.info("finished loading configuration");
169 void STConfig::shutdown()
172 xmltooling::NDC ndc("shutdown");
174 Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
175 log.info("shutting down the library");
176 delete m_tranLogLock;
177 m_tranLogLock = NULL;
178 //delete m_tranLog; // This is crashing for some reason, but we're shutting down anyway.
179 SPConfig::getConfig().term();
180 ShibConfig::getConfig().term();
181 SAMLConfig::getConfig().term();
182 log.info("library shutdown complete");