Completed attribute remoting support.
[shibboleth/cpp-sp.git] / shibsp / SPConfig.cpp
1
2 /*
3  *  Copyright 2001-2007 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 "AccessControl.h"
26 #include "exceptions.h"
27 #include "Handler.h"
28 #include "RequestMapper.h"
29 #include "ServiceProvider.h"
30 #include "SessionCache.h"
31 #include "SPConfig.h"
32 #include "metadata/MetadataExt.h"
33 #include "remoting/ListenerService.h"
34 #include "security/PKIXTrustEngine.h"
35
36 #include "attribute/SimpleAttribute.h"
37 #include "attribute/ScopedAttribute.h"
38 #include "attribute/NameIDAttribute.h"
39
40 #include <log4cpp/Category.hh>
41 #include <saml/SAMLConfig.h>
42 #include <xmltooling/util/NDC.h>
43 #include <xmltooling/util/TemplateEngine.h>
44
45 using namespace shibsp;
46 using namespace opensaml;
47 using namespace xmltooling;
48 using namespace log4cpp;
49
50 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
51 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
52
53 namespace shibsp {
54    SPInternalConfig g_config;
55 }
56
57 SPConfig& SPConfig::getConfig()
58 {
59     return g_config;
60 }
61
62 SPInternalConfig& SPInternalConfig::getInternalConfig()
63 {
64     return g_config;
65 }
66
67 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
68 {
69     //delete m_serviceProvider;
70     m_serviceProvider = serviceProvider;
71 }
72
73 bool SPInternalConfig::init(const char* catalog_path)
74 {
75 #ifdef _DEBUG
76     NDC ndc("init");
77 #endif
78     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
79     log.debug("library initialization started");
80
81     const char* loglevel=getenv("SHIBSP_LOGGING");
82     if (!loglevel)
83         loglevel = SHIBSP_LOGGING;
84     XMLToolingConfig::getConfig().log_config(loglevel);
85
86     if (!catalog_path)
87         catalog_path = getenv("SHIBSP_SCHEMAS");
88     if (!catalog_path)
89         catalog_path = SHIBSP_SCHEMAS;
90     XMLToolingConfig::getConfig().catalog_path = catalog_path;
91
92     if (!SAMLConfig::getConfig().init()) {
93         log.fatal("failed to initialize OpenSAML library");
94         return false;
95     }
96
97     XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
98     XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
99     
100     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
101     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
102     
103     registerMetadataExtClasses();
104     registerPKIXTrustEngine();
105     registerAccessControls();
106     registerListenerServices();
107     registerRequestMappers();
108     registerSessionCaches();
109     registerServiceProviders();
110     registerAttributeFactories();
111     
112     log.info("library initialization complete");
113     return true;
114 }
115
116 void SPInternalConfig::term()
117 {
118 #ifdef _DEBUG
119     NDC ndc("term");
120 #endif
121     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
122     log.info("shutting down the library");
123
124     delete m_serviceProvider;
125     m_serviceProvider = NULL;
126
127     Attribute::deregisterFactories();
128     
129     SingleLogoutServiceManager.deregisterFactories();
130     SessionInitiatorManager.deregisterFactories();
131     SessionCacheManager.deregisterFactories();
132     ServiceProviderManager.deregisterFactories();
133     RequestMapperManager.deregisterFactories();
134     ManageNameIDServiceManager.deregisterFactories();
135     ListenerServiceManager.deregisterFactories();
136     HandlerManager.deregisterFactories();
137     AssertionConsumerServiceManager.deregisterFactories();
138     AccessControlManager.deregisterFactories();
139
140     SAMLConfig::getConfig().term();
141     log.info("library shutdown complete");
142 }