2 * shib-config.cpp -- ShibTarget initialization and finalization routines
4 * Created By: Derek Atkins <derek@ihtfp.com>
9 #include "shib-target.h"
11 #include <log4cpp/PropertyConfigurator.hh>
12 #include <log4cpp/Category.hh>
15 using namespace shibboleth;
16 using namespace shibtarget;
19 #ifndef SHIBTARGET_INIFILE
20 #define SHIBTARGET_INIFILE "/opt/shibboleth/etc/shibboleth/shibboleth.ini"
23 class STConfig : public ShibTargetConfig
26 STConfig(const char* app_name, const char* inifile);
29 ShibINI& getINI() { return *ini; }
40 STConfig * g_Config = NULL;
43 CCache* shibtarget::g_shibTargetCCache = NULL;
45 /****************************************************************************/
49 ShibTargetConfig& ShibTargetConfig::init(const char* app_name, const char* inifile)
52 throw runtime_error ("No Application name");
59 g_Config = new STConfig(app_name, inifile);
65 /****************************************************************************/
68 STConfig::STConfig(const char* app_name, const char* inifile)
69 : samlConf(SAMLConfig::getConfig()), shibConf(ShibConfig::getConfig())
71 ini = new ShibINI((inifile ? inifile : SHIBTARGET_INIFILE));
73 string app = app_name;
77 if (ini->get_tag (app, SHIBTARGET_TAG_LOGGER, true, &tag)) {
78 cerr << "Trying to load logger configuration: " << tag << "\n";
80 log4cpp::PropertyConfigurator::configure(tag);
81 } catch (log4cpp::ConfigureFailure& e) {
82 cerr << "Error reading configuration: " << e.what() << "\n";
85 log4cpp::Category& category = log4cpp::Category::getRoot();
86 category.setPriority(log4cpp::Priority::DEBUG);
87 cerr << "No logger configuration found\n";
90 log4cpp::Category& log = log4cpp::Category::getInstance("shibtarget.STConfig");
93 if (ini->get_tag (app, SHIBTARGET_TAG_SCHEMAS, true, &tag))
94 samlConf.schema_dir = tag;
95 if (ini->get_tag (app, SHIBTARGET_TAG_CERTFILE, true, &tag))
96 samlConf.ssl_certfile = tag;
97 if (ini->get_tag (app, SHIBTARGET_TAG_KEYFILE, true, &tag))
98 samlConf.ssl_keyfile = tag;
99 if (ini->get_tag (app, SHIBTARGET_TAG_KEYPASS, true, &tag))
100 samlConf.ssl_keypass = tag;
101 if (ini->get_tag (app, SHIBTARGET_TAG_CALIST, true, &tag))
102 samlConf.ssl_calist = tag;
104 if (!samlConf.init()) {
105 log.error ("Failed to initialize SAML Library");
106 throw runtime_error ("Failed to initialize SAML Library");
108 log.debug ("SAML Initialized");
111 if (! ini->get_tag (app, SHIBTARGET_TAG_SITES, true, &tag)) {
112 log.crit("No Sites File found in configuration");
113 throw runtime_error ("No Sites File found in configuration");
116 string sitesFile = tag;
117 X509Certificate* verifyKey = NULL;
119 if (ini->get_tag (app, SHIBTARGET_TAG_SITESCERT, true, &tag)) {
120 verifyKey = new X509Certificate (X509Certificate::PEM, tag.c_str());
123 shibConf.origin_mapper = new XMLOriginSiteMapper(sitesFile.c_str(),
124 samlConf.ssl_calist.c_str(),
130 if (!shibConf.init()) {
131 log.error ("Failed to initialize Shib library");
132 throw runtime_error ("Failed to initialize Shib Library");
134 log.debug ("Shib Initialized");
136 // Initialize the SHAR Cache
137 if (!strcmp (app_name, SHIBTARGET_SHAR))
138 g_shibTargetCCache = CCache::getInstance();
140 // Load any extensions
141 string ext = "extensions";
142 if (ini->exists(ext)) {
143 saml::NDC ndc("load extensions");
144 ShibINI::Iterator* iter = ini->tag_iterator(ext);
146 for (const string* str = iter->begin(); str; str = iter->next()) {
147 string file = ini->get(ext, *str);
150 samlConf.saml_register_extension(file.c_str(),ini);
151 log.debug("%s: loading %s", str->c_str(), file.c_str());
153 catch (SAMLException& e)
155 log.error("%s: %s", str->c_str(), e.what());
162 log.debug("finished");
165 STConfig::~STConfig()
169 if (g_shibTargetCCache)
170 delete g_shibTargetCCache;
172 delete shibConf.origin_mapper;
182 void STConfig::shutdown()