Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftTokenCache needs to validate current token is valid #211

Closed
jjohann opened this issue Sep 11, 2014 · 1 comment
Closed

SwiftTokenCache needs to validate current token is valid #211

jjohann opened this issue Sep 11, 2014 · 1 comment
Milestone

Comments

@jjohann
Copy link

jjohann commented Sep 11, 2014

I wrap COSBench runs with scripts that reconfigure swift without restarting COSBench. Tempauth is being used. With the 0.4.0 release, I run into problems because COSBench wants to use an authentication token that was valid with the previous incarnation of Swift, but will be rejected with the running instance (token is not valid in memcached because memcached has restarted.) I think the solution to this problem is to validate the authentication token by doing a HEAD request to the storageURL with the currently cached authToken. If the HEAD request returns 200, it's OK. Otherwise the driver needs to login again.

I've tried the following patch, but I haven't figured out how to do remote debug with Java/eclipse.:

diff -rupN a/dev/cosbench-swauth/src/com/intel/cosbench/client/swauth/SwiftAuthClient.java b/dev/cosbench-swauth/src/com/intel/cosbench/client/swauth/SwiftAuthClient.java
--- a/dev/cosbench-swauth/src/com/intel/cosbench/client/swauth/SwiftAuthClient.java 2014-09-10 13:40:13.299762883 -0600
+++ b/dev/cosbench-swauth/src/com/intel/cosbench/client/swauth/SwiftAuthClient.java 2014-09-11 15:18:29.263687554 -0600
@@ -24,6 +24,7 @@ import java.io.IOException;
 import org.apache.http.*;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
 import org.apache.http.util.EntityUtils;

 import com.intel.cosbench.client.http.HttpClientUtil;
@@ -84,4 +85,19 @@ public class SwiftAuthClient {
         }
     }

+    public boolean check() {
+       HttpResponse response;
+       try {
+           HttpHead method = new HttpHead(storageURL);
+           method.setHeader(X_AUTH_TOKEN, authToken);
+           response = client.execute(method);
+
+           if ((response.getStatusLine().getStatusCode() >= HttpStatus.SC_OK) &&
+               (response.getStatusLine().getStatusCode() < (HttpStatus.SC_OK + 100)))
+               return true;
+       } catch (IOException e) {
+       }
+        return false;
+    }
+
 }
diff -rupN a/dev/cosbench-swauth/src/com/intel/cosbench/client/swauth/utils/SwiftTokenCacheImpl.java b/dev/cosbench-swauth/src/com/intel/cosbench/client/swauth/utils/SwiftTokenCacheImpl.java
--- a/dev/cosbench-swauth/src/com/intel/cosbench/client/swauth/utils/SwiftTokenCacheImpl.java   2014-09-11 15:23:46.595683303 -0600
+++ b/dev/cosbench-swauth/src/com/intel/cosbench/client/swauth/utils/SwiftTokenCacheImpl.java   2014-09-11 15:10:53.639693659 -0600
@@ -40,8 +40,8 @@ public class SwiftTokenCacheImpl {
    }

     public static SwiftTokenCache getSwiftTokenCache(SwiftAuthClient client) {
-       if(latestTokenCache.getVersion()==0)
+       if(latestTokenCache.getVersion()==0 || !client.check())
            loadSwiftTokenCache(client,latestTokenCache);
-               return latestTokenCache;
+        return latestTokenCache;
     }
 }
@ywang19
Copy link
Contributor

ywang19 commented Nov 7, 2014

Thanks, merged in commit: 36c20b0

@ywang19 ywang19 closed this as completed Nov 7, 2014
@ywang19 ywang19 added this to the 0.4.1 milestone Nov 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants