From 210250f63f846255fffe7af0a72708150462777f Mon Sep 17 00:00:00 2001 From: adriancole Date: Tue, 9 Apr 2013 18:31:26 -0700 Subject: [PATCH] decoupled code that requires async apis from cloud identity --- .../v2_0/CloudIdentityApiMetadata.java | 5 +- .../v2_0/CloudIdentityAuthenticationApi.java | 32 ++++++++-- .../CloudIdentityAuthenticationAsyncApi.java | 3 + .../CloudIdentityAuthenticationApiModule.java | 45 ++++++++++++++ .../CloudIdentityAuthenticationModule.java | 16 ----- ...dCloudIdentityAuthenticationApiModule.java | 58 +++++++++++++++++++ 6 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/CloudIdentityAuthenticationApiModule.java create mode 100644 apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/MappedCloudIdentityAuthenticationApiModule.java diff --git a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityApiMetadata.java b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityApiMetadata.java index edf8f4d40d..713fcfc78c 100644 --- a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityApiMetadata.java +++ b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityApiMetadata.java @@ -1,4 +1,3 @@ -package org.jclouds.rackspace.cloudidentity.v2_0; /** * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file @@ -17,6 +16,8 @@ package org.jclouds.rackspace.cloudidentity.v2_0; * specific language governing permissions and limitations * under the License. */ +package org.jclouds.rackspace.cloudidentity.v2_0; + import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; @@ -33,6 +34,7 @@ import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule; import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule.KeystoneAdminURLModule; import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule; import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes; +import org.jclouds.rackspace.cloudidentity.v2_0.config.MappedCloudIdentityAuthenticationApiModule; import com.google.common.collect.ImmutableSet; import com.google.common.reflect.TypeToken; @@ -87,6 +89,7 @@ public class CloudIdentityApiMetadata extends KeystoneApiMetadata { .context(CONTEXT_TOKEN) .documentation(URI.create("http://docs.rackspace.com/auth/api/v2.0/auth-api-devguide/")) .defaultModules(ImmutableSet.>builder() + .add(MappedCloudIdentityAuthenticationApiModule.class) .add(CloudIdentityAuthenticationModule.class) .add(KeystoneAdminURLModule.class) .add(KeystoneParserModule.class) diff --git a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityAuthenticationApi.java b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityAuthenticationApi.java index ed3d03eedd..a86bddae39 100644 --- a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityAuthenticationApi.java +++ b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityAuthenticationApi.java @@ -18,17 +18,27 @@ */ package org.jclouds.rackspace.cloudidentity.v2_0; +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; + import org.jclouds.javax.annotation.Nullable; import org.jclouds.openstack.keystone.v2_0.AuthenticationApi; +import org.jclouds.openstack.keystone.v2_0.binders.BindAuthToJsonPayload; import org.jclouds.openstack.keystone.v2_0.domain.Access; import org.jclouds.rackspace.cloudidentity.v2_0.domain.ApiKeyCredentials; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.SelectJson; /** * Provides synchronous access to the KeyStone Service API. *

* - * @see AuthenticationAsyncApi - * @see * @author Adrian Cole */ @@ -39,13 +49,27 @@ public interface CloudIdentityAuthenticationApi extends AuthenticationApi { * * @return access with token */ - Access authenticateWithTenantNameAndCredentials(@Nullable String tenantId, ApiKeyCredentials apiKeyCredentials); + @Named("authenticate") + @POST + @SelectJson("access") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/tokens") + @MapBinder(BindAuthToJsonPayload.class) + Access authenticateWithTenantNameAndCredentials(@Nullable @PayloadParam("tenantName") String tenantName, + ApiKeyCredentials apiKeyCredentials); /** * Authenticate to generate a token. * * @return access with token */ - Access authenticateWithTenantIdAndCredentials(@Nullable String tenantId, ApiKeyCredentials apiKeyCredentials); + @Named("authenticate") + @POST + @SelectJson("access") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/tokens") + @MapBinder(BindAuthToJsonPayload.class) + Access authenticateWithTenantIdAndCredentials(@Nullable @PayloadParam("tenantId") String tenantId, + ApiKeyCredentials apiKeyCredentials); } diff --git a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityAuthenticationAsyncApi.java b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityAuthenticationAsyncApi.java index c4c03a38f1..acb2dbbe34 100644 --- a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityAuthenticationAsyncApi.java +++ b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/CloudIdentityAuthenticationAsyncApi.java @@ -43,7 +43,10 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @author Adrian Cole + * @deprecated will be removed in jclouds 1.7, as async interfaces are no longer + * supported. please use {@link CloudIdentityAuthenticationAsyncApi} */ +@Deprecated public interface CloudIdentityAuthenticationAsyncApi extends AuthenticationAsyncApi { /** diff --git a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/CloudIdentityAuthenticationApiModule.java b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/CloudIdentityAuthenticationApiModule.java new file mode 100644 index 0000000000..7f60d3d7e8 --- /dev/null +++ b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/CloudIdentityAuthenticationApiModule.java @@ -0,0 +1,45 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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. + */ +package org.jclouds.rackspace.cloudidentity.v2_0.config; + +import static org.jclouds.rest.config.BinderUtils.bindHttpApi; + +import org.jclouds.openstack.keystone.v2_0.AuthenticationApi; +import org.jclouds.rackspace.cloudidentity.v2_0.CloudIdentityAuthenticationApi; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + */ +public class CloudIdentityAuthenticationApiModule extends AbstractModule { + + @Override + protected void configure() { + // AuthenticationApi is used directly for filters and retry handlers, so let's bind it explicitly + bindHttpApi(binder(), CloudIdentityAuthenticationApi.class); + } + + @Provides + private AuthenticationApi provideAuthenticationApi(CloudIdentityAuthenticationApi in){ + return in; + } +} diff --git a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/CloudIdentityAuthenticationModule.java b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/CloudIdentityAuthenticationModule.java index 9553f6ee2c..2b5f7a2821 100644 --- a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/CloudIdentityAuthenticationModule.java +++ b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/CloudIdentityAuthenticationModule.java @@ -18,26 +18,19 @@ */ package org.jclouds.rackspace.cloudidentity.v2_0.config; -import static org.jclouds.rest.config.BinderUtils.bindMappedHttpApi; - import java.util.Map; import org.jclouds.domain.Credentials; -import org.jclouds.openstack.keystone.v2_0.AuthenticationAsyncApi; -import org.jclouds.openstack.keystone.v2_0.AuthenticationApi; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; import org.jclouds.openstack.keystone.v2_0.domain.Access; import org.jclouds.openstack.keystone.v2_0.functions.AuthenticatePasswordCredentials; -import org.jclouds.rackspace.cloudidentity.v2_0.CloudIdentityAuthenticationAsyncApi; -import org.jclouds.rackspace.cloudidentity.v2_0.CloudIdentityAuthenticationApi; import org.jclouds.rackspace.cloudidentity.v2_0.functions.AuthenticateApiKeyCredentials; import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.inject.Injector; -import com.google.inject.Scopes; /** * @@ -45,15 +38,6 @@ import com.google.inject.Scopes; */ public class CloudIdentityAuthenticationModule extends KeystoneAuthenticationModule { - @Override - protected void bindAuthenticationApi() { - // AuthenticationApi is used directly for filters and retry handlers, so let's bind it explicitly - bindMappedHttpApi(binder(), CloudIdentityAuthenticationApi.class, - CloudIdentityAuthenticationAsyncApi.class); - bind(AuthenticationApi.class).to(CloudIdentityAuthenticationApi.class).in(Scopes.SINGLETON); - bind(AuthenticationAsyncApi.class).to(CloudIdentityAuthenticationAsyncApi.class).in(Scopes.SINGLETON); - } - @Override protected Map> authenticationMethods(Injector i) { Builder> fns = ImmutableSet.> builder(); diff --git a/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/MappedCloudIdentityAuthenticationApiModule.java b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/MappedCloudIdentityAuthenticationApiModule.java new file mode 100644 index 0000000000..1b14939c64 --- /dev/null +++ b/apis/rackspace-cloudidentity/src/main/java/org/jclouds/rackspace/cloudidentity/v2_0/config/MappedCloudIdentityAuthenticationApiModule.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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. + */ +package org.jclouds.rackspace.cloudidentity.v2_0.config; + +import static org.jclouds.rest.config.BinderUtils.bindMappedHttpApi; + +import org.jclouds.openstack.keystone.v2_0.AuthenticationApi; +import org.jclouds.openstack.keystone.v2_0.AuthenticationAsyncApi; +import org.jclouds.rackspace.cloudidentity.v2_0.CloudIdentityAuthenticationApi; +import org.jclouds.rackspace.cloudidentity.v2_0.CloudIdentityAuthenticationAsyncApi; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + * @deprecated will be removed in jclouds 1.7, as async interfaces are no longer + * supported. please use + * {@link CloudIdentityAuthenticationApiModule} + */ +@Deprecated +public class MappedCloudIdentityAuthenticationApiModule extends AbstractModule { + + @Override + protected void configure() { + // AuthenticationApi is used directly for filters and retry handlers, so + // let's bind it explicitly + bindMappedHttpApi(binder(), CloudIdentityAuthenticationApi.class, CloudIdentityAuthenticationAsyncApi.class); + } + + @Provides + private AuthenticationApi provideAuthenticationApi(CloudIdentityAuthenticationApi in) { + return in; + } + + @Provides + private AuthenticationAsyncApi provideAuthenticationAsyncApi(CloudIdentityAuthenticationAsyncApi in) { + return in; + } + +}