diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java index 6d01a46e4f..b855e817ed 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java @@ -18,13 +18,23 @@ */ package org.jclouds.openstack.swift.config; +import java.net.URI; +import java.util.concurrent.Future; + +import javax.inject.Inject; +import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.Constants; import org.jclouds.http.RequiresHttp; +import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse; +import org.jclouds.openstack.config.OpenStackAuthenticationModule.GetAuthenticationResponse; +import org.jclouds.openstack.reference.AuthHeaders; import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftClient; import org.jclouds.openstack.swift.SwiftAsyncClient; import org.jclouds.openstack.swift.SwiftClient; +import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.ConfiguresRestClient; import com.google.inject.Provides; @@ -52,4 +62,28 @@ public class SwiftRestClientModule extends BaseSwiftRestClientModule authenticate() { + return client.authenticateStorage(user, key); + } + + } + + protected URI provideStorageUrl(AuthenticationResponse response) { + return response.getServices().get(AuthHeaders.STORAGE_URL); + } + + @Override + protected void configure() { + bind(GetAuthenticationResponse.class).to(GetAuthenticationResponseForStorage.class); + super.configure(); + } } diff --git a/common/openstack/src/main/java/org/jclouds/openstack/OpenStackAuthAsyncClient.java b/common/openstack/src/main/java/org/jclouds/openstack/OpenStackAuthAsyncClient.java index 5e92e86369..c712e36e0f 100755 --- a/common/openstack/src/main/java/org/jclouds/openstack/OpenStackAuthAsyncClient.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/OpenStackAuthAsyncClient.java @@ -93,4 +93,10 @@ public interface OpenStackAuthAsyncClient { @ResponseParser(ParseAuthenticationResponseFromHeaders.class) ListenableFuture authenticate(@HeaderParam(AuthHeaders.AUTH_USER) String user, @HeaderParam(AuthHeaders.AUTH_KEY) String key); + + + @GET + @ResponseParser(ParseAuthenticationResponseFromHeaders.class) + ListenableFuture authenticateStorage(@HeaderParam(AuthHeaders.STORAGE_USER) String user, + @HeaderParam(AuthHeaders.STORAGE_PASS) String key); } diff --git a/common/openstack/src/main/java/org/jclouds/openstack/config/OpenStackAuthenticationModule.java b/common/openstack/src/main/java/org/jclouds/openstack/config/OpenStackAuthenticationModule.java index c0dc3621e7..135afcec83 100755 --- a/common/openstack/src/main/java/org/jclouds/openstack/config/OpenStackAuthenticationModule.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/config/OpenStackAuthenticationModule.java @@ -24,6 +24,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -69,25 +70,44 @@ public class OpenStackAuthenticationModule extends AbstractModule { }; } + @Singleton + public static class GetAuthenticationResponse implements Supplier { + protected final OpenStackAuthAsyncClient client; + protected final String user; + protected final String key; + + @Inject + public GetAuthenticationResponse(AsyncClientFactory factory, @Named(Constants.PROPERTY_IDENTITY) String user, + @Named(Constants.PROPERTY_CREDENTIAL) String key) { + this.client = factory.create(OpenStackAuthAsyncClient.class); + this.user = user; + this.key = key; + } + + @Override + public AuthenticationResponse get() { + try { + Future response = authenticate(); + return response.get(30, TimeUnit.SECONDS); + } catch (Exception e) { + Throwables.propagate(e); + assert false : e; + return null; + } + } + + protected Future authenticate() { + return client.authenticate(user, key); + } + + } + @Provides @Singleton - Supplier provideAuthenticationResponseCache(final AsyncClientFactory factory, - @Named(Constants.PROPERTY_IDENTITY) final String user, - @Named(Constants.PROPERTY_CREDENTIAL) final String key) { + Supplier provideAuthenticationResponseCache( + final GetAuthenticationResponse getAuthenticationResponse) { return Suppliers.memoizeWithExpiration(new RetryOnTimeOutExceptionSupplier( - new Supplier() { - public AuthenticationResponse get() { - try { - Future response = factory.create(OpenStackAuthAsyncClient.class) - .authenticate(user, key); - return response.get(30, TimeUnit.SECONDS); - } catch (Exception e) { - Throwables.propagate(e); - assert false : e; - return null; - } - } - }), 23, TimeUnit.HOURS); + getAuthenticationResponse), 23, TimeUnit.HOURS); } @Provides diff --git a/common/openstack/src/main/java/org/jclouds/openstack/reference/AuthHeaders.java b/common/openstack/src/main/java/org/jclouds/openstack/reference/AuthHeaders.java index 722c1d6187..858b2058c0 100644 --- a/common/openstack/src/main/java/org/jclouds/openstack/reference/AuthHeaders.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/reference/AuthHeaders.java @@ -29,6 +29,8 @@ public interface AuthHeaders { public static final String AUTH_USER = "X-Auth-User"; public static final String AUTH_KEY = "X-Auth-Key"; + public static final String STORAGE_USER = "X-Storage-User"; + public static final String STORAGE_PASS = "X-Storage-Pass"; public static final String AUTH_TOKEN = "X-Auth-Token"; public static final String URL_SUFFIX = "-Url"; diff --git a/common/openstack/src/test/java/org/jclouds/openstack/OpenStackAuthAsyncClientTest.java b/common/openstack/src/test/java/org/jclouds/openstack/OpenStackAuthAsyncClientTest.java index 68c5251c7b..f0c5d2390f 100755 --- a/common/openstack/src/test/java/org/jclouds/openstack/OpenStackAuthAsyncClientTest.java +++ b/common/openstack/src/test/java/org/jclouds/openstack/OpenStackAuthAsyncClientTest.java @@ -60,6 +60,20 @@ public class OpenStackAuthAsyncClientTest extends RestClientTest createContextSpec() { return contextSpec("test", "http://localhost:8080", "1.0", "", "identity", "credential",