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;
52 PlugManager::Factory MemoryCacheFactory;
53 PlugManager::Factory ShibSessionInitiatorFactory;
54 PlugManager::Factory SAML1POSTFactory;
55 PlugManager::Factory SAML1ArtifactFactory;
56 PlugManager::Factory ShibLogoutFactory;
57 //PlugManager::Factory htaccessFactory;
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 if (!SPConfig::getConfig().init(NULL)) {
94 log.fatal("Failed to initialize SP library");
100 // Register built-in plugin types.
101 SPConfig::getConfig().ServiceProviderManager.registerFactory(XML_SERVICE_PROVIDER, XMLServiceProviderFactory);
103 samlConf.getPlugMgr().regFactory(MEMORY_SESSIONCACHE,&MemoryCacheFactory);
105 auto_ptr_char temp1(shibspconstants::SHIB1_SESSIONINIT_PROFILE_URI);
106 samlConf.getPlugMgr().regFactory(temp1.get(),&ShibSessionInitiatorFactory);
107 samlConf.getPlugMgr().regFactory(samlconstants::SAML1_PROFILE_BROWSER_POST,&SAML1POSTFactory);
108 samlConf.getPlugMgr().regFactory(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT,&SAML1ArtifactFactory);
109 auto_ptr_char temp4(shibspconstants::SHIB1_LOGOUT_PROFILE_URI);
110 samlConf.getPlugMgr().regFactory(temp4.get(),&ShibLogoutFactory);
112 log.info("finished initializing");
116 bool STConfig::load(const char* config)
119 xmltooling::NDC ndc("load");
121 Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
124 log.fatal("path to configuration file not supplied");
130 log.info("loading configuration file: %s", config);
131 static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);
132 DOMImplementation* impl=DOMImplementationRegistry::getDOMImplementation(NULL);
133 DOMDocument* dummydoc=impl->createDocument();
134 xmltooling::XercesJanitor<DOMDocument> docjanitor(dummydoc);
135 DOMElement* dummy = dummydoc->createElementNS(NULL,path);
137 auto_ptr_XMLCh src(config);
138 dummy->setAttributeNS(NULL,path,src.get());
140 auto_ptr<ServiceProvider> sp(SPConfig::getConfig().ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));
143 pair<bool,unsigned int> skew=sp->getUnsignedInt("clockSkew");
144 SAMLConfig::getConfig().clock_skew_secs=skew.first ? skew.second : 180;
146 XMLToolingConfig::getConfig().clock_skew_secs=skew.second;
147 SPConfig::getConfig().setServiceProvider(sp.release());
149 m_tranLog=new FixedContextCategory(SHIBTRAN_LOGCAT);
150 m_tranLog->info("opened transaction log");
151 m_tranLogLock = xmltooling::Mutex::create();
153 catch (SAMLException& ex) {
154 log.fatal("caught exception while loading/initializing configuration: %s",ex.what());
160 log.fatal("caught exception while loading/initializing configuration");
166 log.info("finished loading configuration");
170 void STConfig::shutdown()
173 xmltooling::NDC ndc("shutdown");
175 Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
176 log.info("shutting down the library");
177 delete m_tranLogLock;
178 m_tranLogLock = NULL;
179 //delete m_tranLog; // This is crashing for some reason, but we're shutting down anyway.
180 SPConfig::getConfig().term();
181 ShibConfig::getConfig().term();
182 SAMLConfig::getConfig().term();
183 log.info("library shutdown complete");