3 * Copyright 2001-2007 Internet2
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * Library configuration
25 #include "AccessControl.h"
26 #include "exceptions.h"
27 #include "RequestMapper.h"
28 #include "ServiceProvider.h"
29 #include "SessionCache.h"
31 #include "attribute/AttributeDecoder.h"
32 #include "attribute/resolver/AttributeResolver.h"
33 #include "handler/Handler.h"
34 #include "metadata/MetadataExt.h"
35 #include "remoting/ListenerService.h"
36 #include "security/PKIXTrustEngine.h"
38 #include <log4cpp/Category.hh>
39 #include <saml/SAMLConfig.h>
40 #include <xmltooling/util/NDC.h>
41 #include <xmltooling/util/TemplateEngine.h>
43 using namespace shibsp;
44 using namespace opensaml;
45 using namespace xmltooling;
46 using namespace log4cpp;
48 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
49 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
50 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
51 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
54 SPInternalConfig g_config;
57 SPConfig& SPConfig::getConfig()
62 SPInternalConfig& SPInternalConfig::getInternalConfig()
67 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
69 delete m_serviceProvider;
70 m_serviceProvider = serviceProvider;
73 bool SPInternalConfig::init(const char* catalog_path)
78 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
79 log.debug("library initialization started");
81 const char* loglevel=getenv("SHIBSP_LOGGING");
83 loglevel = SHIBSP_LOGGING;
84 XMLToolingConfig::getConfig().log_config(loglevel);
87 catalog_path = getenv("SHIBSP_SCHEMAS");
89 catalog_path = SHIBSP_SCHEMAS;
90 XMLToolingConfig::getConfig().catalog_path = catalog_path;
92 if (!SAMLConfig::getConfig().init()) {
93 log.fatal("failed to initialize OpenSAML library");
97 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
98 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
100 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
101 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
102 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
103 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
105 registerMetadataExtClasses();
106 registerPKIXTrustEngine();
108 registerAccessControls();
109 registerAttributeDecoders();
110 registerAttributeFactories();
111 registerAttributeResolvers();
112 registerListenerServices();
113 registerRequestMappers();
114 registerSessionCaches();
115 registerServiceProviders();
117 log.info("library initialization complete");
121 void SPInternalConfig::term()
126 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
127 log.info("shutting down the library");
129 delete m_serviceProvider;
130 m_serviceProvider = NULL;
132 AssertionConsumerServiceManager.deregisterFactories();
133 ManageNameIDServiceManager.deregisterFactories();
134 SessionInitiatorManager.deregisterFactories();
135 SingleLogoutServiceManager.deregisterFactories();
137 ServiceProviderManager.deregisterFactories();
138 SessionCacheManager.deregisterFactories();
139 RequestMapperManager.deregisterFactories();
140 ListenerServiceManager.deregisterFactories();
141 HandlerManager.deregisterFactories();
142 AttributeResolverManager.deregisterFactories();
143 AttributeDecoderManager.deregisterFactories();
144 Attribute::deregisterFactories();
145 AccessControlManager.deregisterFactories();
147 SAMLConfig::getConfig().term();
148 log.info("library shutdown complete");