Merge pull request #1362 from jclouds/sts-rename

rename TemporaryCredentials to SessionCredentials per aws sdk
This commit is contained in:
Adrian Cole 2013-02-25 20:16:54 -08:00
commit 8e33229e94
19 changed files with 213 additions and 234 deletions

View File

@ -33,7 +33,7 @@ import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.crypto.Crypto;
import org.jclouds.date.TimeStamp;
import org.jclouds.domain.Credentials;
@ -71,15 +71,15 @@ public class RestAuthentication implements HttpRequestFilter, RequestSigner {
public HttpRequest filter(HttpRequest request) throws HttpException {
Credentials current = creds.get();
if (current instanceof TemporaryCredentials) {
request = replaceSecurityTokenHeader(request, TemporaryCredentials.class.cast(current));
if (current instanceof SessionCredentials) {
request = replaceSecurityTokenHeader(request, SessionCredentials.class.cast(current));
}
request = replaceDateHeader(request, timeStampProvider.get());
String signature = sign(createStringToSign(request));
return replaceAuthorizationHeader(request, signature);
}
private HttpRequest replaceSecurityTokenHeader(HttpRequest request, TemporaryCredentials current) {
private HttpRequest replaceSecurityTokenHeader(HttpRequest request, SessionCredentials current) {
return request.toBuilder().replaceHeader("x-amz-security-token", current.getSessionToken()).build();
}

View File

@ -43,7 +43,7 @@ import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.crypto.Crypto;
import org.jclouds.date.TimeStamp;
import org.jclouds.domain.Credentials;
@ -121,8 +121,8 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
public HttpRequest filter(HttpRequest request) throws HttpException {
request = replaceDateHeader(request);
Credentials current = creds.get();
if (current instanceof TemporaryCredentials) {
request = replaceSecurityTokenHeader(request, TemporaryCredentials.class.cast(current));
if (current instanceof SessionCredentials) {
request = replaceSecurityTokenHeader(request, SessionCredentials.class.cast(current));
}
String signature = calculateSignature(createStringToSign(request));
request = replaceAuthorizationHeader(request, signature);
@ -130,7 +130,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
return request;
}
HttpRequest replaceSecurityTokenHeader(HttpRequest request, TemporaryCredentials current) {
HttpRequest replaceSecurityTokenHeader(HttpRequest request, SessionCredentials current) {
return request.toBuilder().replaceHeader("x-amz-security-token", current.getSessionToken()).build();
}

View File

@ -22,7 +22,7 @@ import static org.jclouds.reflect.Reflection2.method;
import static org.testng.Assert.assertEquals;
import org.jclouds.ContextBuilder;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.date.TimeStamp;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.domain.Credentials;
@ -49,8 +49,8 @@ import com.google.inject.Module;
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "RequestAuthorizeSignatureWithTemporaryCredentialsTest")
public class RequestAuthorizeSignatureWithTemporaryCredentialsTest {
@Test(groups = "unit", testName = "RequestAuthorizeSignatureWithSessionCredentialsTest")
public class RequestAuthorizeSignatureWithSessionCredentialsTest {
public static Injector injector(Credentials creds) {
return ContextBuilder.newBuilder("s3")
.credentialsSupplier(Suppliers.<Credentials> ofInstance(creds))
@ -70,7 +70,7 @@ public class RequestAuthorizeSignatureWithTemporaryCredentialsTest {
return injector(creds).getInstance(RequestAuthorizeSignature.class);
}
TemporaryCredentials temporaryCredentials = TemporaryCredentials.builder()
SessionCredentials temporaryCredentials = SessionCredentials.builder()
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")

View File

@ -25,7 +25,7 @@ import java.util.Date;
import org.jclouds.domain.Credentials;
import com.google.common.base.Objects;
import com.google.common.base.Supplier;
import com.google.common.base.Optional;
/**
* AWS credentials for API authentication.
@ -36,77 +36,12 @@ import com.google.common.base.Supplier;
*
* @author Adrian Cole
*/
public final class TemporaryCredentials extends Credentials {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().from(this);
}
public final static class Builder extends Credentials.Builder<TemporaryCredentials> {
private String accessKeyId;
private String secretAccessKey;
private String sessionToken;
private Date expiration;
@Override
public Builder identity(String identity) {
return accessKeyId(identity);
}
@Override
public Builder credential(String credential) {
return secretAccessKey(credential);
}
/**
* @see TemporaryCredentials#getAccessKeyId()
*/
public Builder accessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
return this;
}
/**
* @see TemporaryCredentials#getSecretAccessKey()
*/
public Builder secretAccessKey(String secretAccessKey) {
this.secretAccessKey = secretAccessKey;
return this;
}
/**
* @see TemporaryCredentials#getSessionToken()
*/
public Builder sessionToken(String sessionToken) {
this.sessionToken = sessionToken;
return this;
}
/**
* @see TemporaryCredentials#getExpiration()
*/
public Builder expiration(Date expiration) {
this.expiration = expiration;
return this;
}
public TemporaryCredentials build() {
return new TemporaryCredentials(accessKeyId, secretAccessKey, sessionToken, expiration);
}
public Builder from(TemporaryCredentials in) {
return this.accessKeyId(in.identity).secretAccessKey(in.credential).sessionToken(in.sessionToken)
.expiration(in.expiration);
}
}
public final class SessionCredentials extends Credentials {
private final String sessionToken;
private final Date expiration;
private final Optional<Date> expiration;
private TemporaryCredentials(String accessKeyId, String secretAccessKey, String sessionToken, Date expiration) {
private SessionCredentials(String accessKeyId, String secretAccessKey, String sessionToken, Optional<Date> expiration) {
super(checkNotNull(accessKeyId, "accessKeyId"), checkNotNull(secretAccessKey, "secretAccessKey for %s",
accessKeyId));
this.sessionToken = checkNotNull(sessionToken, "sessionToken for %s", accessKeyId);
@ -138,21 +73,15 @@ public final class TemporaryCredentials extends Credentials {
/**
* The date on which these credentials expire.
*/
public Date getExpiration() {
public Optional<Date> getExpiration() {
return expiration;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(identity, credential, sessionToken, expiration);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
@ -161,17 +90,80 @@ public final class TemporaryCredentials extends Credentials {
return false;
if (getClass() != obj.getClass())
return false;
TemporaryCredentials other = (TemporaryCredentials) obj;
SessionCredentials other = (SessionCredentials) obj;
return Objects.equal(this.identity, other.identity) && Objects.equal(this.credential, other.credential)
&& Objects.equal(this.sessionToken, other.sessionToken) && Objects.equal(this.expiration, other.expiration);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return Objects.toStringHelper(this).add("accessKeyId", identity).add("sessionToken", sessionToken)
.add("expiration", expiration).toString();
return Objects.toStringHelper(this).omitNullValues().add("accessKeyId", identity)
.add("sessionToken", sessionToken).add("expiration", expiration.orNull()).toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().from(this);
}
public final static class Builder extends Credentials.Builder<SessionCredentials> {
private String accessKeyId;
private String secretAccessKey;
private String sessionToken;
private Optional<Date> expiration = Optional.absent();
@Override
public Builder identity(String identity) {
return accessKeyId(identity);
}
@Override
public Builder credential(String credential) {
return secretAccessKey(credential);
}
/**
* @see SessionCredentials#getAccessKeyId()
*/
public Builder accessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
return this;
}
/**
* @see SessionCredentials#getSecretAccessKey()
*/
public Builder secretAccessKey(String secretAccessKey) {
this.secretAccessKey = secretAccessKey;
return this;
}
/**
* @see SessionCredentials#getSessionToken()
*/
public Builder sessionToken(String sessionToken) {
this.sessionToken = sessionToken;
return this;
}
/**
* @see SessionCredentials#getExpiration()
*/
public Builder expiration(Date expiration) {
this.expiration = Optional.fromNullable(expiration);
return this;
}
public SessionCredentials build() {
return new SessionCredentials(accessKeyId, secretAccessKey, sessionToken, expiration);
}
public Builder from(SessionCredentials in) {
return this.accessKeyId(in.identity).secretAccessKey(in.credential).sessionToken(in.sessionToken)
.expiration(in.expiration.orNull());
}
}
}

View File

@ -47,7 +47,7 @@ import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.crypto.Crypto;
import org.jclouds.date.TimeStamp;
import org.jclouds.domain.Credentials;
@ -206,8 +206,8 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
params.removeAll(SIGNATURE);
params.removeAll(SECURITY_TOKEN);
Credentials current = creds.get();
if (current instanceof TemporaryCredentials) {
params.put(SECURITY_TOKEN, TemporaryCredentials.class.cast(current).getSessionToken());
if (current instanceof SessionCredentials) {
params.put(SECURITY_TOKEN, SessionCredentials.class.cast(current).getSessionToken());
}
params.replaceValues(SIGNATURE_METHOD, ImmutableList.of("HmacSHA256"));
params.replaceValues(SIGNATURE_VERSION, ImmutableList.of("2"));

View File

@ -20,7 +20,7 @@ package org.jclouds.aws.xml;
import javax.inject.Inject;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.SaxUtils;
@ -32,32 +32,26 @@ import org.jclouds.util.SaxUtils;
*
* @author Adrian Cole
*/
public class TemporaryCredentialsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<TemporaryCredentials> {
public class SessionCredentialsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<SessionCredentials> {
private final DateService dateService;
@Inject
protected TemporaryCredentialsHandler(DateService dateService) {
protected SessionCredentialsHandler(DateService dateService) {
this.dateService = dateService;
}
private StringBuilder currentText = new StringBuilder();
private TemporaryCredentials.Builder builder = TemporaryCredentials.builder();
private SessionCredentials.Builder builder = SessionCredentials.builder();
/**
* {@inheritDoc}
*/
@Override
public TemporaryCredentials getResult() {
public SessionCredentials getResult() {
try {
return builder.build();
} finally {
builder = TemporaryCredentials.builder();
builder = SessionCredentials.builder();
}
}
/**
* {@inheritDoc}
*/
@Override
public void endElement(String uri, String name, String qName) {
if (qName.equals("AccessKeyId")) {
@ -72,12 +66,8 @@ public class TemporaryCredentialsHandler extends ParseSax.HandlerForGeneratedReq
currentText = new StringBuilder();
}
/**
* {@inheritDoc}
*/
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -18,12 +18,12 @@
*/
package org.jclouds.sts;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.sts.domain.User;
import org.jclouds.sts.domain.UserAndTemporaryCredentials;
import org.jclouds.sts.domain.UserAndSessionCredentials;
import org.jclouds.sts.options.AssumeRoleOptions;
import org.jclouds.sts.options.FederatedUserOptions;
import org.jclouds.sts.options.TemporaryCredentialsOptions;
import org.jclouds.sts.options.SessionCredentialsOptions;
/**
* Provides access to Amazon STS via the Query API
@ -38,13 +38,13 @@ public interface STSApi {
* Returns a set of temporary credentials for an AWS account or IAM user,
* with a default timeout
*/
TemporaryCredentials createTemporaryCredentials();
SessionCredentials createTemporaryCredentials();
/**
* like {@link #createTemporaryCredentials()}, except you can modify the
* timeout and other parameters.
*/
TemporaryCredentials createTemporaryCredentials(TemporaryCredentialsOptions options);
SessionCredentials createTemporaryCredentials(SessionCredentialsOptions options);
/**
* Assumes a role for a specified session. Only IAM users can assume a role.
@ -56,13 +56,13 @@ public interface STSApi {
* The Amazon Resource Name (ARN) of the role that the caller is
* assuming.
*/
UserAndTemporaryCredentials assumeRole(String roleArn, String sessionName);
UserAndSessionCredentials assumeRole(String roleArn, String sessionName);
/**
* like {@link #assumeRole(String, String)}, except you can modify the
* timeout and other parameters.
*/
UserAndTemporaryCredentials assumeRole(String roleArn, String sessionName, AssumeRoleOptions options);
UserAndSessionCredentials assumeRole(String roleArn, String sessionName, AssumeRoleOptions options);
/**
* Returns a set of temporary credentials for a federated user with the user
@ -72,12 +72,12 @@ public interface STSApi {
* The name of the federated user, included as part of
* {@link User#getId}.
*/
UserAndTemporaryCredentials createFederatedUser(String userName);
UserAndSessionCredentials createFederatedUser(String userName);
/**
* like {@link #createFederatedUser(String)}, except you can modify the
* timeout and other parameters.
*/
UserAndTemporaryCredentials createFederatedUser(String userName, FederatedUserOptions options);
UserAndSessionCredentials createFederatedUser(String userName, FederatedUserOptions options);
}

View File

@ -23,18 +23,18 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.xml.TemporaryCredentialsHandler;
import org.jclouds.aws.xml.SessionCredentialsHandler;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.sts.domain.UserAndTemporaryCredentials;
import org.jclouds.sts.domain.UserAndSessionCredentials;
import org.jclouds.sts.options.AssumeRoleOptions;
import org.jclouds.sts.options.FederatedUserOptions;
import org.jclouds.sts.options.TemporaryCredentialsOptions;
import org.jclouds.sts.xml.UserAndTemporaryCredentialsHandler;
import org.jclouds.sts.options.SessionCredentialsOptions;
import org.jclouds.sts.xml.UserAndSessionCredentialsHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -55,19 +55,19 @@ public interface STSAsyncApi {
@Named("GetSessionToken")
@POST
@Path("/")
@XMLResponseParser(TemporaryCredentialsHandler.class)
@XMLResponseParser(SessionCredentialsHandler.class)
@FormParams(keys = "Action", values = "GetSessionToken")
ListenableFuture<TemporaryCredentials> createTemporaryCredentials();
ListenableFuture<SessionCredentials> createTemporaryCredentials();
/**
* @see STSApi#createTemporaryCredentials(TemporaryCredentialsOptions)
* @see STSApi#createTemporaryCredentials(SessionCredentialsOptions)
*/
@Named("GetSessionToken")
@POST
@Path("/")
@XMLResponseParser(TemporaryCredentialsHandler.class)
@XMLResponseParser(SessionCredentialsHandler.class)
@FormParams(keys = "Action", values = "GetSessionToken")
ListenableFuture<TemporaryCredentials> createTemporaryCredentials(TemporaryCredentialsOptions options);
ListenableFuture<SessionCredentials> createTemporaryCredentials(SessionCredentialsOptions options);
/**
* @see STSApi#assumeRole(String, String)
@ -75,9 +75,9 @@ public interface STSAsyncApi {
@Named("AssumeRole")
@POST
@Path("/")
@XMLResponseParser(UserAndTemporaryCredentialsHandler.class)
@XMLResponseParser(UserAndSessionCredentialsHandler.class)
@FormParams(keys = "Action", values = "AssumeRole")
ListenableFuture<UserAndTemporaryCredentials> assumeRole(@FormParam("RoleArn") String roleArn,
ListenableFuture<UserAndSessionCredentials> assumeRole(@FormParam("RoleArn") String roleArn,
@FormParam("RoleSessionName") String sessionName);
/**
@ -86,9 +86,9 @@ public interface STSAsyncApi {
@Named("AssumeRole")
@POST
@Path("/")
@XMLResponseParser(UserAndTemporaryCredentialsHandler.class)
@XMLResponseParser(UserAndSessionCredentialsHandler.class)
@FormParams(keys = "Action", values = "AssumeRole")
ListenableFuture<UserAndTemporaryCredentials> assumeRole(@FormParam("RoleArn") String roleArn,
ListenableFuture<UserAndSessionCredentials> assumeRole(@FormParam("RoleArn") String roleArn,
@FormParam("RoleSessionName") String sessionName, AssumeRoleOptions options);
/**
@ -97,9 +97,9 @@ public interface STSAsyncApi {
@Named("GetFederationToken")
@POST
@Path("/")
@XMLResponseParser(UserAndTemporaryCredentialsHandler.class)
@XMLResponseParser(UserAndSessionCredentialsHandler.class)
@FormParams(keys = "Action", values = "GetFederationToken")
ListenableFuture<UserAndTemporaryCredentials> createFederatedUser(@FormParam("Name") String userName);
ListenableFuture<UserAndSessionCredentials> createFederatedUser(@FormParam("Name") String userName);
/**
* @see STSApi#createFederatedUser(FederatedUserOptions)
@ -107,7 +107,7 @@ public interface STSAsyncApi {
@Named("GetFederationToken")
@POST
@Path("/")
@XMLResponseParser(UserAndTemporaryCredentialsHandler.class)
@XMLResponseParser(UserAndSessionCredentialsHandler.class)
@FormParams(keys = "Action", values = "GetFederationToken")
ListenableFuture<UserAndTemporaryCredentials> createFederatedUser(@FormParam("Name") String userName, FederatedUserOptions options);
ListenableFuture<UserAndSessionCredentials> createFederatedUser(@FormParam("Name") String userName, FederatedUserOptions options);
}

View File

@ -20,7 +20,7 @@ package org.jclouds.sts.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import com.google.common.base.Objects;
@ -28,7 +28,7 @@ import com.google.common.base.Objects;
*
* @author Adrian Cole
*/
public final class UserAndTemporaryCredentials {
public final class UserAndSessionCredentials {
public static Builder builder() {
return new Builder();
}
@ -39,11 +39,11 @@ public final class UserAndTemporaryCredentials {
public final static class Builder {
private User user;
private TemporaryCredentials credentials;
private SessionCredentials credentials;
private int packedPolicySize;
/**
* @see UserAndTemporaryCredentials#getUser()
* @see UserAndSessionCredentials#getUser()
*/
public Builder user(User user) {
this.user = user;
@ -51,42 +51,42 @@ public final class UserAndTemporaryCredentials {
}
/**
* @see UserAndTemporaryCredentials#getCredentials()
* @see UserAndSessionCredentials#getCredentials()
*/
public Builder credentials(TemporaryCredentials credentials) {
public Builder credentials(SessionCredentials credentials) {
this.credentials = credentials;
return this;
}
/**
* @see UserAndTemporaryCredentials#getPackedPolicySize()
* @see UserAndSessionCredentials#getPackedPolicySize()
*/
public Builder packedPolicySize(int packedPolicySize) {
this.packedPolicySize = packedPolicySize;
return this;
}
public UserAndTemporaryCredentials build() {
return new UserAndTemporaryCredentials(user, credentials, packedPolicySize);
public UserAndSessionCredentials build() {
return new UserAndSessionCredentials(user, credentials, packedPolicySize);
}
public Builder from(UserAndTemporaryCredentials in) {
public Builder from(UserAndSessionCredentials in) {
return this.user(in.user).credentials(in.credentials).packedPolicySize(in.packedPolicySize);
}
}
private final User user;
private final TemporaryCredentials credentials;
private final SessionCredentials credentials;
private final int packedPolicySize;
private UserAndTemporaryCredentials(User user, TemporaryCredentials credentials, int packedPolicySize) {
private UserAndSessionCredentials(User user, SessionCredentials credentials, int packedPolicySize) {
this.user = checkNotNull(user, "user");
this.credentials = checkNotNull(credentials, "credentials for %s", user);
this.packedPolicySize = checkNotNull(packedPolicySize, "packedPolicySize for %s", user);
}
/**
* user correlating to {@link UserAndTemporaryCredentials#getCredentials()}
* user correlating to {@link UserAndSessionCredentials#getCredentials()}
*/
public User getUser() {
return user;
@ -96,7 +96,7 @@ public final class UserAndTemporaryCredentials {
* The temporary security credentials, which includes an Access Key ID, a
* Secret Access Key, and a security token.
*/
public TemporaryCredentials getCredentials() {
public SessionCredentials getCredentials() {
return credentials;
}
@ -120,7 +120,7 @@ public final class UserAndTemporaryCredentials {
return false;
if (getClass() != obj.getClass())
return false;
UserAndTemporaryCredentials other = (UserAndTemporaryCredentials) obj;
UserAndSessionCredentials other = (UserAndSessionCredentials) obj;
return Objects.equal(this.user, other.user) && Objects.equal(this.credentials, other.credentials)
&& Objects.equal(this.packedPolicySize, other.packedPolicySize);
}

View File

@ -32,7 +32,7 @@ import com.google.common.collect.Multimap;
*
* @author Adrian Cole
*/
public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implements Cloneable {
public class SessionCredentialsOptions extends BaseHttpRequestOptions implements Cloneable {
// long as this is a more typical unit for duration, hence less casting
private Long durationSeconds;
@ -42,7 +42,7 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
/**
* The identification number of the MFA device for the user.
*/
public TemporaryCredentialsOptions serialNumber(String serialNumber) {
public SessionCredentialsOptions serialNumber(String serialNumber) {
this.serialNumber = serialNumber;
return this;
}
@ -51,7 +51,7 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
* The duration, in seconds, that the credentials should remain valid. 12
* hours is default. 15 minutes is current minimum.
*/
public TemporaryCredentialsOptions durationSeconds(long durationSeconds) {
public SessionCredentialsOptions durationSeconds(long durationSeconds) {
this.durationSeconds = durationSeconds;
return this;
}
@ -59,7 +59,7 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
/**
* The value provided by the MFA device.
*/
public TemporaryCredentialsOptions tokenCode(String tokenCode) {
public SessionCredentialsOptions tokenCode(String tokenCode) {
this.tokenCode = tokenCode;
return this;
}
@ -67,24 +67,24 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
public static class Builder {
/**
* @see TemporaryCredentialsOptions#serialNumber
* @see SessionCredentialsOptions#serialNumber
*/
public static TemporaryCredentialsOptions serialNumber(String serialNumber) {
return new TemporaryCredentialsOptions().serialNumber(serialNumber);
public static SessionCredentialsOptions serialNumber(String serialNumber) {
return new SessionCredentialsOptions().serialNumber(serialNumber);
}
/**
* @see TemporaryCredentialsOptions#durationSeconds
* @see SessionCredentialsOptions#durationSeconds
*/
public static TemporaryCredentialsOptions durationSeconds(long durationSeconds) {
return new TemporaryCredentialsOptions().durationSeconds(durationSeconds);
public static SessionCredentialsOptions durationSeconds(long durationSeconds) {
return new SessionCredentialsOptions().durationSeconds(durationSeconds);
}
/**
* @see TemporaryCredentialsOptions#tokenCode
* @see SessionCredentialsOptions#tokenCode
*/
public static TemporaryCredentialsOptions tokenCode(String tokenCode) {
return new TemporaryCredentialsOptions().tokenCode(tokenCode);
public static SessionCredentialsOptions tokenCode(String tokenCode) {
return new SessionCredentialsOptions().tokenCode(tokenCode);
}
}
@ -109,8 +109,8 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
}
@Override
public TemporaryCredentialsOptions clone() {
return new TemporaryCredentialsOptions().serialNumber(serialNumber).durationSeconds(durationSeconds)
public SessionCredentialsOptions clone() {
return new SessionCredentialsOptions().serialNumber(serialNumber).durationSeconds(durationSeconds)
.tokenCode(tokenCode);
}
@ -125,7 +125,7 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
return false;
if (getClass() != obj.getClass())
return false;
TemporaryCredentialsOptions other = TemporaryCredentialsOptions.class.cast(obj);
SessionCredentialsOptions other = SessionCredentialsOptions.class.cast(obj);
return Objects.equal(this.serialNumber, other.serialNumber)
&& Objects.equal(this.durationSeconds, other.durationSeconds)
&& Objects.equal(this.tokenCode, other.tokenCode);

View File

@ -21,10 +21,10 @@ package org.jclouds.sts.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import org.jclouds.aws.xml.TemporaryCredentialsHandler;
import org.jclouds.aws.xml.SessionCredentialsHandler;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.sts.domain.User;
import org.jclouds.sts.domain.UserAndTemporaryCredentials;
import org.jclouds.sts.domain.UserAndSessionCredentials;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@ -34,27 +34,24 @@ import com.google.inject.Inject;
*
* @author Adrian Cole
*/
public class UserAndTemporaryCredentialsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<UserAndTemporaryCredentials> {
public class UserAndSessionCredentialsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<UserAndSessionCredentials> {
private final TemporaryCredentialsHandler credsHandler;
private final SessionCredentialsHandler credsHandler;
private StringBuilder currentText = new StringBuilder();
private UserAndTemporaryCredentials.Builder builder = UserAndTemporaryCredentials.builder();
private UserAndSessionCredentials.Builder builder = UserAndSessionCredentials.builder();
@Inject
public UserAndTemporaryCredentialsHandler(TemporaryCredentialsHandler credsHandler) {
public UserAndSessionCredentialsHandler(SessionCredentialsHandler credsHandler) {
this.credsHandler = credsHandler;
}
/**
* {@inheritDoc}
*/
@Override
public UserAndTemporaryCredentials getResult() {
public UserAndSessionCredentials getResult() {
try {
return builder.build();
} finally {
builder = UserAndTemporaryCredentials.builder();
builder = UserAndSessionCredentials.builder();
}
}

View File

@ -24,7 +24,7 @@ import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.ContextBuilder;
import org.jclouds.aws.xml.TemporaryCredentialsHandlerTest;
import org.jclouds.aws.xml.SessionCredentialsHandlerTest;
import org.jclouds.date.TimeStamp;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpRequest;
@ -84,7 +84,7 @@ public class FormSignerTest {
@Test
void testAddsSecurityToken() {
HttpRequest filtered = filter(new TemporaryCredentialsHandlerTest().expected()).filter(request);
HttpRequest filtered = filter(new SessionCredentialsHandlerTest().expected()).filter(request);
assertEquals(
filtered.getPayload().getRawContent(),
"Action=DescribeImages&ImageId.1=ami-2bb65342&SecurityToken=AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT&Signature=/8ReFVH1tvyNORsJb%2BSBieT9zvdqREQQr/olwmxC7VY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=apiVersion&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE");

View File

@ -22,8 +22,8 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.xml.TemporaryCredentialsHandler;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.aws.xml.SessionCredentialsHandler;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
@ -32,16 +32,16 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "TemporaryCredentialsHandlerTest")
public class TemporaryCredentialsHandlerTest extends BaseHandlerTest {
@Test(groups = "unit", testName = "SessionCredentialsHandlerTest")
public class SessionCredentialsHandlerTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/credentials.xml");
TemporaryCredentials expected = expected();
SessionCredentials expected = expected();
TemporaryCredentialsHandler handler = injector.getInstance(TemporaryCredentialsHandler.class);
TemporaryCredentials result = factory.create(handler).parse(is);
SessionCredentialsHandler handler = injector.getInstance(SessionCredentialsHandler.class);
SessionCredentials result = factory.create(handler).parse(is);
assertEquals(result, expected);
assertEquals(result.getAccessKeyId(), expected.getAccessKeyId());
@ -50,8 +50,8 @@ public class TemporaryCredentialsHandlerTest extends BaseHandlerTest {
assertEquals(result.getExpiration(), expected.getExpiration());
}
public TemporaryCredentials expected() {
return TemporaryCredentials.builder()
public SessionCredentials expected() {
return SessionCredentials.builder()
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")

View File

@ -20,7 +20,7 @@ package org.jclouds.sts;
import static org.jclouds.sts.options.AssumeRoleOptions.Builder.externalId;
import static org.jclouds.sts.options.FederatedUserOptions.Builder.policy;
import static org.jclouds.sts.options.TemporaryCredentialsOptions.Builder.serialNumber;
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.serialNumber;
import static org.testng.Assert.assertEquals;
import java.util.concurrent.TimeUnit;

View File

@ -22,12 +22,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.testng.Assert.assertTrue;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.sts.domain.UserAndTemporaryCredentials;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.sts.domain.UserAndSessionCredentials;
import org.jclouds.sts.internal.BaseSTSApiLiveTest;
import org.jclouds.sts.options.AssumeRoleOptions;
import org.jclouds.sts.options.FederatedUserOptions;
import org.jclouds.sts.options.TemporaryCredentialsOptions;
import org.jclouds.sts.options.SessionCredentialsOptions;
import org.testng.SkipException;
import org.testng.annotations.Test;
@ -39,8 +39,8 @@ public class STSApiLiveTest extends BaseSTSApiLiveTest {
@Test
protected void testCreateTemporaryCredentials() {
TemporaryCredentials creds = api().createTemporaryCredentials(
new TemporaryCredentialsOptions().durationSeconds(MINUTES.toSeconds(15)));
SessionCredentials creds = api().createTemporaryCredentials(
new SessionCredentialsOptions().durationSeconds(MINUTES.toSeconds(15)));
checkTemporaryCredentials(creds);
// TODO: actually login to some service
//
@ -53,7 +53,7 @@ public class STSApiLiveTest extends BaseSTSApiLiveTest {
@Test
protected void testCreateFederatedUser() {
UserAndTemporaryCredentials user = api().createFederatedUser("Bob", new FederatedUserOptions().durationSeconds(MINUTES.toSeconds(15)));
UserAndSessionCredentials user = api().createFederatedUser("Bob", new FederatedUserOptions().durationSeconds(MINUTES.toSeconds(15)));
checkTemporaryCredentials(user.getCredentials());
assertTrue(user.getUser().getId().contains("Bob"), user + " id incorrect");
assertTrue(user.getUser().getArn().contains("Bob"), user + " arn incorrect");
@ -63,7 +63,7 @@ public class STSApiLiveTest extends BaseSTSApiLiveTest {
@Test
protected void testAssumeRole() {
String arnToAssume = getTestArn();
UserAndTemporaryCredentials role = api().assumeRole(arnToAssume, "session",
UserAndSessionCredentials role = api().assumeRole(arnToAssume, "session",
new AssumeRoleOptions().durationSeconds(MINUTES.toSeconds(15)));
checkTemporaryCredentials(role.getCredentials());
assertTrue(role.getUser().getId().contains("session"), role + " id incorrect");
@ -75,7 +75,7 @@ public class STSApiLiveTest extends BaseSTSApiLiveTest {
throw new SkipException("TODO: need to query a valid arn to assume");
}
private void checkTemporaryCredentials(TemporaryCredentials creds) {
private void checkTemporaryCredentials(SessionCredentials creds) {
checkNotNull(creds.getAccessKeyId(), "AccessKeyId cannot be null for TemporaryCredentials.");
checkNotNull(creds.getSecretAccessKey(), "SecretAccessKey cannot be null for TemporaryCredentials.");
checkNotNull(creds.getSessionToken(), "SessionToken cannot be null for TemporaryCredentials.");

View File

@ -18,9 +18,9 @@
*/
package org.jclouds.sts.options;
import static org.jclouds.sts.options.TemporaryCredentialsOptions.Builder.serialNumber;
import static org.jclouds.sts.options.TemporaryCredentialsOptions.Builder.durationSeconds;
import static org.jclouds.sts.options.TemporaryCredentialsOptions.Builder.tokenCode;
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.serialNumber;
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.durationSeconds;
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.tokenCode;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
@ -31,36 +31,36 @@ import com.google.common.collect.ImmutableSet;
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "TemporaryCredentialsOptionsTest")
public class TemporaryCredentialsOptionsTest {
@Test(groups = "unit", testName = "SessionCredentialsOptionsTest")
public class SessionCredentialsOptionsTest {
public void testSerialNumber() {
TemporaryCredentialsOptions options = new TemporaryCredentialsOptions().serialNumber("YourMFADeviceSerialNumber");
SessionCredentialsOptions options = new SessionCredentialsOptions().serialNumber("YourMFADeviceSerialNumber");
assertEquals(ImmutableSet.of("YourMFADeviceSerialNumber"), options.buildFormParameters().get("SerialNumber"));
}
public void testSerialNumberStatic() {
TemporaryCredentialsOptions options = serialNumber("YourMFADeviceSerialNumber");
SessionCredentialsOptions options = serialNumber("YourMFADeviceSerialNumber");
assertEquals(ImmutableSet.of("YourMFADeviceSerialNumber"), options.buildFormParameters().get("SerialNumber"));
}
public void testDurationSeconds() {
TemporaryCredentialsOptions options = new TemporaryCredentialsOptions().durationSeconds(3600);
SessionCredentialsOptions options = new SessionCredentialsOptions().durationSeconds(3600);
assertEquals(ImmutableSet.of("3600"), options.buildFormParameters().get("DurationSeconds"));
}
public void testDurationSecondsStatic() {
TemporaryCredentialsOptions options = durationSeconds(3600);
SessionCredentialsOptions options = durationSeconds(3600);
assertEquals(ImmutableSet.of("3600"), options.buildFormParameters().get("DurationSeconds"));
}
public void testTokenCode() {
TemporaryCredentialsOptions options = new TemporaryCredentialsOptions().tokenCode("123456");
SessionCredentialsOptions options = new SessionCredentialsOptions().tokenCode("123456");
assertEquals(ImmutableSet.of("123456"), options.buildFormParameters().get("TokenCode"));
}
public void testTokenCodeStatic() {
TemporaryCredentialsOptions options = tokenCode("123456");
SessionCredentialsOptions options = tokenCode("123456");
assertEquals(ImmutableSet.of("123456"), options.buildFormParameters().get("TokenCode"));
}

View File

@ -23,9 +23,9 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.sts.domain.UserAndTemporaryCredentials;
import org.jclouds.sts.domain.UserAndSessionCredentials;
import org.jclouds.sts.domain.User;
import org.jclouds.sts.xml.UserAndTemporaryCredentialsHandler;
import org.jclouds.sts.xml.UserAndSessionCredentialsHandler;
import org.testng.annotations.Test;
/**
@ -38,18 +38,18 @@ public class AssumeRoleResponseTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/assume_role.xml");
UserAndTemporaryCredentials expected = expected();
UserAndSessionCredentials expected = expected();
UserAndTemporaryCredentialsHandler handler = injector.getInstance(UserAndTemporaryCredentialsHandler.class);
UserAndTemporaryCredentials result = factory.create(handler).parse(is);
UserAndSessionCredentialsHandler handler = injector.getInstance(UserAndSessionCredentialsHandler.class);
UserAndSessionCredentials result = factory.create(handler).parse(is);
assertEquals(result, expected);
assertEquals(result.getUser(), expected.getUser());
assertEquals(result.getPackedPolicySize(), expected.getPackedPolicySize());
}
public UserAndTemporaryCredentials expected() {
return UserAndTemporaryCredentials.builder()
public UserAndSessionCredentials expected() {
return UserAndSessionCredentials.builder()
.credentials(new GetSessionTokenResponseTest().expected())
.user(User.fromIdAndArn("ARO123EXAMPLE123:Bob", "arn:aws:sts::123456789012:assumed-role/demo/Bob"))
.packedPolicySize(6).build();

View File

@ -23,9 +23,9 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.sts.domain.UserAndTemporaryCredentials;
import org.jclouds.sts.domain.UserAndSessionCredentials;
import org.jclouds.sts.domain.User;
import org.jclouds.sts.xml.UserAndTemporaryCredentialsHandler;
import org.jclouds.sts.xml.UserAndSessionCredentialsHandler;
import org.testng.annotations.Test;
/**
@ -38,18 +38,18 @@ public class GetFederationTokenResponseTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/federation_token.xml");
UserAndTemporaryCredentials expected = expected();
UserAndSessionCredentials expected = expected();
UserAndTemporaryCredentialsHandler handler = injector.getInstance(UserAndTemporaryCredentialsHandler.class);
UserAndTemporaryCredentials result = factory.create(handler).parse(is);
UserAndSessionCredentialsHandler handler = injector.getInstance(UserAndSessionCredentialsHandler.class);
UserAndSessionCredentials result = factory.create(handler).parse(is);
assertEquals(result, expected);
assertEquals(result.getUser(), expected.getUser());
assertEquals(result.getPackedPolicySize(), expected.getPackedPolicySize());
}
public UserAndTemporaryCredentials expected() {
return UserAndTemporaryCredentials.builder()
public UserAndSessionCredentials expected() {
return UserAndSessionCredentials.builder()
.credentials(new GetSessionTokenResponseTest().expected())
.user(User.fromIdAndArn("123456789012:Bob", "arn:aws:sts::123456789012:federated-user/Bob"))
.packedPolicySize(6).build();

View File

@ -22,8 +22,8 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.aws.domain.TemporaryCredentials;
import org.jclouds.aws.xml.TemporaryCredentialsHandler;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.aws.xml.SessionCredentialsHandler;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
@ -38,10 +38,10 @@ public class GetSessionTokenResponseTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/session_token.xml");
TemporaryCredentials expected = expected();
SessionCredentials expected = expected();
TemporaryCredentialsHandler handler = injector.getInstance(TemporaryCredentialsHandler.class);
TemporaryCredentials result = factory.create(handler).parse(is);
SessionCredentialsHandler handler = injector.getInstance(SessionCredentialsHandler.class);
SessionCredentials result = factory.create(handler).parse(is);
assertEquals(result, expected);
assertEquals(result.getAccessKeyId(), expected.getAccessKeyId());
@ -50,8 +50,8 @@ public class GetSessionTokenResponseTest extends BaseHandlerTest {
assertEquals(result.getExpiration(), expected.getExpiration());
}
public TemporaryCredentials expected() {
return TemporaryCredentials.builder()
public SessionCredentials expected() {
return SessionCredentials.builder()
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")