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/AttributeExtractor.h"
33 #include "attribute/resolver/AttributeResolver.h"
34 #include "binding/ArtifactResolver.h"
35 #include "handler/SessionInitiator.h"
36 #include "metadata/MetadataExt.h"
37 #include "remoting/ListenerService.h"
38 #include "security/PKIXTrustEngine.h"
40 #include <log4cpp/Category.hh>
41 #include <saml/SAMLConfig.h>
42 #include <xmltooling/util/NDC.h>
43 #include <xmltooling/util/TemplateEngine.h>
45 using namespace shibsp;
46 using namespace opensaml;
47 using namespace xmltooling;
48 using namespace log4cpp;
50 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
51 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
52 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
53 DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
54 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
55 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
58 SPInternalConfig g_config;
61 SPConfig& SPConfig::getConfig()
66 SPInternalConfig& SPInternalConfig::getInternalConfig()
71 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
73 delete m_serviceProvider;
74 m_serviceProvider = serviceProvider;
77 bool SPInternalConfig::init(const char* catalog_path)
82 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
83 log.debug("library initialization started");
85 const char* loglevel=getenv("SHIBSP_LOGGING");
87 loglevel = SHIBSP_LOGGING;
88 XMLToolingConfig::getConfig().log_config(loglevel);
91 catalog_path = getenv("SHIBSP_SCHEMAS");
93 catalog_path = SHIBSP_SCHEMAS;
94 XMLToolingConfig::getConfig().catalog_path = catalog_path;
96 if (!SAMLConfig::getConfig().init()) {
97 log.fatal("failed to initialize OpenSAML library");
101 XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
102 XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
104 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
105 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
106 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
107 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
108 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
109 REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
111 registerMetadataExtClasses();
112 registerPKIXTrustEngine();
114 registerAccessControls();
115 registerAttributeDecoders();
116 registerAttributeExtractors();
117 registerAttributeFactories();
118 registerAttributeResolvers();
120 registerSessionInitiators();
121 registerListenerServices();
122 registerRequestMappers();
123 registerSessionCaches();
124 registerServiceProviders();
126 if (isEnabled(OutOfProcess))
127 m_artifactResolver = new ArtifactResolver();
129 log.info("library initialization complete");
133 void SPInternalConfig::term()
138 Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
139 log.info("shutting down the library");
141 setServiceProvider(NULL);
142 setArtifactResolver(NULL);
144 AssertionConsumerServiceManager.deregisterFactories();
145 ManageNameIDServiceManager.deregisterFactories();
146 SessionInitiatorManager.deregisterFactories();
147 SingleLogoutServiceManager.deregisterFactories();
149 ServiceProviderManager.deregisterFactories();
150 SessionCacheManager.deregisterFactories();
151 RequestMapperManager.deregisterFactories();
152 ListenerServiceManager.deregisterFactories();
153 HandlerManager.deregisterFactories();
154 AttributeDecoderManager.deregisterFactories();
155 AttributeExtractorManager.deregisterFactories();
156 AttributeResolverManager.deregisterFactories();
157 Attribute::deregisterFactories();
158 AccessControlManager.deregisterFactories();
160 SAMLConfig::getConfig().term();
161 log.info("library shutdown complete");