Added support Keystone style auth

This commit is contained in:
Jeremy Daggett 2012-01-25 18:35:24 -08:00
parent 4241c9239a
commit 676e153080
10 changed files with 248 additions and 34 deletions

View File

@ -18,18 +18,24 @@
*/
package org.jclouds.openstack.keystone.v2_0;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import org.jclouds.Constants;
import org.jclouds.openstack.filters.AuthenticateRequest;
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.ApiAccessKeyCredentials;
import org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import com.google.common.util.concurrent.ListenableFuture;
@ -38,16 +44,16 @@ import com.google.common.util.concurrent.ListenableFuture;
* Provides asynchronous access to Service via their REST API.
* <p/>
*
* @see ServiceClient
* @see IdentityServiceClient
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Client_Operations.html"
* />
* @author Adrian Cole
*/
@Path("/v{" + Constants.PROPERTY_API_VERSION + "}")
public interface ServiceAsyncClient {
public interface IdentityServiceAsyncClient {
/**
* @see ServiceClient#authenticateTenantWithCredentials(String,PasswordCredentials)
* @see IdentityServiceClient#authenticateTenantWithCredentials(String,PasswordCredentials)
*/
@POST
@SelectJson("access")
@ -58,7 +64,7 @@ public interface ServiceAsyncClient {
PasswordCredentials passwordCredentials);
/**
* @see ServiceClient#authenticateTenantWithCredentials(String,ApiAccessKeyCredentials)
* @see IdentityServiceClient#authenticateTenantWithCredentials(String,ApiAccessKeyCredentials)
*/
@POST
@SelectJson("access")
@ -67,4 +73,16 @@ public interface ServiceAsyncClient {
@MapBinder(BindAuthToJsonPayload.class)
ListenableFuture<Access> authenticateTenantWithCredentials(@PayloadParam("tenantId") String tenantId,
ApiAccessKeyCredentials apiAccessKeyCredentials);
/**
* @see IdentityServiceClient#getTenants()
*/
@GET
@SelectJson("tenants")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/tenants")
@RequestFilters(AuthenticateRequest.class)
ListenableFuture<? extends Set<Tenant>> getTenants();
}

View File

@ -29,13 +29,13 @@ import org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials;
* Provides synchronous access to the KeyStone Service API.
* <p/>
*
* @see ServiceAsyncClient
* @see IdentityServiceAsyncClient
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Client_Operations.html"
* />
* @author Adrian Cole
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface ServiceClient {
public interface IdentityServiceClient {
/**
* Authenticate to generate a token.

View File

@ -55,10 +55,10 @@ public class BindAuthToJsonPayload extends BindToJsonPayload implements MapBinde
throw new IllegalStateException("BindAuthToJsonPayload needs parameters");
}
protected void addCredentialsInArgsOrNull(GeneratedHttpRequest<?> gRequest, Builder<String, Object> builder) {
protected void addCredentialsInArgsOrNull(GeneratedHttpRequest<?> gRequest, Builder<String, Object> builder, String tenantId) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof PasswordCredentials) {
builder.put("auth", ImmutableMap.of("passwordCredentials", PasswordCredentials.class.cast(arg)));
builder.put("auth", ImmutableMap.of("passwordCredentials", PasswordCredentials.class.cast(arg), "tenantId", tenantId));
} else if (arg instanceof ApiAccessKeyCredentials) {
builder.put("auth", ImmutableMap.of("apiAccessKeyCredentials", ApiAccessKeyCredentials.class.cast(arg)));
}
@ -73,8 +73,9 @@ public class BindAuthToJsonPayload extends BindToJsonPayload implements MapBinde
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
Builder<String, Object> builder = ImmutableMap.<String, Object> builder();
builder.put("tenantId", postParams.get("tenantId"));
addCredentialsInArgsOrNull(gRequest, builder);
//builder.put("tenantId", postParams.get("tenantId"));
addCredentialsInArgsOrNull(gRequest, builder, postParams.get("tenantId"));
return super.bindToRequest(request, builder.build());
}

View File

@ -34,7 +34,7 @@ import org.jclouds.domain.Credentials;
import org.jclouds.http.RequiresHttp;
import org.jclouds.location.Provider;
import org.jclouds.openstack.Authentication;
import org.jclouds.openstack.keystone.v2_0.ServiceAsyncClient;
import org.jclouds.openstack.keystone.v2_0.IdentityServiceAsyncClient;
import org.jclouds.openstack.keystone.v2_0.domain.Access;
import org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials;
import org.jclouds.rest.AsyncClientFactory;
@ -81,8 +81,8 @@ public class KeyStoneAuthenticationModule extends AbstractModule {
@Provides
@Singleton
protected ServiceAsyncClient provideServiceClient(AsyncClientFactory factory) {
return factory.create(ServiceAsyncClient.class);
protected IdentityServiceAsyncClient provideServiceClient(AsyncClientFactory factory) {
return factory.create(IdentityServiceAsyncClient.class);
}
@Provides
@ -96,7 +96,7 @@ public class KeyStoneAuthenticationModule extends AbstractModule {
public static class GetAccess extends RetryOnTimeOutExceptionFunction<Credentials, Access> {
@Inject
public GetAccess(final ServiceAsyncClient client) {
public GetAccess(final IdentityServiceAsyncClient client) {
super(new Function<Credentials, Access>() {
@Override

View File

@ -40,7 +40,9 @@ import org.jclouds.hpcloud.objectstorage.lvs.functions.ParseContainerMetadataFro
import org.jclouds.hpcloud.objectstorage.lvs.options.CreateContainerOptions;
import org.jclouds.hpcloud.objectstorage.lvs.options.ListCDNContainerOptions;
import org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasHeaders;
import org.jclouds.hpcloud.services.HPExtensionCDN;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.services.ObjectStore;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.domain.ContainerMetadata;
@ -68,7 +70,7 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
@Endpoint(ObjectStore.class)
public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyncClient {
/**
@ -97,7 +99,7 @@ public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyn
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/")
@Endpoint(CDNManagement.class)
@Endpoint(HPExtensionCDN.class)
ListenableFuture<? extends Set<ContainerCDNMetadata>> listCDNContainers(ListCDNContainerOptions... options);
/**
@ -108,7 +110,7 @@ public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyn
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
@ExceptionParser(ReturnNullOnContainerNotFound.class)
@Path("/{container}")
@Endpoint(CDNManagement.class)
@Endpoint(HPExtensionCDN.class)
ListenableFuture<ContainerCDNMetadata> getCDNMetadata(@PathParam("container") String container);
/**
@ -119,7 +121,7 @@ public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyn
@Path("/{container}")
@Headers(keys = HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED, values = "True")
@ResponseParser(ParseCDNUriFromHeaders.class)
@Endpoint(CDNManagement.class)
@Endpoint(HPExtensionCDN.class)
ListenableFuture<URI> enableCDN(@PathParam("container") String container,
@HeaderParam(HPCloudObjectStorageLasVegasHeaders.CDN_TTL) long ttl);
@ -131,7 +133,7 @@ public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyn
@Path("/{container}")
@Headers(keys = HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED, values = "True")
@ResponseParser(ParseCDNUriFromHeaders.class)
@Endpoint(CDNManagement.class)
@Endpoint(HPExtensionCDN.class)
ListenableFuture<URI> enableCDN(@PathParam("container") String container);
/**
@ -141,7 +143,7 @@ public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyn
@POST
@Path("/{container}")
@ResponseParser(ParseCDNUriFromHeaders.class)
@Endpoint(CDNManagement.class)
@Endpoint(HPExtensionCDN.class)
ListenableFuture<URI> updateCDN(@PathParam("container") String container,
@HeaderParam(HPCloudObjectStorageLasVegasHeaders.CDN_TTL) long ttl);
@ -152,7 +154,7 @@ public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyn
@PUT
@Path("/{container}")
@Headers(keys = HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED, values = "False")
@Endpoint(CDNManagement.class)
@Endpoint(HPExtensionCDN.class)
ListenableFuture<Boolean> disableCDN(@PathParam("container") String container);
}

View File

@ -42,14 +42,17 @@ public class HPCloudObjectStorageLasVegasPropertiesBuilder extends SwiftProperti
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV");
properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.objects.hpcloudsvc.com/auth");
properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION);
properties.setProperty(PROPERTY_CDN_ENDPOINT, "https://region-a.geo-1.cdnmgmt.hpcloudsvc.com");
properties.setProperty(PROPERTY_API_VERSION, "2.0");
//properties.setProperty(PROPERTY_CDN_ENDPOINT, "https://region-a.geo-1.cdnmgmt.hpcloudsvc.com");
return properties;
}
/*
protected HPCloudObjectStorageLasVegasPropertiesBuilder withCDNEndpoint(String endpoint) {
properties.setProperty(PROPERTY_CDN_ENDPOINT, endpoint);
return this;
}
*/
}

View File

@ -18,24 +18,37 @@
*/
package org.jclouds.hpcloud.objectstorage.lvs.config;
import static org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasConstants.PROPERTY_CDN_ENDPOINT;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.hpcloud.objectstorage.lvs.CDNManagement;
import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasAsyncClient;
import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasClient;
import org.jclouds.hpcloud.services.HPExtensionCDN;
import org.jclouds.hpcloud.services.HPExtentionServiceType;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.RequiresHttp;
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
import org.jclouds.openstack.reference.AuthHeaders;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
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.Service;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.config.SwiftObjectModule;
import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.inject.Provides;
/**
@ -45,10 +58,36 @@ import com.google.inject.Provides;
@ConfiguresRestClient
@RequiresHttp
public class HPCloudObjectStorageLasVegasRestClientModule extends
BaseSwiftRestClientModule<HPCloudObjectStorageLasVegasClient, HPCloudObjectStorageLasVegasAsyncClient> {
RestClientModule<HPCloudObjectStorageLasVegasClient, HPCloudObjectStorageLasVegasAsyncClient> {
private final KeyStoneAuthenticationModule authModule;
public HPCloudObjectStorageLasVegasRestClientModule() {
this(new KeyStoneAuthenticationModule());
}
public HPCloudObjectStorageLasVegasRestClientModule(KeyStoneAuthenticationModule authModule) {
super(HPCloudObjectStorageLasVegasClient.class, HPCloudObjectStorageLasVegasAsyncClient.class);
this.authModule = authModule;
}
protected void configure() {
install(authModule);
install(new SwiftObjectModule());
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSwiftErrorFromHttpResponse.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(BackoffLimitedRetryHandler.class);
}
@Provides
@ -65,13 +104,39 @@ public class HPCloudObjectStorageLasVegasRestClientModule extends
@Provides
@Singleton
@CDNManagement
protected URI provideCDNUrl(AuthenticationResponse response, @Named(PROPERTY_CDN_ENDPOINT) String cdnEndpoint) {
@Storage
protected URI provideStorageUrl(Access response) {
return Iterables.getOnlyElement(Iterables.find(response.getServiceCatalog(), new Predicate<Service>(){
@Override
public boolean apply(Service input) {
return input.getId().equals(ServiceType.OBJECT_STORE);
}
}).getEndpoints()).getPublicURL();
}
@Provides
@Singleton
@HPExtensionCDN
protected URI provideCDNUrl(Access response) {
/*
if (response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL) == null) {
return URI.create(cdnEndpoint + response.getServices().get(AuthHeaders.STORAGE_URL).getPath());
}
// Placeholder for when the Object Storage service returns the CDN Management URL in the headers
return response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL);
*/
return Iterables.getOnlyElement(Iterables.find(response.getServiceCatalog(), new Predicate<Service>(){
@Override
public boolean apply(Service input) {
return input.getId().equals(HPExtentionServiceType.CDN);
}
}).getEndpoints()).getPublicURL();
}
}

View File

@ -0,0 +1,41 @@
/**
* 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.hpcloud.services;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* HP Extension Block Store Service
*
* @author Jeremy Daggett
* @see <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* />
* @see HPExtensionServiceType#BLOCK_STORE
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface HPExtensionBlockStore {
}

View File

@ -0,0 +1,41 @@
/**
* 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.hpcloud.services;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* CDN
*
* @author Jeremy Daggett
* @see <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* />
* @see HPExtensionServiceType#CDN
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface HPExtensionCDN {
}

View File

@ -0,0 +1,43 @@
/**
* 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, Name 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.hpcloud.services;
import org.jclouds.openstack.services.ServiceType;
/**
* An HP Extension Service, such as CDN, or Block Store Service.
* A service provides one or more endpoints through which users can access resources and perform
* (presumably useful) operations.
*
* @author Jeremy Daggett
* @see <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* />
*/
public interface HPExtentionServiceType extends ServiceType {
/**
* CDN
*/
public static final String CDN = "hpext:cdn";
/**
* Block Storage
*/
public static final String BLOCK_STORE = "hpext:block-store";
}