https://bugs.internet2.edu/jira/browse/SSPCPP-293
[shibboleth/sp.git] / shibsp / SPConfig.cpp
index 8c1fa44..f89ee17 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@
 #include "ServiceProvider.h"
 #include "SessionCache.h"
 #include "SPConfig.h"
+#include "TransactionLog.h"
 #include "attribute/Attribute.h"
 #include "handler/SessionInitiator.h"
 #include "remoting/ListenerService.h"
@@ -54,6 +55,7 @@
 # include "binding/ArtifactResolver.h"
 # include "metadata/MetadataExt.h"
 # include "security/PKIXTrustEngine.h"
+# include "security/SecurityPolicyProvider.h"
 # include <saml/SAMLConfig.h>
 #endif
 
@@ -64,6 +66,7 @@
 #include <xmltooling/util/ParserPool.h>
 #include <xmltooling/util/PathResolver.h>
 #include <xmltooling/util/TemplateEngine.h>
+#include <xmltooling/util/Threads.h>
 #include <xmltooling/util/XMLHelper.h>
 
 using namespace shibsp;
@@ -96,12 +99,52 @@ SPConfig& SPConfig::getConfig()
     return g_config;
 }
 
+SPConfig::SPConfig() : attribute_value_delimeter(';'), m_serviceProvider(nullptr),
+#ifndef SHIBSP_LITE
+    m_artifactResolver(nullptr),
+#endif
+    m_features(0), m_configDoc(nullptr)
+{
+}
+
+SPConfig::~SPConfig()
+{
+}
+
+void SPConfig::setFeatures(unsigned long enabled)
+{
+    m_features = enabled;
+}
+
+bool SPConfig::isEnabled(components_t feature)
+{
+    return (m_features & feature)>0;
+}
+
+ServiceProvider* SPConfig::getServiceProvider() const
+{
+    return m_serviceProvider;
+}
+
 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
 {
     delete m_serviceProvider;
     m_serviceProvider = serviceProvider;
 }
 
+#ifndef SHIBSP_LITE
+void SPConfig::setArtifactResolver(MessageDecoder::ArtifactResolver* artifactResolver)
+{
+    delete m_artifactResolver;
+    m_artifactResolver = artifactResolver;
+}
+
+const MessageDecoder::ArtifactResolver* SPConfig::getArtifactResolver() const
+{
+    return m_artifactResolver;
+}
+#endif
+
 bool SPConfig::init(const char* catalog_path, const char* inst_prefix)
 {
 #ifdef _DEBUG
@@ -209,6 +252,7 @@ bool SPConfig::init(const char* catalog_path, const char* inst_prefix)
         registerAttributeFilters();
         registerMatchFunctors();
     }
+    registerSecurityPolicyProviders();
 #endif
 
     if (isEnabled(Listener))
@@ -226,7 +270,7 @@ bool SPConfig::init(const char* catalog_path, const char* inst_prefix)
     if (isEnabled(OutOfProcess))
         m_artifactResolver = new ArtifactResolver();
 #endif
-    srand(static_cast<unsigned int>(std::time(NULL)));
+    srand(static_cast<unsigned int>(std::time(nullptr)));
 
     log.info("%s library initialization complete", PACKAGE_STRING);
     return true;
@@ -240,12 +284,12 @@ void SPConfig::term()
     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
     log.info("%s library shutting down", PACKAGE_STRING);
 
-    setServiceProvider(NULL);
+    setServiceProvider(nullptr);
     if (m_configDoc)
         m_configDoc->release();
-    m_configDoc = NULL;
+    m_configDoc = nullptr;
 #ifndef SHIBSP_LITE
-    setArtifactResolver(NULL);
+    setArtifactResolver(nullptr);
 #endif
 
     ArtifactResolutionServiceManager.deregisterFactories();
@@ -259,6 +303,7 @@ void SPConfig::term()
     Attribute::deregisterFactories();
 
 #ifndef SHIBSP_LITE
+    SecurityPolicyProviderManager.deregisterFactories();
     if (isEnabled(AttributeResolution)) {
         MatchFunctorManager.deregisterFactories();
         AttributeFilterManager.deregisterFactories();
@@ -322,7 +367,7 @@ bool SPConfig::instantiate(const char* config, bool rethrow)
             dummydoc = XMLToolingConfig::getConfig().getParser().parse(snippet);
             XercesJanitor<xercesc::DOMDocument> docjanitor(dummydoc);
             static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
-            auto_ptr_char type(dummydoc->getDocumentElement()->getAttributeNS(NULL,_type));
+            auto_ptr_char type(dummydoc->getDocumentElement()->getAttributeNS(nullptr,_type));
             if (type.get() && *type.get())
                 setServiceProvider(ServiceProviderManager.newPlugin(type.get(), dummydoc->getDocumentElement()));
             else
@@ -342,3 +387,23 @@ bool SPConfig::instantiate(const char* config, bool rethrow)
     }
     return false;
 }
+
+TransactionLog::TransactionLog() : log(logging::Category::getInstance(SHIBSP_TX_LOGCAT)), m_lock(Mutex::create())
+{
+}
+
+TransactionLog::~TransactionLog()
+{
+    delete m_lock;
+}
+
+Lockable* TransactionLog::lock()
+{
+    m_lock->lock();
+    return this;
+}
+
+void TransactionLog::unlock()
+{
+    m_lock->unlock();
+}