New -lite library and elimination of SAML libraries from modules.
[shibboleth/cpp-sp.git] / shibsp / SPConfig.cpp
index 737ff08..3df7a26 100644 (file)
 #include "internal.h"
 #include "AccessControl.h"
 #include "exceptions.h"
-#include "Handler.h"
 #include "RequestMapper.h"
 #include "ServiceProvider.h"
 #include "SessionCache.h"
 #include "SPConfig.h"
-#include "metadata/MetadataExt.h"
+#include "attribute/Attribute.h"
+#include "handler/SessionInitiator.h"
 #include "remoting/ListenerService.h"
-#include "security/PKIXTrustEngine.h"
 
-#include "attribute/SimpleAttribute.h"
-#include "attribute/ScopedAttribute.h"
-#include "attribute/NameIDAttribute.h"
+#ifndef SHIBSP_LITE
+# 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 "metadata/MetadataExt.h"
+# include "security/PKIXTrustEngine.h"
+# include <saml/SAMLConfig.h>
+#else
+# include <xmltooling/XMLToolingConfig.h>
+#endif
 
 #include <log4cpp/Category.hh>
-#include <saml/SAMLConfig.h>
 #include <xmltooling/util/NDC.h>
 #include <xmltooling/util/TemplateEngine.h>
 
@@ -47,9 +55,21 @@ 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);
 
+#ifdef SHIBSP_LITE
+DECL_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
+DECL_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
+DECL_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
+DECL_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
+DECL_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
+#endif
+
 namespace shibsp {
    SPInternalConfig g_config;
 }
@@ -66,7 +86,7 @@ SPInternalConfig& SPInternalConfig::getInternalConfig()
 
 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
 {
-    //delete m_serviceProvider;
+    delete m_serviceProvider;
     m_serviceProvider = serviceProvider;
 }
 
@@ -89,25 +109,74 @@ bool SPInternalConfig::init(const char* catalog_path)
         catalog_path = SHIBSP_SCHEMAS;
     XMLToolingConfig::getConfig().catalog_path = catalog_path;
 
+#ifndef SHIBSP_LITE
     if (!SAMLConfig::getConfig().init()) {
         log.fatal("failed to initialize OpenSAML library");
         return false;
     }
+#else
+    if (!XMLToolingConfig::getConfig().init()) {
+        log.fatal("failed to initialize XMLTooling library");
+        return false;
+    }
+#endif
 
     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);
-    
-    registerMetadataExtClasses();
-    registerPKIXTrustEngine();
-    registerAccessControls();
-    registerListenerServices();
-    registerRequestMappers();
-    registerSessionCaches();
+
+#ifdef SHIBSP_LITE
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(SecurityPolicyException,opensaml);
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ProfileException,opensaml);
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(FatalProfileException,opensaml);
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(RetryableProfileException,opensaml);
+    REGISTER_XMLTOOLING_EXCEPTION_FACTORY(MetadataException,opensaml::saml2md);
+#endif
+
+#ifndef SHIBSP_LITE
+    if (isEnabled(Metadata))
+        registerMetadataExtClasses();
+    if (isEnabled(Trust))
+        registerPKIXTrustEngine();
+#endif
+
+    registerAttributeFactories();
+    registerHandlers();
+    registerSessionInitiators();
     registerServiceProviders();
 
+#ifndef SHIBSP_LITE
+    if (isEnabled(AttributeResolution)) {
+        registerAttributeExtractors();
+        registerAttributeDecoders();
+        registerAttributeResolvers();
+        registerAttributeFilters();
+        registerMatchFunctors();
+    }
+#endif
+
+    if (isEnabled(Listener))
+        registerListenerServices();
+
+    if (isEnabled(RequestMapping)) {
+        registerAccessControls();
+        registerRequestMappers();
+    }
+
+    if (isEnabled(Caching))
+        registerSessionCaches();
+
+#ifndef SHIBSP_LITE
+    if (isEnabled(OutOfProcess))
+        m_artifactResolver = new ArtifactResolver();
+#endif
+
     log.info("library initialization complete");
     return true;
 }
@@ -120,20 +189,44 @@ void SPInternalConfig::term()
     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
     log.info("shutting down the library");
 
-    delete m_serviceProvider;
-    m_serviceProvider = NULL;
-    
-    SingleLogoutServiceManager.deregisterFactories();
-    SessionInitiatorManager.deregisterFactories();
-    SessionCacheManager.deregisterFactories();
-    ServiceProviderManager.deregisterFactories();
-    RequestMapperManager.deregisterFactories();
+    setServiceProvider(NULL);
+#ifndef SHIBSP_LITE
+    setArtifactResolver(NULL);
+#endif
+
+    AssertionConsumerServiceManager.deregisterFactories();
     ManageNameIDServiceManager.deregisterFactories();
-    ListenerServiceManager.deregisterFactories();
+    SessionInitiatorManager.deregisterFactories();
+    SingleLogoutServiceManager.deregisterFactories();
     HandlerManager.deregisterFactories();
-    AssertionConsumerServiceManager.deregisterFactories();
-    AccessControlManager.deregisterFactories();
+    ServiceProviderManager.deregisterFactories();
+    Attribute::deregisterFactories();
+
+#ifndef SHIBSP_LITE
+    if (isEnabled(AttributeResolution)) {
+        MatchFunctorManager.deregisterFactories();
+        AttributeFilterManager.deregisterFactories();
+        AttributeDecoderManager.deregisterFactories();
+        AttributeExtractorManager.deregisterFactories();
+        AttributeResolverManager.deregisterFactories();
+    }
+#endif
 
+    if (isEnabled(Listener))
+        ListenerServiceManager.deregisterFactories();
+
+    if (isEnabled(RequestMapping)) {
+        AccessControlManager.deregisterFactories();
+        RequestMapperManager.deregisterFactories();
+    }
+
+    if (isEnabled(Caching))
+        SessionCacheManager.deregisterFactories();
+
+#ifndef SHIBSP_LITE
     SAMLConfig::getConfig().term();
+#else
+    XMLToolingConfig::getConfig().term();
+#endif
     log.info("library shutdown complete");
 }