https://bugs.internet2.edu/jira/browse/CPPXT-53
authorcantor <cantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Fri, 8 Jan 2010 00:51:35 +0000 (00:51 +0000)
committercantor <cantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Fri, 8 Jan 2010 00:51:35 +0000 (00:51 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/branches/REL_1@707 de75baf8-a10c-0410-a50a-987c0e22f00f

xmltooling/security/impl/FilesystemCredentialResolver.cpp
xmltooling/security/impl/SecurityHelper.cpp

index 541057e..c3250e0 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "internal.h"
 #include "logging.h"
+#include "io/HTTPResponse.h"
 #include "security/BasicX509Credential.h"
 #include "security/CredentialCriteria.h"
 #include "security/CredentialResolver.h"
@@ -65,7 +66,10 @@ namespace xmltooling {
         SOAPTransport* getTransport() {
             SOAPTransport::Address addr("FilesystemCredentialResolver", source.c_str(), source.c_str());
             string scheme(addr.m_endpoint, strchr(addr.m_endpoint,':') - addr.m_endpoint);
-            return XMLToolingConfig::getConfig().SOAPTransportManager.newPlugin(scheme.c_str(), addr);
+            SOAPTransport* ret = XMLToolingConfig::getConfig().SOAPTransportManager.newPlugin(scheme.c_str(), addr);
+            if (ret)
+                ret->setCacheTag(&cacheTag);
+            return ret;
         }
 
     public:
@@ -129,7 +133,7 @@ namespace xmltooling {
         }
 
         bool local,reloadChanges;
-        string format,source,backing;
+        string format,source,backing,cacheTag;
         time_t filestamp,reloadInterval;
     };
 
@@ -638,6 +642,15 @@ Lockable* FilesystemCredentialResolver::lock()
             m_key.load(log, m_keypass.c_str());
             updated = true;
         }
+        catch (long& ex) {
+            if (ex == HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED) {
+                log.info("remote key (%s) unchanged from cached version", m_key.source.c_str());
+            }
+            else {
+                // Shouldn't happen, we should only get codes intended to be gracefully handled.
+                log.crit("maintaining existing key, remote fetch returned atypical status code (%d)", ex);
+            }
+        }
         catch (exception& ex) {
             log.crit("maintaining existing key: %s", ex.what());
         }
@@ -650,6 +663,15 @@ Lockable* FilesystemCredentialResolver::lock()
                 i->load(log, (i==m_certs.begin()) ? m_certpass.c_str() : NULL);
                 updated = true;
             }
+            catch (long& ex) {
+                if (ex == HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED) {
+                    log.info("remote certificate(s) (%s) unchanged from cached version", i->source.c_str());
+                }
+                else {
+                    // Shouldn't happen, we should only get codes intended to be gracefully handled.
+                    log.crit("maintaining existing certificate(s), remote fetch returned atypical status code (%d)", ex);
+                }
+            }
             catch (exception& ex) {
                 log.crit("maintaining existing certificate(s): %s", ex.what());
             }
@@ -663,6 +685,15 @@ Lockable* FilesystemCredentialResolver::lock()
                 j->load(log);
                 updated = true;
             }
+            catch (long& ex) {
+                if (ex == HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED) {
+                    log.info("remote CRL(s) (%s) unchanged from cached version", j->source.c_str());
+                }
+                else {
+                    // Shouldn't happen, we should only get codes intended to be gracefully handled.
+                    log.crit("maintaining existing CRL(s), remote fetch returned atypical status code (%d)", ex);
+                }
+            }
             catch (exception& ex) {
                 log.crit("maintaining existing CRL(s): %s", ex.what());
             }
index c61d233..de4c422 100644 (file)
 
 #include "internal.h"
 #include "logging.h"
+#include "io/HTTPResponse.h"
 #include "security/OpenSSLCryptoX509CRL.h"
 #include "security/SecurityHelper.h"
 #include "security/X509Credential.h"
+#include "soap/HTTPSOAPTransport.h"
 #include "util/NDC.h"
 
 #include <fstream>
@@ -397,6 +399,10 @@ XSECCryptoKey* SecurityHelper::loadKeyFromURL(SOAPTransport& transport, const ch
     transport.send();
     istream& msg = transport.receive();
 
+    // Check for "not modified" status.
+    if (dynamic_cast<HTTPSOAPTransport*>(&transport) && transport.getStatusCode() == HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED)
+        throw (long)HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED;
+
     // Dump to output file.
     ofstream out(backing, fstream::trunc|fstream::binary);
     out << msg.rdbuf();
@@ -412,6 +418,10 @@ vector<XSECCryptoX509*>::size_type SecurityHelper::loadCertificatesFromURL(
     transport.send();
     istream& msg = transport.receive();
 
+    // Check for "not modified" status.
+    if (dynamic_cast<HTTPSOAPTransport*>(&transport) && transport.getStatusCode() == HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED)
+        throw (long)HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED;
+
     // Dump to output file.
     ofstream out(backing, fstream::trunc|fstream::binary);
     out << msg.rdbuf();
@@ -428,6 +438,10 @@ vector<XSECCryptoX509CRL*>::size_type SecurityHelper::loadCRLsFromURL(
     transport.send();
     istream& msg = transport.receive();
 
+    // Check for "not modified" status.
+    if (dynamic_cast<HTTPSOAPTransport*>(&transport) && transport.getStatusCode() == HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED)
+        throw (long)HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED;
+
     // Dump to output file.
     ofstream out(backing, fstream::trunc|fstream::binary);
     out << msg.rdbuf();