util/DateTime.h \
util/NDC.h \
util/ParserPool.h \
+ util/ReplayCache.h \
util/StorageService.h \
util/Threads.h \
util/XMLConstants.h \
util/DateTime.cpp \
util/NDC.cpp \
util/ParserPool.cpp \
+ util/ReplayCache.cpp \
util/StorageService.cpp \
util/XMLConstants.cpp \
util/XMLHelper.cpp \
#include "signature/CredentialResolver.h"
#include "soap/SOAP.h"
#include "util/NDC.h"
+#include "util/ReplayCache.h"
#include "util/StorageService.h"
#include "util/XMLConstants.h"
#include "validation/Validator.h"
return true;
}
+void XMLToolingConfig::setReplayCache(ReplayCache* replayCache)
+{
+ delete m_replayCache;
+ m_replayCache = replayCache;
+}
+
bool XMLToolingInternalConfig::init()
{
#ifdef _DEBUG
KeyResolverManager.deregisterFactories();
#endif
+ delete m_replayCache;
+ m_replayCache = NULL;
+
for (vector<void*>::reverse_iterator i=m_libhandles.rbegin(); i!=m_libhandles.rend(); i++) {
#if defined(WIN32)
FARPROC fn=GetProcAddress(static_cast<HMODULE>(*i),"xmltooling_extension_term");
\r
namespace xmltooling {\r
\r
+ class XMLTOOL_API ReplayCache;\r
class XMLTOOL_API StorageService;\r
class XMLTOOL_API TrustEngine;\r
class XMLTOOL_API XSECCryptoX509CRL;\r
{\r
MAKE_NONCOPYABLE(XMLToolingConfig);\r
protected:\r
- XMLToolingConfig() : clock_skew_secs(180) {}\r
+ XMLToolingConfig() : m_replayCache(NULL), clock_skew_secs(180) {}\r
+ \r
+ /** Global ReplayCache instance. */\r
+ ReplayCache* m_replayCache;\r
public:\r
virtual ~XMLToolingConfig() {}\r
\r
* @return reference to a validating parser pool.\r
*/\r
virtual ParserPool& getValidatingParser() const=0;\r
- \r
+\r
+ /**\r
+ * Sets the global ReplayCache instance.\r
+ * This method must be externally synchronized with any code that uses the object.\r
+ * Any previously set object is destroyed.\r
+ * \r
+ * @param replayCache new ReplayCache instance to store\r
+ */\r
+ void setReplayCache(ReplayCache* replayCache);\r
+\r
+ /**\r
+ * Returns the global ReplayCache instance.\r
+ * \r
+ * @return global ReplayCache or NULL\r
+ */\r
+ ReplayCache* getReplayCache() const {\r
+ return m_replayCache;\r
+ }\r
+ \r
/**\r
* List of catalog files to load into validating parser pool at initialization time.\r
* Like other path settings, the separator depends on the platform\r
--- /dev/null
+/*
+ * 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 "util/ReplayCache.h"
+
+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;
+}
--- /dev/null
+/*\r
+ * Copyright 2001-2006 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/**\r
+ * @file xmltooling/util/ReplayCache.h\r
+ * \r
+ * Helper class on top of StorageService for detecting message replay.\r
+ */\r
+\r
+#ifndef __xmltooling_replay_h__\r
+#define __xmltooling_replay_h__\r
+\r
+#include <xmltooling/util/StorageService.h>\r
+\r
+namespace xmltooling {\r
+\r
+ /**\r
+ * Helper class on top of StorageService for detecting message replay.\r
+ */\r
+ class XMLTOOL_API ReplayCache\r
+ {\r
+ MAKE_NONCOPYABLE(ReplayCache);\r
+ public:\r
+ \r
+ /**\r
+ * Creates a replay cache on top of a particular StorageService.\r
+ * \r
+ * @param storage pointer to a StorageService, or NULL to keep cache in memory\r
+ */\r
+ ReplayCache(StorageService* storage=NULL);\r
+\r
+ virtual ~ReplayCache();\r
+ \r
+ /**\r
+ * Returns true iff the check value is not found in the cache, and stores it.\r
+ * \r
+ * @param context a context label to subdivide the cache\r
+ * @param s value to check\r
+ * @param expires time for disposal of value from cache\r
+ */\r
+ virtual bool check(const char* context, const char* s, time_t expires);\r
+ \r
+ bool check(const char* context, const XMLCh* str, time_t expires) {\r
+ auto_ptr_char temp(str);\r
+ return check(context, temp.get(), expires);\r
+ }\r
+ \r
+ private:\r
+ StorageService* m_storage;\r
+ };\r
+};\r
+\r
+#endif /* __xmltooling_replay_h__ */\r