From 90ade2861c4d44e13d4d0013034fbd66cd294069 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Mon, 9 Oct 2006 16:42:41 +0000 Subject: [PATCH] Moved ReplayCache into xmltooling --- saml/Makefile.am | 2 - saml/SAMLConfig.cpp | 9 ---- saml/SAMLConfig.h | 24 +-------- saml/binding/ReplayCache.h | 67 ------------------------ saml/binding/impl/ReplayCache.cpp | 48 ----------------- saml/saml.vcproj | 8 --- saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp | 4 +- saml/saml1/binding/impl/SAML1POSTDecoder.cpp | 4 +- saml/saml2/binding/impl/SAML2POSTDecoder.cpp | 4 +- samltest/samltest.h | 9 ++-- samltest/samltest.vcproj | 13 ++--- 11 files changed, 18 insertions(+), 174 deletions(-) delete mode 100644 saml/binding/ReplayCache.h delete mode 100644 saml/binding/impl/ReplayCache.cpp diff --git a/saml/Makefile.am b/saml/Makefile.am index ab119fb..c8e1d03 100644 --- a/saml/Makefile.am +++ b/saml/Makefile.am @@ -34,7 +34,6 @@ samlbindinclude_HEADERS = \ binding/ArtifactMap.h \ binding/MessageDecoder.h \ binding/MessageEncoder.h \ - binding/ReplayCache.h \ binding/SAMLArtifact.h \ binding/URLEncoder.h @@ -95,7 +94,6 @@ libsaml_la_SOURCES = \ binding/impl/ArtifactMap.cpp \ binding/impl/MessageDecoder.cpp \ binding/impl/MessageEncoder.cpp \ - binding/impl/ReplayCache.cpp \ binding/impl/SAMLArtifact.cpp \ binding/impl/URLEncoder.cpp \ saml1/core/impl/AssertionsImpl.cpp \ diff --git a/saml/SAMLConfig.cpp b/saml/SAMLConfig.cpp index 4e4c7ce..709850e 100644 --- a/saml/SAMLConfig.cpp +++ b/saml/SAMLConfig.cpp @@ -27,7 +27,6 @@ #include "binding/ArtifactMap.h" #include "binding/MessageDecoder.h" #include "binding/MessageEncoder.h" -#include "binding/ReplayCache.h" #include "binding/SAMLArtifact.h" #include "binding/URLEncoder.h" #include "saml1/core/Assertions.h" @@ -98,12 +97,6 @@ void SAMLConfig::setURLEncoder(URLEncoder* urlEncoder) m_urlEncoder = urlEncoder; } -void SAMLConfig::setReplayCache(ReplayCache* replayCache) -{ - delete m_replayCache; - m_replayCache = replayCache; -} - bool SAMLInternalConfig::init(bool initXMLTooling) { #ifdef _DEBUG @@ -157,8 +150,6 @@ void SAMLInternalConfig::term(bool termXMLTooling) m_artifactMap = NULL; delete m_urlEncoder; m_urlEncoder = NULL; - delete m_replayCache; - m_replayCache = NULL; if (termXMLTooling) { XMLToolingConfig::getConfig().term(); diff --git a/saml/SAMLConfig.h b/saml/SAMLConfig.h index 8491d0f..6945ab4 100644 --- a/saml/SAMLConfig.h +++ b/saml/SAMLConfig.h @@ -39,7 +39,6 @@ namespace opensaml { class SAML_API ArtifactMap; class SAML_API MessageEncoder; class SAML_API MessageDecoder; - class SAML_API ReplayCache; class SAML_API SAMLArtifact; class SAML_API TrustEngine; class SAML_API URLEncoder; @@ -132,24 +131,6 @@ namespace opensaml { } /** - * Sets the global ReplayCache instance. - * This method must be externally synchronized with any code that uses the object. - * Any previously set object is destroyed. - * - * @param replayCache new ReplayCache instance to store - */ - void setReplayCache(ReplayCache* replayCache); - - /** - * Returns the global ReplayCache instance. - * - * @return global ReplayCache or NULL - */ - ReplayCache* getReplayCache() const { - return m_replayCache; - } - - /** * Generate random information using the underlying security library * * @param buf buffer for the information @@ -214,16 +195,13 @@ namespace opensaml { xmltooling::PluginManager MetadataFilterManager; protected: - SAMLConfig() : m_artifactMap(NULL), m_urlEncoder(NULL), m_replayCache(NULL) {} + SAMLConfig() : m_artifactMap(NULL), m_urlEncoder(NULL) {} /** Global ArtifactMap instance for use by artifact-related functions. */ ArtifactMap* m_artifactMap; /** Global URLEncoder instance for use by URL-related functions. */ URLEncoder* m_urlEncoder; - - /** Global ReplayCache instance. */ - ReplayCache* m_replayCache; }; #if defined (_MSC_VER) diff --git a/saml/binding/ReplayCache.h b/saml/binding/ReplayCache.h deleted file mode 100644 index d5655fd..0000000 --- a/saml/binding/ReplayCache.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2001-2006 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file saml/binding/ReplayCache.h - * - * Helper class on top of StorageService for detecting message replay. - */ - -#ifndef __saml_replay_h__ -#define __saml_replay_h__ - -#include -#include - -namespace opensaml { - - /** - * Helper class on top of StorageService for detecting message replay. - */ - class SAML_API ReplayCache - { - MAKE_NONCOPYABLE(ReplayCache); - public: - - /** - * Creates a replay cache on top of a particular StorageService. - * - * @param storage pointer to a StorageService, or NULL to keep cache in memory - */ - ReplayCache(xmltooling::StorageService* storage=NULL); - - virtual ~ReplayCache(); - - /** - * Returns true iff the check value is not found in the cache, and stores it. - * - * @param context a context label to subdivide the cache - * @param s value to check - * @param expires time for disposal of value from cache - */ - virtual bool check(const char* context, const char* s, time_t expires); - - bool check(const char* context, const XMLCh* str, time_t expires) { - xmltooling::auto_ptr_char temp(str); - return check(context, temp.get(), expires); - } - - private: - xmltooling::StorageService* m_storage; - }; -}; - -#endif /* __saml_replay_h__ */ diff --git a/saml/binding/impl/ReplayCache.cpp b/saml/binding/impl/ReplayCache.cpp deleted file mode 100644 index 5081bce..0000000 --- a/saml/binding/impl/ReplayCache.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2001-2006 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * ReplayCache.cpp - * - * Helper class on top of StorageService for detecting message replay. - */ - -#include "internal.h" -#include "binding/ReplayCache.h" - -using namespace opensaml; -using namespace xmltooling; -using namespace std; - -ReplayCache::ReplayCache(StorageService* storage) : m_storage(storage) -{ - if (!m_storage) - m_storage = XMLToolingConfig::getConfig().StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE, NULL); -} - -ReplayCache::~ReplayCache() -{ - delete m_storage; -} - -bool ReplayCache::check(const char* context, const char* s, time_t expires) -{ - // In storage already? - if (m_storage->readString(context, s)) - return false; - m_storage->createText(context, s, "x", expires); - return true; -} diff --git a/saml/saml.vcproj b/saml/saml.vcproj index 1fe2f1c..25beeeb 100644 --- a/saml/saml.vcproj +++ b/saml/saml.vcproj @@ -464,10 +464,6 @@ > - - @@ -691,10 +687,6 @@ > - - diff --git a/saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp b/saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp index 2d1b23c..24b8423 100644 --- a/saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp +++ b/saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp @@ -23,7 +23,6 @@ #include "internal.h" #include "exceptions.h" #include "saml/binding/SAMLArtifact.h" -#include "saml/binding/ReplayCache.h" #include "saml1/binding/SAML1ArtifactDecoder.h" #include "saml2/metadata/Metadata.h" #include "saml2/metadata/MetadataProvider.h" @@ -31,6 +30,7 @@ #include #include +#include using namespace opensaml::saml2md; using namespace opensaml::saml1p; @@ -88,7 +88,7 @@ Response* SAML1ArtifactDecoder::decode( log.debug("processing encoded artifact (%s)", *raw); // Check replay. - ReplayCache* replayCache = SAMLConfig::getConfig().getReplayCache(); + ReplayCache* replayCache = XMLToolingConfig::getConfig().getReplayCache(); if (replayCache) { if (!replayCache->check("SAML1Artifact", *raw, time(NULL) + (2*XMLToolingConfig::getConfig().clock_skew_secs))) { log.error("replay detected of artifact (%s)", *raw); diff --git a/saml/saml1/binding/impl/SAML1POSTDecoder.cpp b/saml/saml1/binding/impl/SAML1POSTDecoder.cpp index de0deaa..ee458ec 100644 --- a/saml/saml1/binding/impl/SAML1POSTDecoder.cpp +++ b/saml/saml1/binding/impl/SAML1POSTDecoder.cpp @@ -22,7 +22,6 @@ #include "internal.h" #include "exceptions.h" -#include "saml/binding/ReplayCache.h" #include "saml1/binding/SAML1POSTDecoder.h" #include "saml2/metadata/Metadata.h" #include "saml2/metadata/MetadataProvider.h" @@ -31,6 +30,7 @@ #include #include #include +#include using namespace opensaml::saml2md; using namespace opensaml::saml1p; @@ -121,7 +121,7 @@ Response* SAML1POSTDecoder::decode( throw BindingException("Detected expired POST profile response."); // Check replay. - ReplayCache* replayCache = SAMLConfig::getConfig().getReplayCache(); + ReplayCache* replayCache = XMLToolingConfig::getConfig().getReplayCache(); if (replayCache) { auto_ptr_char id(response->getResponseID()); if (!replayCache->check("SAML1POST", id.get(), response->getIssueInstant()->getEpoch() + (2*XMLToolingConfig::getConfig().clock_skew_secs))) { diff --git a/saml/saml2/binding/impl/SAML2POSTDecoder.cpp b/saml/saml2/binding/impl/SAML2POSTDecoder.cpp index 7fedc01..7da4411 100644 --- a/saml/saml2/binding/impl/SAML2POSTDecoder.cpp +++ b/saml/saml2/binding/impl/SAML2POSTDecoder.cpp @@ -22,7 +22,6 @@ #include "internal.h" #include "exceptions.h" -#include "saml/binding/ReplayCache.h" #include "saml2/binding/SAML2POSTDecoder.h" #include "saml2/core/Protocols.h" #include "saml2/metadata/Metadata.h" @@ -32,6 +31,7 @@ #include #include #include +#include using namespace opensaml::saml2md; using namespace opensaml::saml2p; @@ -149,7 +149,7 @@ XMLObject* SAML2POSTDecoder::decode( throw BindingException("Detected expired POST binding message."); // Check replay. - ReplayCache* replayCache = SAMLConfig::getConfig().getReplayCache(); + ReplayCache* replayCache = XMLToolingConfig::getConfig().getReplayCache(); if (replayCache) { auto_ptr_char id(xmlObject->getXMLID()); if (!replayCache->check("SAML2POST", id.get(), response->getIssueInstant()->getEpoch() + (2*XMLToolingConfig::getConfig().clock_skew_secs))) { diff --git a/samltest/samltest.h b/samltest/samltest.h index 741a9e0..2e6f5a5 100644 --- a/samltest/samltest.h +++ b/samltest/samltest.h @@ -15,12 +15,11 @@ */ #include "internal.h" -#include -#include -#include - #include #include +#include +#include +#include //#define SAML_LEAKCHECK @@ -33,7 +32,7 @@ public: XMLToolingConfig::getConfig().log_config(); if (!SAMLConfig::getConfig().init()) return false; - SAMLConfig::getConfig().setReplayCache(new ReplayCache()); + XMLToolingConfig::getConfig().setReplayCache(new ReplayCache()); SAMLConfig::getConfig().setArtifactMap(new ArtifactMap()); if (getenv("SAMLTEST_DATA")) diff --git a/samltest/samltest.vcproj b/samltest/samltest.vcproj index 7f6e2c8..f8eea0c 100644 --- a/samltest/samltest.vcproj +++ b/samltest/samltest.vcproj @@ -46,6 +46,7 @@ BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" + BrowseInformation="1" WarningLevel="3" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" @@ -942,7 +943,7 @@ > @@ -951,7 +952,7 @@ > @@ -964,7 +965,7 @@ > @@ -973,7 +974,7 @@ > @@ -2378,7 +2379,7 @@ > @@ -2387,7 +2388,7 @@ > -- 2.1.4