Attribute filtering code.
[shibboleth/sp.git] / shibsp / SPConfig.cpp
index 90bd9c2..ff26b4a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- *  Copyright 2001-2006 Internet2
+ *  Copyright 2001-2007 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 #include "internal.h"
+#include "AccessControl.h"
 #include "exceptions.h"
-#include "ListenerService.h"
+#include "RequestMapper.h"
+#include "ServiceProvider.h"
+#include "SessionCache.h"
 #include "SPConfig.h"
+#include "attribute/AttributeDecoder.h"
+#include "attribute/filtering/AttributeFilter.h"
+#include "attribute/filtering/MatchFunctor.h"
+#include "attribute/resolver/AttributeExtractor.h"
+#include "attribute/resolver/AttributeResolver.h"
+#include "binding/ArtifactResolver.h"
+#include "handler/SessionInitiator.h"
+#include "metadata/MetadataExt.h"
+#include "remoting/ListenerService.h"
+#include "security/PKIXTrustEngine.h"
 
 #include <log4cpp/Category.hh>
 #include <saml/SAMLConfig.h>
@@ -36,6 +49,10 @@ using namespace opensaml;
 using namespace xmltooling;
 using namespace log4cpp;
 
+DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
+DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
+DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
+DECL_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
 
@@ -55,7 +72,7 @@ SPInternalConfig& SPInternalConfig::getInternalConfig()
 
 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
 {
-    //delete m_serviceProvider;
+    delete m_serviceProvider;
     m_serviceProvider = serviceProvider;
 }
 
@@ -72,8 +89,11 @@ bool SPInternalConfig::init(const char* catalog_path)
         loglevel = SHIBSP_LOGGING;
     XMLToolingConfig::getConfig().log_config(loglevel);
 
-    if (catalog_path)
-        XMLToolingConfig::getConfig().catalog_path = catalog_path;
+    if (!catalog_path)
+        catalog_path = getenv("SHIBSP_SCHEMAS");
+    if (!catalog_path)
+        catalog_path = SHIBSP_SCHEMAS;
+    XMLToolingConfig::getConfig().catalog_path = catalog_path;
 
     if (!SAMLConfig::getConfig().init()) {
         log.fatal("failed to initialize OpenSAML library");
@@ -83,11 +103,45 @@ bool SPInternalConfig::init(const char* catalog_path)
     XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
     XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
     
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeException,shibsp);
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeExtractionException,shibsp);
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeFilteringException,shibsp);
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(AttributeResolutionException,shibsp);
     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
     
-    registerListenerServices();
+    if (isEnabled(Metadata))
+        registerMetadataExtClasses();
+    if (isEnabled(Trust))
+        registerPKIXTrustEngine();
+
+    registerAttributeFactories();
+    registerHandlers();
+    registerSessionInitiators();
+    registerServiceProviders();
+
+    if (isEnabled(AttributeResolution)) {
+        registerAttributeDecoders();
+        registerAttributeExtractors();
+        registerAttributeFilters();
+        registerAttributeResolvers();
+        registerMatchFunctors();
+    }
+
+    if (isEnabled(Listener))
+        registerListenerServices();
+
+    if (isEnabled(RequestMapping)) {
+        registerAccessControls();
+        registerRequestMappers();
+    }
+
+    if (isEnabled(Caching))
+        registerSessionCaches();
 
+    if (isEnabled(OutOfProcess))
+        m_artifactResolver = new ArtifactResolver();
+    
     log.info("library initialization complete");
     return true;
 }
@@ -100,10 +154,35 @@ void SPInternalConfig::term()
     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
     log.info("shutting down the library");
 
-    //delete m_serviceProvider;
-    m_serviceProvider = NULL;
-    
-    ListenerServiceManager.deregisterFactories();
+    setServiceProvider(NULL);
+    setArtifactResolver(NULL);
+
+    AssertionConsumerServiceManager.deregisterFactories();
+    ManageNameIDServiceManager.deregisterFactories();
+    SessionInitiatorManager.deregisterFactories();
+    SingleLogoutServiceManager.deregisterFactories();
+    HandlerManager.deregisterFactories();
+    ServiceProviderManager.deregisterFactories();
+    Attribute::deregisterFactories();
+
+    if (isEnabled(AttributeResolution)) {
+        MatchFunctorManager.deregisterFactories();
+        AttributeDecoderManager.deregisterFactories();
+        AttributeFilterManager.deregisterFactories();
+        AttributeExtractorManager.deregisterFactories();
+        AttributeResolverManager.deregisterFactories();
+    }
+
+    if (isEnabled(Listener))
+        ListenerServiceManager.deregisterFactories();
+
+    if (isEnabled(RequestMapping)) {
+        AccessControlManager.deregisterFactories();
+        RequestMapperManager.deregisterFactories();
+    }
+
+    if (isEnabled(Caching))
+        SessionCacheManager.deregisterFactories();
 
     SAMLConfig::getConfig().term();
     log.info("library shutdown complete");