decoupled code that requires async apis from cloud identity

This commit is contained in:
adriancole 2013-04-09 18:31:26 -07:00
parent e613c95eb9
commit 210250f63f
6 changed files with 138 additions and 21 deletions

View File

@ -1,4 +1,3 @@
package org.jclouds.rackspace.cloudidentity.v2_0;
/** /**
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
@ -17,6 +16,8 @@ package org.jclouds.rackspace.cloudidentity.v2_0;
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.rackspace.cloudidentity.v2_0;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; 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.openstack.keystone.v2_0.config.KeystoneRestClientModule.KeystoneAdminURLModule;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule; 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.CloudIdentityCredentialTypes;
import org.jclouds.rackspace.cloudidentity.v2_0.config.MappedCloudIdentityAuthenticationApiModule;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
@ -87,6 +89,7 @@ public class CloudIdentityApiMetadata extends KeystoneApiMetadata {
.context(CONTEXT_TOKEN) .context(CONTEXT_TOKEN)
.documentation(URI.create("http://docs.rackspace.com/auth/api/v2.0/auth-api-devguide/")) .documentation(URI.create("http://docs.rackspace.com/auth/api/v2.0/auth-api-devguide/"))
.defaultModules(ImmutableSet.<Class<? extends Module>>builder() .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(MappedCloudIdentityAuthenticationApiModule.class)
.add(CloudIdentityAuthenticationModule.class) .add(CloudIdentityAuthenticationModule.class)
.add(KeystoneAdminURLModule.class) .add(KeystoneAdminURLModule.class)
.add(KeystoneParserModule.class) .add(KeystoneParserModule.class)

View File

@ -18,17 +18,27 @@
*/ */
package org.jclouds.rackspace.cloudidentity.v2_0; 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.javax.annotation.Nullable;
import org.jclouds.openstack.keystone.v2_0.AuthenticationApi; 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.openstack.keystone.v2_0.domain.Access;
import org.jclouds.rackspace.cloudidentity.v2_0.domain.ApiKeyCredentials; 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. * Provides synchronous access to the KeyStone Service API.
* <p/> * <p/>
* *
* @see AuthenticationAsyncApi * @see <a href=
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Api_Operations.html" * "http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Api_Operations.html"
* /> * />
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -39,13 +49,27 @@ public interface CloudIdentityAuthenticationApi extends AuthenticationApi {
* *
* @return access with token * @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. * Authenticate to generate a token.
* *
* @return access with 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);
} }

View File

@ -43,7 +43,10 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Api_Operations.html" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Api_Operations.html"
* /> * />
* @author Adrian Cole * @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 { public interface CloudIdentityAuthenticationAsyncApi extends AuthenticationAsyncApi {
/** /**

View File

@ -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;
}
}

View File

@ -18,26 +18,19 @@
*/ */
package org.jclouds.rackspace.cloudidentity.v2_0.config; package org.jclouds.rackspace.cloudidentity.v2_0.config;
import static org.jclouds.rest.config.BinderUtils.bindMappedHttpApi;
import java.util.Map; import java.util.Map;
import org.jclouds.domain.Credentials; 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.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; 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.domain.Access;
import org.jclouds.openstack.keystone.v2_0.functions.AuthenticatePasswordCredentials; 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 org.jclouds.rackspace.cloudidentity.v2_0.functions.AuthenticateApiKeyCredentials;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Scopes;
/** /**
* *
@ -45,15 +38,6 @@ import com.google.inject.Scopes;
*/ */
public class CloudIdentityAuthenticationModule extends KeystoneAuthenticationModule { 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 @Override
protected Map<String, Function<Credentials, Access>> authenticationMethods(Injector i) { protected Map<String, Function<Credentials, Access>> authenticationMethods(Injector i) {
Builder<Function<Credentials, Access>> fns = ImmutableSet.<Function<Credentials, Access>> builder(); Builder<Function<Credentials, Access>> fns = ImmutableSet.<Function<Credentials, Access>> builder();

View File

@ -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;
}
}