Next integration phase, metadata and trust conversion.
[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         catalog_path = getenv("SHIBSP_SCHEMAS");
79     if (!catalog_path)
80         catalog_path = SHIBSP_SCHEMAS;
81     XMLToolingConfig::getConfig().catalog_path = catalog_path;
82
83     if (!SAMLConfig::getConfig().init()) {
84         log.fatal("failed to initialize OpenSAML library");
85         return false;
86     }
87
88     XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
89     XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
90     
91     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
92     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
93     
94     registerListenerServices();
95     registerMetadataExtClasses();
96     registerPKIXTrustEngine();
97
98     log.info("library initialization complete");
99     return true;
100 }
101
102 void SPInternalConfig::term()
103 {
104 #ifdef _DEBUG
105     NDC ndc("term");
106 #endif
107     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
108     log.info("shutting down the library");
109
110     //delete m_serviceProvider;
111     m_serviceProvider = NULL;
112     
113     ListenerServiceManager.deregisterFactories();
114
115     SAMLConfig::getConfig().term();
116     log.info("library shutdown complete");
117 }