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>
27 #if defined(HAVE_LOG4SHIB)
28 # include <log4shib/OstreamAppender.hh>
29 #elif defined(HAVE_LOG4CPP)
30 # include <log4cpp/OstreamAppender.hh>
32 # error "Supported logging library not available."
37 using namespace shibboleth;
38 using namespace shibtarget;
39 using namespace shibtarget::logging;
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 XMLRequestMapFactory;
54 PlugManager::Factory ShibSessionInitiatorFactory;
55 PlugManager::Factory SAML1POSTFactory;
56 PlugManager::Factory SAML1ArtifactFactory;
57 PlugManager::Factory ShibLogoutFactory;
58 //PlugManager::Factory htaccessFactory;
60 SAML_EXCEPTION_FACTORY(ListenerException);
61 SAML_EXCEPTION_FACTORY(ConfigurationException);
63 ShibTargetConfig& ShibTargetConfig::getConfig()
68 bool STConfig::init(const char* schemadir)
70 // With new build of log4cpp, we need to establish a "default"
71 // logging appender to stderr up front.
72 const char* loglevel=getenv("SHIB_LOGGING");
74 loglevel = SHIB_LOGGING;
75 Category& root = Category::getRoot();
76 if (!strcmp(loglevel,"DEBUG"))
77 root.setPriority(Priority::DEBUG);
78 else if (!strcmp(loglevel,"INFO"))
79 root.setPriority(Priority::INFO);
80 else if (!strcmp(loglevel,"NOTICE"))
81 root.setPriority(Priority::NOTICE);
82 else if (!strcmp(loglevel,"WARN"))
83 root.setPriority(Priority::WARN);
84 else if (!strcmp(loglevel,"ERROR"))
85 root.setPriority(Priority::ERROR);
86 else if (!strcmp(loglevel,"CRIT"))
87 root.setPriority(Priority::CRIT);
88 else if (!strcmp(loglevel,"ALERT"))
89 root.setPriority(Priority::ALERT);
90 else if (!strcmp(loglevel,"EMERG"))
91 root.setPriority(Priority::EMERG);
92 else if (!strcmp(loglevel,"FATAL"))
93 root.setPriority(Priority::FATAL);
94 root.setAppender(new OstreamAppender("default",&cerr));
97 saml::NDC ndc("init");
99 Category& log = Category::getInstance("shibtarget.Config");
102 log.fatal("XML schema directory not supplied");
106 // This will cause some extra console logging, but for now,
107 // initialize the underlying libraries.
108 SAMLConfig& samlConf=SAMLConfig::getConfig();
110 samlConf.schema_dir = schemadir;
112 if (!samlConf.init()) {
113 log.fatal("Failed to initialize SAML Library");
118 log.fatal("Died initializing SAML Library");
122 ShibConfig& shibConf=ShibConfig::getConfig();
124 if (!shibConf.init()) {
125 log.fatal("Failed to initialize Shib library");
131 log.fatal("Died initializing Shib library.");
136 // Register built-in plugin types.
137 REGISTER_EXCEPTION_FACTORY(ListenerException);
138 REGISTER_EXCEPTION_FACTORY(ConfigurationException);
140 samlConf.getPlugMgr().regFactory(shibtarget::XML::UnixListenerType,&UnixListenerFactory);
142 samlConf.getPlugMgr().regFactory(shibtarget::XML::TCPListenerType,&TCPListenerFactory);
143 samlConf.getPlugMgr().regFactory(shibtarget::XML::MemoryListenerType,&MemoryListenerFactory);
144 samlConf.getPlugMgr().regFactory(shibtarget::XML::MemorySessionCacheType,&MemoryCacheFactory);
145 samlConf.getPlugMgr().regFactory(shibtarget::XML::LegacyRequestMapType,&XMLRequestMapFactory);
146 samlConf.getPlugMgr().regFactory(shibtarget::XML::XMLRequestMapType,&XMLRequestMapFactory);
147 samlConf.getPlugMgr().regFactory(shibtarget::XML::NativeRequestMapType,&XMLRequestMapFactory);
149 auto_ptr_char temp1(Constants::SHIB_SESSIONINIT_PROFILE_URI);
150 samlConf.getPlugMgr().regFactory(temp1.get(),&ShibSessionInitiatorFactory);
151 auto_ptr_char temp2(SAMLBrowserProfile::BROWSER_POST);
152 samlConf.getPlugMgr().regFactory(temp2.get(),&SAML1POSTFactory);
153 auto_ptr_char temp3(SAMLBrowserProfile::BROWSER_ARTIFACT);
154 samlConf.getPlugMgr().regFactory(temp3.get(),&SAML1ArtifactFactory);
155 auto_ptr_char temp4(Constants::SHIB_LOGOUT_PROFILE_URI);
156 samlConf.getPlugMgr().regFactory(temp4.get(),&ShibLogoutFactory);
158 saml::XML::registerSchema(shibtarget::XML::SHIBTARGET_NS,shibtarget::XML::SHIBTARGET_SCHEMA_ID,NULL,false);
159 saml::XML::registerSchema(shibtarget::XML::SAML2META_NS,shibtarget::XML::SAML2META_SCHEMA_ID,NULL,false);
160 saml::XML::registerSchema(shibtarget::XML::SAML2ASSERT_NS,shibtarget::XML::SAML2ASSERT_SCHEMA_ID,NULL,false);
161 saml::XML::registerSchema(shibtarget::XML::XMLENC_NS,shibtarget::XML::XMLENC_SCHEMA_ID,NULL,false);
163 log.info("finished initializing");
167 bool STConfig::load(const char* config)
170 saml::NDC ndc("load");
172 Category& log = Category::getInstance("shibtarget.Config");
175 log.fatal("path to configuration file not supplied");
181 log.info("loading configuration file: %s", config);
182 static const XMLCh uri[] = { chLatin_u, chLatin_r, chLatin_i, chNull };
183 DOMImplementation* impl=DOMImplementationRegistry::getDOMImplementation(NULL);
184 DOMDocument* dummydoc=impl->createDocument();
185 DOMElement* dummy = dummydoc->createElementNS(NULL,XML::Literals::ShibbolethTargetConfig);
186 auto_ptr_XMLCh src(config);
187 dummy->setAttributeNS(NULL,uri,src.get());
188 m_ini=ShibTargetConfigFactory(dummy);
191 pair<bool,unsigned int> skew=m_ini->getUnsignedInt("clockSkew");
192 SAMLConfig::getConfig().clock_skew_secs=skew.first ? skew.second : 180;
194 m_tranLog=new FixedContextCategory(SHIBTRAN_LOGCAT);
195 m_tranLog->info("opened transaction log");
196 m_tranLogLock = Mutex::create();
198 catch (SAMLException& ex) {
199 log.fatal("caught exception while loading/initializing configuration: %s",ex.what());
205 log.fatal("caught exception while loading/initializing configuration");
211 log.info("finished loading configuration");
215 void STConfig::shutdown()
218 saml::NDC ndc("shutdown");
220 Category& log = Category::getInstance("shibtarget.Config");
221 log.info("shutting down the library");
222 delete m_tranLogLock;
223 m_tranLogLock = NULL;
224 //delete m_tranLog; // This is crashing for some reason, but we're shutting down anyway.
227 ShibConfig::getConfig().term();
228 SAMLConfig::getConfig().term();
229 log.info("library shutdown complete");