mirror of https://github.com/apache/jclouds.git
Issue 75: authentication is rackspace scoped, not cloud files
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1627 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
02f858fd97
commit
3877b69c76
|
@ -34,8 +34,8 @@ import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTIONS;
|
||||||
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTION_REUSE;
|
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTION_REUSE;
|
||||||
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_SESSION_FAILURES;
|
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_SESSION_FAILURES;
|
||||||
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_REQUEST_INVOKER_THREADS;
|
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_REQUEST_INVOKER_THREADS;
|
||||||
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_CLOUDFILES_KEY;
|
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_RACKSPACE_KEY;
|
||||||
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_CLOUDFILES_USER;
|
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_RACKSPACE_USER;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -88,8 +88,8 @@ public class CloudFilesContextBuilder extends
|
||||||
}
|
}
|
||||||
|
|
||||||
public void authenticate(String id, String secret) {
|
public void authenticate(String id, String secret) {
|
||||||
properties.setProperty(PROPERTY_CLOUDFILES_USER, checkNotNull(id, "user"));
|
properties.setProperty(PROPERTY_RACKSPACE_USER, checkNotNull(id, "user"));
|
||||||
properties.setProperty(PROPERTY_CLOUDFILES_KEY, checkNotNull(secret, "key"));
|
properties.setProperty(PROPERTY_RACKSPACE_KEY, checkNotNull(secret, "key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CloudFilesContext buildContext() {
|
public CloudFilesContext buildContext() {
|
||||||
|
|
|
@ -6,13 +6,13 @@ import java.net.URI;
|
||||||
import org.jclouds.cloud.ConfiguresCloudConnection;
|
import org.jclouds.cloud.ConfiguresCloudConnection;
|
||||||
import org.jclouds.http.HttpConstants;
|
import org.jclouds.http.HttpConstants;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rackspace.cloudfiles.Authentication;
|
import org.jclouds.rackspace.Authentication;
|
||||||
import org.jclouds.rackspace.cloudfiles.CDN;
|
import org.jclouds.rackspace.CDN;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesAuthentication;
|
import org.jclouds.rackspace.RackSpaceAuthentication;
|
||||||
|
import org.jclouds.rackspace.Storage;
|
||||||
|
import org.jclouds.rackspace.RackSpaceAuthentication.AuthenticationResponse;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesConnection;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesConnection;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesContext;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesContext;
|
||||||
import org.jclouds.rackspace.cloudfiles.Storage;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesAuthentication.AuthenticationResponse;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesContext;
|
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesContext;
|
||||||
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants;
|
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants;
|
||||||
import org.jclouds.rest.RestClientFactory;
|
import org.jclouds.rest.RestClientFactory;
|
||||||
|
@ -44,9 +44,9 @@ public class RestCloudFilesConnectionModule extends AbstractModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
protected AuthenticationResponse provideAuthenticationResponse(
|
protected AuthenticationResponse provideAuthenticationResponse(
|
||||||
@Authentication URI authenticationUri, RestClientFactory factory,
|
@Authentication URI authenticationUri, RestClientFactory factory,
|
||||||
@Named(CloudFilesConstants.PROPERTY_CLOUDFILES_USER) String user,
|
@Named(CloudFilesConstants.PROPERTY_RACKSPACE_USER) String user,
|
||||||
@Named(CloudFilesConstants.PROPERTY_CLOUDFILES_KEY) String key) {
|
@Named(CloudFilesConstants.PROPERTY_RACKSPACE_KEY) String key) {
|
||||||
return factory.create(authenticationUri, CloudFilesAuthentication.class).authenticate(user,
|
return factory.create(authenticationUri, RackSpaceAuthentication.class).authenticate(user,
|
||||||
key);
|
key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public class RestCloudFilesConnectionModule extends AbstractModule {
|
||||||
@Authentication
|
@Authentication
|
||||||
protected String provideAuthenticationToken(@Authentication URI authenticationUri,
|
protected String provideAuthenticationToken(@Authentication URI authenticationUri,
|
||||||
RestClientFactory factory,
|
RestClientFactory factory,
|
||||||
@Named(CloudFilesConstants.PROPERTY_CLOUDFILES_USER) String user,
|
@Named(CloudFilesConstants.PROPERTY_RACKSPACE_USER) String user,
|
||||||
@Named(CloudFilesConstants.PROPERTY_CLOUDFILES_KEY) String key) {
|
@Named(CloudFilesConstants.PROPERTY_RACKSPACE_KEY) String key) {
|
||||||
return factory.create(authenticationUri, CloudFilesAuthentication.class).authenticate(user,
|
return factory.create(authenticationUri, RackSpaceAuthentication.class).authenticate(user,
|
||||||
key).getAuthToken();
|
key).getAuthToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.jclouds.rackspace.reference.RackSpaceConstants;
|
||||||
*/
|
*/
|
||||||
public interface CloudFilesConstants extends ObjectStoreConstants, RackSpaceConstants {
|
public interface CloudFilesConstants extends ObjectStoreConstants, RackSpaceConstants {
|
||||||
|
|
||||||
public static final String PROPERTY_CLOUDFILES_USER = "jclouds.cloudfiles.user";
|
|
||||||
public static final String PROPERTY_CLOUDFILES_KEY = "jclouds.cloudfiles.key";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,17 +35,12 @@ public interface CloudFilesHeaders {
|
||||||
|
|
||||||
public static final String ACCOUNT_BYTES_USED = "X-Account-Bytes-Used";
|
public static final String ACCOUNT_BYTES_USED = "X-Account-Bytes-Used";
|
||||||
public static final String ACCOUNT_CONTAINER_COUNT = "X-Account-Container-Count";
|
public static final String ACCOUNT_CONTAINER_COUNT = "X-Account-Container-Count";
|
||||||
public static final String AUTH_KEY = "X-Auth-Key";
|
|
||||||
public static final String AUTH_TOKEN = "X-Auth-Token";
|
|
||||||
public static final String AUTH_USER = "X-Auth-User";
|
|
||||||
public static final String CDN_ENABLED = "X-CDN-Enabled";
|
public static final String CDN_ENABLED = "X-CDN-Enabled";
|
||||||
public static final String CDN_MANAGEMENT_URL = "X-CDN-Management-Url";
|
|
||||||
public static final String CDN_REFERRER_ACL = "X-Referrer-ACL ";
|
public static final String CDN_REFERRER_ACL = "X-Referrer-ACL ";
|
||||||
public static final String CDN_TTL = "X-TTL";
|
public static final String CDN_TTL = "X-TTL";
|
||||||
public static final String CDN_URI = "X-CDN-URI";
|
public static final String CDN_URI = "X-CDN-URI";
|
||||||
public static final String CDN_USER_AGENT_ACL = "X-User-Agent-ACL";
|
public static final String CDN_USER_AGENT_ACL = "X-User-Agent-ACL";
|
||||||
public static final String CONTAINER_BYTES_USED = "X-Container-Bytes-Used";
|
public static final String CONTAINER_BYTES_USED = "X-Container-Bytes-Used";
|
||||||
public static final String CONTAINER_OBJECT_COUNT = "X-Container-Object-Count";
|
public static final String CONTAINER_OBJECT_COUNT = "X-Container-Object-Count";
|
||||||
public static final String STORAGE_URL = "X-Storage-Url";
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,8 +30,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpRequestFilter;
|
import org.jclouds.http.HttpRequestFilter;
|
||||||
import org.jclouds.rackspace.cloudfiles.Authentication;
|
import org.jclouds.rackspace.Authentication;
|
||||||
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
|
import org.jclouds.rackspace.reference.RackSpaceHeaders;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
@ -89,7 +89,7 @@ public class AuthenticateRequest implements HttpRequestFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void filter(HttpRequest request) throws HttpException {
|
public void filter(HttpRequest request) throws HttpException {
|
||||||
request.getHeaders().replaceValues(CloudFilesHeaders.AUTH_TOKEN,
|
request.getHeaders().replaceValues(RackSpaceHeaders.AUTH_TOKEN,
|
||||||
Collections.singletonList(getAuthToken()));
|
Collections.singletonList(getAuthToken()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,11 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rackspace.cloudfiles;
|
||||||
|
|
||||||
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_CLOUDFILES_KEY;
|
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_RACKSPACE_KEY;
|
||||||
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_CLOUDFILES_USER;
|
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_RACKSPACE_USER;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
import static org.testng.Assert.assertFalse;
|
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -46,8 +45,8 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "live", testName = "cloudfiles.CloudFilesAuthenticationLiveTest")
|
@Test(groups = "live", testName = "cloudfiles.CloudFilesAuthenticationLiveTest")
|
||||||
public class CloudFilesConnectionLiveTest {
|
public class CloudFilesConnectionLiveTest {
|
||||||
|
|
||||||
protected static final String sysRackspaceUser = System.getProperty(PROPERTY_CLOUDFILES_USER);
|
protected static final String sysRackspaceUser = System.getProperty(PROPERTY_RACKSPACE_USER);
|
||||||
protected static final String sysRackspaceKey = System.getProperty(PROPERTY_CLOUDFILES_KEY);
|
protected static final String sysRackspaceKey = System.getProperty(PROPERTY_RACKSPACE_KEY);
|
||||||
|
|
||||||
private String bucketPrefix = System.getProperty("user.name") + ".cfint";
|
private String bucketPrefix = System.getProperty("user.name") + ".cfint";
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,6 @@
|
||||||
<modules>
|
<modules>
|
||||||
<module>core</module>
|
<module>core</module>
|
||||||
</modules>
|
</modules>
|
||||||
<properties>
|
|
||||||
<jclouds.cloudfiles.user />
|
|
||||||
<jclouds.cloudfiles.key />
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
|
@ -69,53 +65,4 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>live</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>integration</id>
|
|
||||||
<phase>integration-test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>test</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<!-- note that the groups/excluded groups don't work due to some problem
|
|
||||||
in surefire or testng. instead, we have to exclude via file path
|
|
||||||
<groups>live,integration</groups>
|
|
||||||
<excludedGroups>unit,performance</excludedGroups> -->
|
|
||||||
<excludes>
|
|
||||||
<exclude>none</exclude>
|
|
||||||
</excludes>
|
|
||||||
<includes>
|
|
||||||
<include>**/*IntegrationTest.java</include>
|
|
||||||
<include>**/*LiveTest.java</include>
|
|
||||||
</includes>
|
|
||||||
<systemProperties>
|
|
||||||
<property>
|
|
||||||
<name>file.encoding</name>
|
|
||||||
<value>UTF-8</value>
|
|
||||||
</property>
|
|
||||||
<property>
|
|
||||||
<name>jclouds.cloudfiles.user</name>
|
|
||||||
<value>${jclouds.cloudfiles.user}</value>
|
|
||||||
</property>
|
|
||||||
<property>
|
|
||||||
<name>jclouds.cloudfiles.key</name>
|
|
||||||
<value>${jclouds.cloudfiles.key}</value>
|
|
||||||
</property>
|
|
||||||
</systemProperties>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -21,23 +21,19 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rackspace;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import org.jclouds.cloud.CloudContext;
|
|
||||||
|
|
||||||
import com.google.inject.BindingAnnotation;
|
import com.google.inject.BindingAnnotation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an authenticated context to Cloud Files.
|
* Represents an authenticated context to RackSpace.
|
||||||
*
|
*
|
||||||
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||||
* @see CloudFilesConnection
|
|
||||||
* @see CloudContext
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
|
@ -21,23 +21,19 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rackspace;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import org.jclouds.cloud.CloudContext;
|
|
||||||
|
|
||||||
import com.google.inject.BindingAnnotation;
|
import com.google.inject.BindingAnnotation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an authenticated context to Cloud Files.
|
* Represents a component related to RackSpace Cloud Files Content delivery network.
|
||||||
*
|
*
|
||||||
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
||||||
* @see CloudFilesConnection
|
|
||||||
* @see CloudContext
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
|
@ -21,31 +21,28 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rackspace;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseAuthenticationResponseFromHeaders;
|
import org.jclouds.rackspace.functions.ParseAuthenticationResponseFromHeaders;
|
||||||
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
|
import org.jclouds.rackspace.reference.RackSpaceHeaders;
|
||||||
import org.jclouds.rest.ResponseParser;
|
import org.jclouds.rest.ResponseParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to Cloud Files via their REST API.
|
* Provides access to Rackspace resources via their REST API.
|
||||||
* <p/>
|
* <p/>
|
||||||
* All commands return a Future of the result from Cloud Files. Any exceptions incurred during
|
|
||||||
* processing will be wrapped in an {@link ExecutionException} as documented in {@link Future#get()}.
|
|
||||||
*
|
*
|
||||||
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||||
|
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface CloudFilesAuthentication {
|
public interface RackSpaceAuthentication {
|
||||||
|
|
||||||
public interface AuthenticationResponse {
|
public interface AuthenticationResponse {
|
||||||
@Storage
|
@Storage
|
||||||
|
@ -54,6 +51,9 @@ public interface CloudFilesAuthentication {
|
||||||
@CDN
|
@CDN
|
||||||
URI getCDNManagementUrl();
|
URI getCDNManagementUrl();
|
||||||
|
|
||||||
|
@Server
|
||||||
|
URI getServerManagementUrl();
|
||||||
|
|
||||||
@Authentication
|
@Authentication
|
||||||
String getAuthToken();
|
String getAuthToken();
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,6 @@ public interface CloudFilesAuthentication {
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseAuthenticationResponseFromHeaders.class)
|
@ResponseParser(ParseAuthenticationResponseFromHeaders.class)
|
||||||
@Path("/auth")
|
@Path("/auth")
|
||||||
AuthenticationResponse authenticate(@HeaderParam(CloudFilesHeaders.AUTH_USER) String user,
|
AuthenticationResponse authenticate(@HeaderParam(RackSpaceHeaders.AUTH_USER) String user,
|
||||||
@HeaderParam(CloudFilesHeaders.AUTH_KEY) String key);
|
@HeaderParam(RackSpaceHeaders.AUTH_KEY) String key);
|
||||||
}
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import com.google.inject.BindingAnnotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a component related to RackSpace Cloud Servers.
|
||||||
|
*
|
||||||
|
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
|
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
|
@BindingAnnotation
|
||||||
|
public @interface Server {
|
||||||
|
|
||||||
|
}
|
|
@ -21,23 +21,19 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rackspace;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import org.jclouds.cloud.CloudContext;
|
|
||||||
|
|
||||||
import com.google.inject.BindingAnnotation;
|
import com.google.inject.BindingAnnotation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an authenticated context to Cloud Files.
|
* Represents a component related to RackSpace Cloud Files.
|
||||||
*
|
*
|
||||||
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
||||||
* @see CloudFilesConnection
|
|
||||||
* @see CloudContext
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
|
@ -21,15 +21,18 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles.functions;
|
package org.jclouds.rackspace.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.rackspace.reference.RackSpaceHeaders.AUTH_TOKEN;
|
||||||
|
import static org.jclouds.rackspace.reference.RackSpaceHeaders.CDN_MANAGEMENT_URL;
|
||||||
|
import static org.jclouds.rackspace.reference.RackSpaceHeaders.SERVER_MANAGEMENT_URL;
|
||||||
|
import static org.jclouds.rackspace.reference.RackSpaceHeaders.STORAGE_URL;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesAuthentication.AuthenticationResponse;
|
import org.jclouds.rackspace.RackSpaceAuthentication.AuthenticationResponse;
|
||||||
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -49,21 +52,28 @@ public class ParseAuthenticationResponseFromHeaders implements
|
||||||
return new AuthenticationResponse() {
|
return new AuthenticationResponse() {
|
||||||
|
|
||||||
public String getAuthToken() {
|
public String getAuthToken() {
|
||||||
return checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.AUTH_TOKEN),
|
return checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN),
|
||||||
CloudFilesHeaders.AUTH_TOKEN);
|
AUTH_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getCDNManagementUrl() {
|
public URI getCDNManagementUrl() {
|
||||||
String cdnManagementUrl = checkNotNull(from
|
String cdnManagementUrl = checkNotNull(from
|
||||||
.getFirstHeaderOrNull(CloudFilesHeaders.CDN_MANAGEMENT_URL),
|
.getFirstHeaderOrNull(CDN_MANAGEMENT_URL),
|
||||||
CloudFilesHeaders.CDN_MANAGEMENT_URL);
|
CDN_MANAGEMENT_URL);
|
||||||
return URI.create(cdnManagementUrl);
|
return URI.create(cdnManagementUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public URI getServerManagementUrl() {
|
||||||
|
String serverManagementUrl = checkNotNull(from
|
||||||
|
.getFirstHeaderOrNull(SERVER_MANAGEMENT_URL),
|
||||||
|
SERVER_MANAGEMENT_URL);
|
||||||
|
return URI.create(serverManagementUrl);
|
||||||
|
}
|
||||||
|
|
||||||
public URI getStorageUrl() {
|
public URI getStorageUrl() {
|
||||||
String storageUrl = checkNotNull(from
|
String storageUrl = checkNotNull(from
|
||||||
.getFirstHeaderOrNull(CloudFilesHeaders.STORAGE_URL),
|
.getFirstHeaderOrNull(STORAGE_URL),
|
||||||
CloudFilesHeaders.STORAGE_URL);
|
STORAGE_URL);
|
||||||
return URI.create(storageUrl);
|
return URI.create(storageUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,6 @@ package org.jclouds.rackspace.reference;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public interface RackSpaceConstants {
|
public interface RackSpaceConstants {
|
||||||
|
public static final String PROPERTY_RACKSPACE_USER = "jclouds.rackspace.user";
|
||||||
|
public static final String PROPERTY_RACKSPACE_KEY = "jclouds.rackspace.key";
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.jclouds.rackspace.reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Headers common to Rackspace apis.
|
||||||
|
*
|
||||||
|
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface RackSpaceHeaders {
|
||||||
|
|
||||||
|
public static final String AUTH_USER = "X-Auth-User";
|
||||||
|
public static final String AUTH_KEY = "X-Auth-Key";
|
||||||
|
public static final String AUTH_TOKEN = "X-Auth-Token";
|
||||||
|
public static final String CDN_MANAGEMENT_URL = "X-CDN-Management-Url";
|
||||||
|
public static final String SERVER_MANAGEMENT_URL = "X-Server-Management-Url";
|
||||||
|
public static final String STORAGE_URL = "X-Storage-Url";
|
||||||
|
|
||||||
|
}
|
|
@ -21,10 +21,10 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rackspace;
|
||||||
|
|
||||||
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_CLOUDFILES_KEY;
|
import static org.jclouds.rackspace.reference.RackSpaceConstants.PROPERTY_RACKSPACE_KEY;
|
||||||
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_CLOUDFILES_USER;
|
import static org.jclouds.rackspace.reference.RackSpaceConstants.PROPERTY_RACKSPACE_USER;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
|
@ -36,7 +36,8 @@ import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesAuthentication.AuthenticationResponse;
|
import org.jclouds.rackspace.RackSpaceAuthentication;
|
||||||
|
import org.jclouds.rackspace.RackSpaceAuthentication.AuthenticationResponse;
|
||||||
import org.jclouds.rest.RestClientFactory;
|
import org.jclouds.rest.RestClientFactory;
|
||||||
import org.jclouds.rest.config.JaxrsModule;
|
import org.jclouds.rest.config.JaxrsModule;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
@ -53,29 +54,30 @@ import com.google.inject.Singleton;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", testName = "cloudfiles.CloudFilesAuthenticationLiveTest")
|
@Test(groups = "live", testName = "rackspace.RackSpaceAuthenticationLiveTest")
|
||||||
public class CloudFilesAuthenticationLiveTest {
|
public class RackSpaceAuthenticationLiveTest {
|
||||||
|
|
||||||
protected static final String sysRackspaceUser = System.getProperty(PROPERTY_CLOUDFILES_USER);
|
protected static final String sysRackspaceUser = System.getProperty(PROPERTY_RACKSPACE_USER);
|
||||||
protected static final String sysRackspaceKey = System.getProperty(PROPERTY_CLOUDFILES_KEY);
|
protected static final String sysRackspaceKey = System.getProperty(PROPERTY_RACKSPACE_KEY);
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthentication() throws Exception {
|
public void testAuthentication() throws Exception {
|
||||||
CloudFilesAuthentication authentication = injector
|
RackSpaceAuthentication authentication = injector
|
||||||
.getInstance(CloudFilesAuthentication.class);
|
.getInstance(RackSpaceAuthentication.class);
|
||||||
AuthenticationResponse response = authentication.authenticate(sysRackspaceUser,
|
AuthenticationResponse response = authentication.authenticate(sysRackspaceUser,
|
||||||
sysRackspaceKey);
|
sysRackspaceKey);
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getStorageUrl());
|
assertNotNull(response.getStorageUrl());
|
||||||
assertNotNull(response.getCDNManagementUrl());
|
assertNotNull(response.getCDNManagementUrl());
|
||||||
|
assertNotNull(response.getServerManagementUrl());
|
||||||
assertNotNull(response.getAuthToken());
|
assertNotNull(response.getAuthToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = HttpResponseException.class)
|
@Test(expectedExceptions = HttpResponseException.class)
|
||||||
public void testBadAuthentication() throws Exception {
|
public void testBadAuthentication() throws Exception {
|
||||||
CloudFilesAuthentication authentication = injector
|
RackSpaceAuthentication authentication = injector
|
||||||
.getInstance(CloudFilesAuthentication.class);
|
.getInstance(RackSpaceAuthentication.class);
|
||||||
try {
|
try {
|
||||||
authentication.authenticate("foo", "bar");
|
authentication.authenticate("foo", "bar");
|
||||||
} catch (UndeclaredThrowableException e) {
|
} catch (UndeclaredThrowableException e) {
|
||||||
|
@ -96,10 +98,10 @@ public class CloudFilesAuthenticationLiveTest {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected CloudFilesAuthentication provideCloudFilesAuthentication(
|
protected RackSpaceAuthentication provideCloudFilesAuthentication(
|
||||||
RestClientFactory factory) {
|
RestClientFactory factory) {
|
||||||
return factory.create(URI.create("https://api.mosso.com"),
|
return factory.create(URI.create("https://api.mosso.com"),
|
||||||
CloudFilesAuthentication.class);
|
RackSpaceAuthentication.class);
|
||||||
}
|
}
|
||||||
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
||||||
new JavaUrlHttpCommandExecutorServiceModule());
|
new JavaUrlHttpCommandExecutorServiceModule());
|
|
@ -21,7 +21,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rackspace;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
import org.jclouds.http.HttpMethod;
|
import org.jclouds.http.HttpMethod;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseAuthenticationResponseFromHeaders;
|
import org.jclouds.rackspace.functions.ParseAuthenticationResponseFromHeaders;
|
||||||
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
|
import org.jclouds.rackspace.reference.RackSpaceHeaders;
|
||||||
import org.jclouds.rest.JaxrsAnnotationProcessor;
|
import org.jclouds.rest.JaxrsAnnotationProcessor;
|
||||||
import org.jclouds.rest.config.JaxrsModule;
|
import org.jclouds.rest.config.JaxrsModule;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
@ -49,26 +49,26 @@ import com.google.inject.Guice;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "cloudfiles.CloudFilesAuthentication")
|
@Test(groups = "unit", testName = "rackspace.RackSpaceAuthentication")
|
||||||
public class CloudFilesAuthenticationTest {
|
public class RackSpaceAuthenticationTest {
|
||||||
|
|
||||||
JaxrsAnnotationProcessor.Factory factory;
|
JaxrsAnnotationProcessor.Factory factory;
|
||||||
|
|
||||||
public void testAuthenticate() throws SecurityException, NoSuchMethodException {
|
public void testAuthenticate() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudFilesAuthentication.class.getMethod("authenticate", String.class,
|
Method method = RackSpaceAuthentication.class.getMethod("authenticate", String.class,
|
||||||
String.class);
|
String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
URI endpoint = URI.create("http://localhost");
|
||||||
HttpRequest httpMethod = factory.create(CloudFilesAuthentication.class).createRequest(
|
HttpRequest httpMethod = factory.create(RackSpaceAuthentication.class).createRequest(
|
||||||
endpoint, method, new Object[] { "foo", "bar" });
|
endpoint, method, new Object[] { "foo", "bar" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/auth");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/auth");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 2);
|
assertEquals(httpMethod.getHeaders().size(), 2);
|
||||||
assertEquals(httpMethod.getHeaders().get(CloudFilesHeaders.AUTH_USER), Collections
|
assertEquals(httpMethod.getHeaders().get(RackSpaceHeaders.AUTH_USER), Collections
|
||||||
.singletonList("foo"));
|
.singletonList("foo"));
|
||||||
assertEquals(httpMethod.getHeaders().get(CloudFilesHeaders.AUTH_KEY), Collections
|
assertEquals(httpMethod.getHeaders().get(RackSpaceHeaders.AUTH_KEY), Collections
|
||||||
.singletonList("bar"));
|
.singletonList("bar"));
|
||||||
factory.create(CloudFilesAuthentication.class);
|
factory.create(RackSpaceAuthentication.class);
|
||||||
assertEquals(JaxrsAnnotationProcessor.getParserOrThrowException(method),
|
assertEquals(JaxrsAnnotationProcessor.getParserOrThrowException(method),
|
||||||
ParseAuthenticationResponseFromHeaders.class);
|
ParseAuthenticationResponseFromHeaders.class);
|
||||||
|
|
|
@ -40,6 +40,10 @@
|
||||||
<module>core</module>
|
<module>core</module>
|
||||||
<module>cloudfiles</module>
|
<module>cloudfiles</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
<properties>
|
||||||
|
<jclouds.rackspace.user />
|
||||||
|
<jclouds.rackspace.key />
|
||||||
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
|
@ -66,4 +70,54 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>live</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>integration</id>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<!-- note that the groups/excluded groups don't work due to some problem
|
||||||
|
in surefire or testng. instead, we have to exclude via file path
|
||||||
|
<groups>live,integration</groups>
|
||||||
|
<excludedGroups>unit,performance</excludedGroups> -->
|
||||||
|
<excludes>
|
||||||
|
<exclude>none</exclude>
|
||||||
|
</excludes>
|
||||||
|
<includes>
|
||||||
|
<include>**/*IntegrationTest.java</include>
|
||||||
|
<include>**/*LiveTest.java</include>
|
||||||
|
</includes>
|
||||||
|
<systemProperties>
|
||||||
|
<property>
|
||||||
|
<name>file.encoding</name>
|
||||||
|
<value>UTF-8</value>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<name>jclouds.rackspace.user</name>
|
||||||
|
<value>${jclouds.rackspace.user}</value>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<name>jclouds.rackspace.key</name>
|
||||||
|
<value>${jclouds.rackspace.key}</value>
|
||||||
|
</property>
|
||||||
|
</systemProperties>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
Loading…
Reference in New Issue