2 * Copyright 2001-2007 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<Handler,const DOMElement*>::Factory ShibSessionInitiatorFactory;
54 PluginManager<Handler,const DOMElement*>::Factory SAML1POSTFactory;
55 PluginManager<Handler,const DOMElement*>::Factory SAML1ArtifactFactory;
56 PluginManager<Handler,const DOMElement*>::Factory ShibLogoutFactory;
58 ShibTargetConfig& ShibTargetConfig::getConfig()
63 bool STConfig::init(const char* schemadir)
66 xmltooling::NDC ndc("init");
68 Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
71 log.fatal("XML schema directory not supplied");
75 // This will cause some extra console logging, but for now,
76 // initialize the underlying libraries.
77 SAMLConfig& samlConf=SAMLConfig::getConfig();
79 samlConf.schema_dir = schemadir;
80 if (!samlConf.init()) {
81 log.fatal("failed to initialize OpenSAML1 library");
85 ShibConfig& shibConf=ShibConfig::getConfig();
86 if (!shibConf.init()) {
87 log.fatal("Failed to initialize Shib library");
92 SPConfig& conf=SPConfig::getConfig();
93 if (!SPConfig::getConfig().init(NULL)) {
94 log.fatal("Failed to initialize SP library");
100 // Register built-in plugin types.
101 conf.ServiceProviderManager.registerFactory(XML_SERVICE_PROVIDER, XMLServiceProviderFactory);
103 conf.SessionInitiatorManager.registerFactory(shibspconstants::SHIB1_SESSIONINIT_PROFILE_URI,&ShibSessionInitiatorFactory);
104 conf.AssertionConsumerServiceManager.registerFactory(samlconstants::SAML1_PROFILE_BROWSER_POST,&SAML1POSTFactory);
105 conf.AssertionConsumerServiceManager.registerFactory(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT,&SAML1ArtifactFactory);
106 conf.SingleLogoutServiceManager.registerFactory(shibspconstants::SHIB1_LOGOUT_PROFILE_URI,&ShibLogoutFactory);
108 log.info("finished initializing");
112 bool STConfig::load(const char* config)
115 xmltooling::NDC ndc("load");
117 Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
120 log.fatal("path to configuration file not supplied");
126 log.info("loading configuration file: %s", config);
127 static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);
128 DOMImplementation* impl=DOMImplementationRegistry::getDOMImplementation(NULL);
129 DOMDocument* dummydoc=impl->createDocument();
130 xmltooling::XercesJanitor<DOMDocument> docjanitor(dummydoc);
131 DOMElement* dummy = dummydoc->createElementNS(NULL,path);
133 auto_ptr_XMLCh src(config);
134 dummy->setAttributeNS(NULL,path,src.get());
136 auto_ptr<ServiceProvider> sp(SPConfig::getConfig().ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));
139 pair<bool,unsigned int> skew=sp->getUnsignedInt("clockSkew");
140 SAMLConfig::getConfig().clock_skew_secs=skew.first ? skew.second : 180;
141 SPConfig::getConfig().setServiceProvider(sp.release());
143 m_tranLog=new FixedContextCategory(SHIBTRAN_LOGCAT);
144 m_tranLog->info("opened transaction log");
145 m_tranLogLock = xmltooling::Mutex::create();
147 catch (SAMLException& ex) {
148 log.fatal("caught exception while loading/initializing configuration: %s",ex.what());
154 log.fatal("caught exception while loading/initializing configuration");
160 log.info("finished loading configuration");
164 void STConfig::shutdown()
167 xmltooling::NDC ndc("shutdown");
169 Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
170 log.info("shutting down the library");
171 delete m_tranLogLock;
172 m_tranLogLock = NULL;
173 //delete m_tranLog; // This is crashing for some reason, but we're shutting down anyway.
174 SPConfig::getConfig().term();
175 ShibConfig::getConfig().term();
176 SAMLConfig::getConfig().term();
177 log.info("library shutdown complete");