PKIX trust engine using metadata exts.
[shibboleth/sp.git] / shibsp / SPConfig.cpp
1
2 /*
3  *  Copyright 2001-2006 Internet2
4  * 
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /**
19  * SPConfig.cpp
20  * 
21  * Library configuration 
22  */
23
24 #include "internal.h"
25 #include "exceptions.h"
26 #include "ListenerService.h"
27 #include "MetadataExt.h"
28 #include "PKIXTrustEngine.h"
29 #include "SPConfig.h"
30
31 #include <log4cpp/Category.hh>
32 #include <saml/SAMLConfig.h>
33 #include <xmltooling/util/NDC.h>
34 #include <xmltooling/util/TemplateEngine.h>
35
36 using namespace shibsp;
37 using namespace opensaml;
38 using namespace xmltooling;
39 using namespace log4cpp;
40
41 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
42 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
43
44 namespace shibsp {
45    SPInternalConfig g_config;
46 }
47
48 SPConfig& SPConfig::getConfig()
49 {
50     return g_config;
51 }
52
53 SPInternalConfig& SPInternalConfig::getInternalConfig()
54 {
55     return g_config;
56 }
57
58 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
59 {
60     //delete m_serviceProvider;
61     m_serviceProvider = serviceProvider;
62 }
63
64 bool SPInternalConfig::init(const char* catalog_path)
65 {
66 #ifdef _DEBUG
67     NDC ndc("init");
68 #endif
69     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
70     log.debug("library initialization started");
71
72     const char* loglevel=getenv("SHIBSP_LOGGING");
73     if (!loglevel)
74         loglevel = SHIBSP_LOGGING;
75     XMLToolingConfig::getConfig().log_config(loglevel);
76
77     if (catalog_path)
78         XMLToolingConfig::getConfig().catalog_path = catalog_path;
79
80     if (!SAMLConfig::getConfig().init()) {
81         log.fatal("failed to initialize OpenSAML library");
82         return false;
83     }
84
85     XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
86     XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
87     
88     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
89     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
90     
91     registerListenerServices();
92     registerMetadataExtClasses();
93     registerPKIXTrustEngine();
94
95     log.info("library initialization complete");
96     return true;
97 }
98
99 void SPInternalConfig::term()
100 {
101 #ifdef _DEBUG
102     NDC ndc("term");
103 #endif
104     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
105     log.info("shutting down the library");
106
107     //delete m_serviceProvider;
108     m_serviceProvider = NULL;
109     
110     ListenerServiceManager.deregisterFactories();
111
112     SAMLConfig::getConfig().term();
113     log.info("library shutdown complete");
114 }