mirror of https://github.com/apache/jclouds.git
Merge pull request #1362 from jclouds/sts-rename
rename TemporaryCredentials to SessionCredentials per aws sdk
This commit is contained in:
commit
8e33229e94
|
@ -33,7 +33,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.aws.domain.TemporaryCredentials;
|
import org.jclouds.aws.domain.SessionCredentials;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
@ -71,15 +71,15 @@ public class RestAuthentication implements HttpRequestFilter, RequestSigner {
|
||||||
|
|
||||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||||
Credentials current = creds.get();
|
Credentials current = creds.get();
|
||||||
if (current instanceof TemporaryCredentials) {
|
if (current instanceof SessionCredentials) {
|
||||||
request = replaceSecurityTokenHeader(request, TemporaryCredentials.class.cast(current));
|
request = replaceSecurityTokenHeader(request, SessionCredentials.class.cast(current));
|
||||||
}
|
}
|
||||||
request = replaceDateHeader(request, timeStampProvider.get());
|
request = replaceDateHeader(request, timeStampProvider.get());
|
||||||
String signature = sign(createStringToSign(request));
|
String signature = sign(createStringToSign(request));
|
||||||
return replaceAuthorizationHeader(request, signature);
|
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();
|
return request.toBuilder().replaceHeader("x-amz-security-token", current.getSessionToken()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.aws.domain.TemporaryCredentials;
|
import org.jclouds.aws.domain.SessionCredentials;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
@ -121,8 +121,8 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
||||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||||
request = replaceDateHeader(request);
|
request = replaceDateHeader(request);
|
||||||
Credentials current = creds.get();
|
Credentials current = creds.get();
|
||||||
if (current instanceof TemporaryCredentials) {
|
if (current instanceof SessionCredentials) {
|
||||||
request = replaceSecurityTokenHeader(request, TemporaryCredentials.class.cast(current));
|
request = replaceSecurityTokenHeader(request, SessionCredentials.class.cast(current));
|
||||||
}
|
}
|
||||||
String signature = calculateSignature(createStringToSign(request));
|
String signature = calculateSignature(createStringToSign(request));
|
||||||
request = replaceAuthorizationHeader(request, signature);
|
request = replaceAuthorizationHeader(request, signature);
|
||||||
|
@ -130,7 +130,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
||||||
return request;
|
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();
|
return request.toBuilder().replaceHeader("x-amz-security-token", current.getSessionToken()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import static org.jclouds.reflect.Reflection2.method;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import org.jclouds.ContextBuilder;
|
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.TimeStamp;
|
||||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
@ -49,8 +49,8 @@ import com.google.inject.Module;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||||
@Test(groups = "unit", testName = "RequestAuthorizeSignatureWithTemporaryCredentialsTest")
|
@Test(groups = "unit", testName = "RequestAuthorizeSignatureWithSessionCredentialsTest")
|
||||||
public class RequestAuthorizeSignatureWithTemporaryCredentialsTest {
|
public class RequestAuthorizeSignatureWithSessionCredentialsTest {
|
||||||
public static Injector injector(Credentials creds) {
|
public static Injector injector(Credentials creds) {
|
||||||
return ContextBuilder.newBuilder("s3")
|
return ContextBuilder.newBuilder("s3")
|
||||||
.credentialsSupplier(Suppliers.<Credentials> ofInstance(creds))
|
.credentialsSupplier(Suppliers.<Credentials> ofInstance(creds))
|
||||||
|
@ -70,7 +70,7 @@ public class RequestAuthorizeSignatureWithTemporaryCredentialsTest {
|
||||||
return injector(creds).getInstance(RequestAuthorizeSignature.class);
|
return injector(creds).getInstance(RequestAuthorizeSignature.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemporaryCredentials temporaryCredentials = TemporaryCredentials.builder()
|
SessionCredentials temporaryCredentials = SessionCredentials.builder()
|
||||||
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
|
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
|
||||||
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
|
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
|
||||||
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")
|
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")
|
|
@ -25,7 +25,7 @@ import java.util.Date;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AWS credentials for API authentication.
|
* AWS credentials for API authentication.
|
||||||
|
@ -36,77 +36,12 @@ import com.google.common.base.Supplier;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public final class TemporaryCredentials extends Credentials {
|
public final class SessionCredentials 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String sessionToken;
|
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",
|
super(checkNotNull(accessKeyId, "accessKeyId"), checkNotNull(secretAccessKey, "secretAccessKey for %s",
|
||||||
accessKeyId));
|
accessKeyId));
|
||||||
this.sessionToken = checkNotNull(sessionToken, "sessionToken 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.
|
* The date on which these credentials expire.
|
||||||
*/
|
*/
|
||||||
public Date getExpiration() {
|
public Optional<Date> getExpiration() {
|
||||||
return expiration;
|
return expiration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(identity, credential, sessionToken, expiration);
|
return Objects.hashCode(identity, credential, sessionToken, expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
|
@ -161,17 +90,80 @@ public final class TemporaryCredentials extends Credentials {
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
TemporaryCredentials other = (TemporaryCredentials) obj;
|
SessionCredentials other = (SessionCredentials) obj;
|
||||||
return Objects.equal(this.identity, other.identity) && Objects.equal(this.credential, other.credential)
|
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);
|
&& Objects.equal(this.sessionToken, other.sessionToken) && Objects.equal(this.expiration, other.expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Objects.toStringHelper(this).add("accessKeyId", identity).add("sessionToken", sessionToken)
|
return Objects.toStringHelper(this).omitNullValues().add("accessKeyId", identity)
|
||||||
.add("expiration", expiration).toString();
|
.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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -47,7 +47,7 @@ import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.aws.domain.TemporaryCredentials;
|
import org.jclouds.aws.domain.SessionCredentials;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
@ -206,8 +206,8 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
||||||
params.removeAll(SIGNATURE);
|
params.removeAll(SIGNATURE);
|
||||||
params.removeAll(SECURITY_TOKEN);
|
params.removeAll(SECURITY_TOKEN);
|
||||||
Credentials current = creds.get();
|
Credentials current = creds.get();
|
||||||
if (current instanceof TemporaryCredentials) {
|
if (current instanceof SessionCredentials) {
|
||||||
params.put(SECURITY_TOKEN, TemporaryCredentials.class.cast(current).getSessionToken());
|
params.put(SECURITY_TOKEN, SessionCredentials.class.cast(current).getSessionToken());
|
||||||
}
|
}
|
||||||
params.replaceValues(SIGNATURE_METHOD, ImmutableList.of("HmacSHA256"));
|
params.replaceValues(SIGNATURE_METHOD, ImmutableList.of("HmacSHA256"));
|
||||||
params.replaceValues(SIGNATURE_VERSION, ImmutableList.of("2"));
|
params.replaceValues(SIGNATURE_VERSION, ImmutableList.of("2"));
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.aws.xml;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.aws.domain.TemporaryCredentials;
|
import org.jclouds.aws.domain.SessionCredentials;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.util.SaxUtils;
|
import org.jclouds.util.SaxUtils;
|
||||||
|
@ -32,32 +32,26 @@ import org.jclouds.util.SaxUtils;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class TemporaryCredentialsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<TemporaryCredentials> {
|
public class SessionCredentialsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<SessionCredentials> {
|
||||||
private final DateService dateService;
|
private final DateService dateService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected TemporaryCredentialsHandler(DateService dateService) {
|
protected SessionCredentialsHandler(DateService dateService) {
|
||||||
this.dateService = dateService;
|
this.dateService = dateService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBuilder currentText = new StringBuilder();
|
private StringBuilder currentText = new StringBuilder();
|
||||||
private TemporaryCredentials.Builder builder = TemporaryCredentials.builder();
|
private SessionCredentials.Builder builder = SessionCredentials.builder();
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public TemporaryCredentials getResult() {
|
public SessionCredentials getResult() {
|
||||||
try {
|
try {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
} finally {
|
} finally {
|
||||||
builder = TemporaryCredentials.builder();
|
builder = SessionCredentials.builder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void endElement(String uri, String name, String qName) {
|
public void endElement(String uri, String name, String qName) {
|
||||||
if (qName.equals("AccessKeyId")) {
|
if (qName.equals("AccessKeyId")) {
|
||||||
|
@ -72,12 +66,8 @@ public class TemporaryCredentialsHandler extends ParseSax.HandlerForGeneratedReq
|
||||||
currentText = new StringBuilder();
|
currentText = new StringBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void characters(char ch[], int start, int length) {
|
public void characters(char ch[], int start, int length) {
|
||||||
currentText.append(ch, start, length);
|
currentText.append(ch, start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,12 +18,12 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.sts;
|
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.User;
|
||||||
import org.jclouds.sts.domain.UserAndTemporaryCredentials;
|
import org.jclouds.sts.domain.UserAndSessionCredentials;
|
||||||
import org.jclouds.sts.options.AssumeRoleOptions;
|
import org.jclouds.sts.options.AssumeRoleOptions;
|
||||||
import org.jclouds.sts.options.FederatedUserOptions;
|
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
|
* 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,
|
* Returns a set of temporary credentials for an AWS account or IAM user,
|
||||||
* with a default timeout
|
* with a default timeout
|
||||||
*/
|
*/
|
||||||
TemporaryCredentials createTemporaryCredentials();
|
SessionCredentials createTemporaryCredentials();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* like {@link #createTemporaryCredentials()}, except you can modify the
|
* like {@link #createTemporaryCredentials()}, except you can modify the
|
||||||
* timeout and other parameters.
|
* 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.
|
* 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
|
* The Amazon Resource Name (ARN) of the role that the caller is
|
||||||
* assuming.
|
* assuming.
|
||||||
*/
|
*/
|
||||||
UserAndTemporaryCredentials assumeRole(String roleArn, String sessionName);
|
UserAndSessionCredentials assumeRole(String roleArn, String sessionName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* like {@link #assumeRole(String, String)}, except you can modify the
|
* like {@link #assumeRole(String, String)}, except you can modify the
|
||||||
* timeout and other parameters.
|
* 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
|
* 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
|
* The name of the federated user, included as part of
|
||||||
* {@link User#getId}.
|
* {@link User#getId}.
|
||||||
*/
|
*/
|
||||||
UserAndTemporaryCredentials createFederatedUser(String userName);
|
UserAndSessionCredentials createFederatedUser(String userName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* like {@link #createFederatedUser(String)}, except you can modify the
|
* like {@link #createFederatedUser(String)}, except you can modify the
|
||||||
* timeout and other parameters.
|
* timeout and other parameters.
|
||||||
*/
|
*/
|
||||||
UserAndTemporaryCredentials createFederatedUser(String userName, FederatedUserOptions options);
|
UserAndSessionCredentials createFederatedUser(String userName, FederatedUserOptions options);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,18 +23,18 @@ import javax.ws.rs.FormParam;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
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.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.FormParams;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.VirtualHost;
|
import org.jclouds.rest.annotations.VirtualHost;
|
||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
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.AssumeRoleOptions;
|
||||||
import org.jclouds.sts.options.FederatedUserOptions;
|
import org.jclouds.sts.options.FederatedUserOptions;
|
||||||
import org.jclouds.sts.options.TemporaryCredentialsOptions;
|
import org.jclouds.sts.options.SessionCredentialsOptions;
|
||||||
import org.jclouds.sts.xml.UserAndTemporaryCredentialsHandler;
|
import org.jclouds.sts.xml.UserAndSessionCredentialsHandler;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
@ -55,19 +55,19 @@ public interface STSAsyncApi {
|
||||||
@Named("GetSessionToken")
|
@Named("GetSessionToken")
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@XMLResponseParser(TemporaryCredentialsHandler.class)
|
@XMLResponseParser(SessionCredentialsHandler.class)
|
||||||
@FormParams(keys = "Action", values = "GetSessionToken")
|
@FormParams(keys = "Action", values = "GetSessionToken")
|
||||||
ListenableFuture<TemporaryCredentials> createTemporaryCredentials();
|
ListenableFuture<SessionCredentials> createTemporaryCredentials();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see STSApi#createTemporaryCredentials(TemporaryCredentialsOptions)
|
* @see STSApi#createTemporaryCredentials(SessionCredentialsOptions)
|
||||||
*/
|
*/
|
||||||
@Named("GetSessionToken")
|
@Named("GetSessionToken")
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@XMLResponseParser(TemporaryCredentialsHandler.class)
|
@XMLResponseParser(SessionCredentialsHandler.class)
|
||||||
@FormParams(keys = "Action", values = "GetSessionToken")
|
@FormParams(keys = "Action", values = "GetSessionToken")
|
||||||
ListenableFuture<TemporaryCredentials> createTemporaryCredentials(TemporaryCredentialsOptions options);
|
ListenableFuture<SessionCredentials> createTemporaryCredentials(SessionCredentialsOptions options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see STSApi#assumeRole(String, String)
|
* @see STSApi#assumeRole(String, String)
|
||||||
|
@ -75,9 +75,9 @@ public interface STSAsyncApi {
|
||||||
@Named("AssumeRole")
|
@Named("AssumeRole")
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@XMLResponseParser(UserAndTemporaryCredentialsHandler.class)
|
@XMLResponseParser(UserAndSessionCredentialsHandler.class)
|
||||||
@FormParams(keys = "Action", values = "AssumeRole")
|
@FormParams(keys = "Action", values = "AssumeRole")
|
||||||
ListenableFuture<UserAndTemporaryCredentials> assumeRole(@FormParam("RoleArn") String roleArn,
|
ListenableFuture<UserAndSessionCredentials> assumeRole(@FormParam("RoleArn") String roleArn,
|
||||||
@FormParam("RoleSessionName") String sessionName);
|
@FormParam("RoleSessionName") String sessionName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,9 +86,9 @@ public interface STSAsyncApi {
|
||||||
@Named("AssumeRole")
|
@Named("AssumeRole")
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@XMLResponseParser(UserAndTemporaryCredentialsHandler.class)
|
@XMLResponseParser(UserAndSessionCredentialsHandler.class)
|
||||||
@FormParams(keys = "Action", values = "AssumeRole")
|
@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);
|
@FormParam("RoleSessionName") String sessionName, AssumeRoleOptions options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,9 +97,9 @@ public interface STSAsyncApi {
|
||||||
@Named("GetFederationToken")
|
@Named("GetFederationToken")
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@XMLResponseParser(UserAndTemporaryCredentialsHandler.class)
|
@XMLResponseParser(UserAndSessionCredentialsHandler.class)
|
||||||
@FormParams(keys = "Action", values = "GetFederationToken")
|
@FormParams(keys = "Action", values = "GetFederationToken")
|
||||||
ListenableFuture<UserAndTemporaryCredentials> createFederatedUser(@FormParam("Name") String userName);
|
ListenableFuture<UserAndSessionCredentials> createFederatedUser(@FormParam("Name") String userName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see STSApi#createFederatedUser(FederatedUserOptions)
|
* @see STSApi#createFederatedUser(FederatedUserOptions)
|
||||||
|
@ -107,7 +107,7 @@ public interface STSAsyncApi {
|
||||||
@Named("GetFederationToken")
|
@Named("GetFederationToken")
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@XMLResponseParser(UserAndTemporaryCredentialsHandler.class)
|
@XMLResponseParser(UserAndSessionCredentialsHandler.class)
|
||||||
@FormParams(keys = "Action", values = "GetFederationToken")
|
@FormParams(keys = "Action", values = "GetFederationToken")
|
||||||
ListenableFuture<UserAndTemporaryCredentials> createFederatedUser(@FormParam("Name") String userName, FederatedUserOptions options);
|
ListenableFuture<UserAndSessionCredentials> createFederatedUser(@FormParam("Name") String userName, FederatedUserOptions options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.sts.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import com.google.common.base.Objects;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public final class UserAndTemporaryCredentials {
|
public final class UserAndSessionCredentials {
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,11 @@ public final class UserAndTemporaryCredentials {
|
||||||
|
|
||||||
public final static class Builder {
|
public final static class Builder {
|
||||||
private User user;
|
private User user;
|
||||||
private TemporaryCredentials credentials;
|
private SessionCredentials credentials;
|
||||||
private int packedPolicySize;
|
private int packedPolicySize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see UserAndTemporaryCredentials#getUser()
|
* @see UserAndSessionCredentials#getUser()
|
||||||
*/
|
*/
|
||||||
public Builder user(User user) {
|
public Builder user(User user) {
|
||||||
this.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;
|
this.credentials = credentials;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see UserAndTemporaryCredentials#getPackedPolicySize()
|
* @see UserAndSessionCredentials#getPackedPolicySize()
|
||||||
*/
|
*/
|
||||||
public Builder packedPolicySize(int packedPolicySize) {
|
public Builder packedPolicySize(int packedPolicySize) {
|
||||||
this.packedPolicySize = packedPolicySize;
|
this.packedPolicySize = packedPolicySize;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserAndTemporaryCredentials build() {
|
public UserAndSessionCredentials build() {
|
||||||
return new UserAndTemporaryCredentials(user, credentials, packedPolicySize);
|
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);
|
return this.user(in.user).credentials(in.credentials).packedPolicySize(in.packedPolicySize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final User user;
|
private final User user;
|
||||||
private final TemporaryCredentials credentials;
|
private final SessionCredentials credentials;
|
||||||
private final int packedPolicySize;
|
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.user = checkNotNull(user, "user");
|
||||||
this.credentials = checkNotNull(credentials, "credentials for %s", user);
|
this.credentials = checkNotNull(credentials, "credentials for %s", user);
|
||||||
this.packedPolicySize = checkNotNull(packedPolicySize, "packedPolicySize 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() {
|
public User getUser() {
|
||||||
return user;
|
return user;
|
||||||
|
@ -96,7 +96,7 @@ public final class UserAndTemporaryCredentials {
|
||||||
* The temporary security credentials, which includes an Access Key ID, a
|
* The temporary security credentials, which includes an Access Key ID, a
|
||||||
* Secret Access Key, and a security token.
|
* Secret Access Key, and a security token.
|
||||||
*/
|
*/
|
||||||
public TemporaryCredentials getCredentials() {
|
public SessionCredentials getCredentials() {
|
||||||
return credentials;
|
return credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public final class UserAndTemporaryCredentials {
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
UserAndTemporaryCredentials other = (UserAndTemporaryCredentials) obj;
|
UserAndSessionCredentials other = (UserAndSessionCredentials) obj;
|
||||||
return Objects.equal(this.user, other.user) && Objects.equal(this.credentials, other.credentials)
|
return Objects.equal(this.user, other.user) && Objects.equal(this.credentials, other.credentials)
|
||||||
&& Objects.equal(this.packedPolicySize, other.packedPolicySize);
|
&& Objects.equal(this.packedPolicySize, other.packedPolicySize);
|
||||||
}
|
}
|
|
@ -32,7 +32,7 @@ import com.google.common.collect.Multimap;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @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
|
// long as this is a more typical unit for duration, hence less casting
|
||||||
private Long durationSeconds;
|
private Long durationSeconds;
|
||||||
|
@ -42,7 +42,7 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
|
||||||
/**
|
/**
|
||||||
* The identification number of the MFA device for the user.
|
* The identification number of the MFA device for the user.
|
||||||
*/
|
*/
|
||||||
public TemporaryCredentialsOptions serialNumber(String serialNumber) {
|
public SessionCredentialsOptions serialNumber(String serialNumber) {
|
||||||
this.serialNumber = serialNumber;
|
this.serialNumber = serialNumber;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
|
||||||
* The duration, in seconds, that the credentials should remain valid. 12
|
* The duration, in seconds, that the credentials should remain valid. 12
|
||||||
* hours is default. 15 minutes is current minimum.
|
* hours is default. 15 minutes is current minimum.
|
||||||
*/
|
*/
|
||||||
public TemporaryCredentialsOptions durationSeconds(long durationSeconds) {
|
public SessionCredentialsOptions durationSeconds(long durationSeconds) {
|
||||||
this.durationSeconds = durationSeconds;
|
this.durationSeconds = durationSeconds;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
|
||||||
/**
|
/**
|
||||||
* The value provided by the MFA device.
|
* The value provided by the MFA device.
|
||||||
*/
|
*/
|
||||||
public TemporaryCredentialsOptions tokenCode(String tokenCode) {
|
public SessionCredentialsOptions tokenCode(String tokenCode) {
|
||||||
this.tokenCode = tokenCode;
|
this.tokenCode = tokenCode;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -67,24 +67,24 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemporaryCredentialsOptions#serialNumber
|
* @see SessionCredentialsOptions#serialNumber
|
||||||
*/
|
*/
|
||||||
public static TemporaryCredentialsOptions serialNumber(String serialNumber) {
|
public static SessionCredentialsOptions serialNumber(String serialNumber) {
|
||||||
return new TemporaryCredentialsOptions().serialNumber(serialNumber);
|
return new SessionCredentialsOptions().serialNumber(serialNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemporaryCredentialsOptions#durationSeconds
|
* @see SessionCredentialsOptions#durationSeconds
|
||||||
*/
|
*/
|
||||||
public static TemporaryCredentialsOptions durationSeconds(long durationSeconds) {
|
public static SessionCredentialsOptions durationSeconds(long durationSeconds) {
|
||||||
return new TemporaryCredentialsOptions().durationSeconds(durationSeconds);
|
return new SessionCredentialsOptions().durationSeconds(durationSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemporaryCredentialsOptions#tokenCode
|
* @see SessionCredentialsOptions#tokenCode
|
||||||
*/
|
*/
|
||||||
public static TemporaryCredentialsOptions tokenCode(String tokenCode) {
|
public static SessionCredentialsOptions tokenCode(String tokenCode) {
|
||||||
return new TemporaryCredentialsOptions().tokenCode(tokenCode);
|
return new SessionCredentialsOptions().tokenCode(tokenCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,8 +109,8 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemporaryCredentialsOptions clone() {
|
public SessionCredentialsOptions clone() {
|
||||||
return new TemporaryCredentialsOptions().serialNumber(serialNumber).durationSeconds(durationSeconds)
|
return new SessionCredentialsOptions().serialNumber(serialNumber).durationSeconds(durationSeconds)
|
||||||
.tokenCode(tokenCode);
|
.tokenCode(tokenCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class TemporaryCredentialsOptions extends BaseHttpRequestOptions implemen
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
TemporaryCredentialsOptions other = TemporaryCredentialsOptions.class.cast(obj);
|
SessionCredentialsOptions other = SessionCredentialsOptions.class.cast(obj);
|
||||||
return Objects.equal(this.serialNumber, other.serialNumber)
|
return Objects.equal(this.serialNumber, other.serialNumber)
|
||||||
&& Objects.equal(this.durationSeconds, other.durationSeconds)
|
&& Objects.equal(this.durationSeconds, other.durationSeconds)
|
||||||
&& Objects.equal(this.tokenCode, other.tokenCode);
|
&& Objects.equal(this.tokenCode, other.tokenCode);
|
|
@ -21,10 +21,10 @@ package org.jclouds.sts.xml;
|
||||||
import static org.jclouds.util.SaxUtils.currentOrNull;
|
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
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.http.functions.ParseSax;
|
||||||
import org.jclouds.sts.domain.User;
|
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.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -34,27 +34,24 @@ import com.google.inject.Inject;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @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 StringBuilder currentText = new StringBuilder();
|
||||||
private UserAndTemporaryCredentials.Builder builder = UserAndTemporaryCredentials.builder();
|
private UserAndSessionCredentials.Builder builder = UserAndSessionCredentials.builder();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public UserAndTemporaryCredentialsHandler(TemporaryCredentialsHandler credsHandler) {
|
public UserAndSessionCredentialsHandler(SessionCredentialsHandler credsHandler) {
|
||||||
this.credsHandler = credsHandler;
|
this.credsHandler = credsHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public UserAndTemporaryCredentials getResult() {
|
public UserAndSessionCredentials getResult() {
|
||||||
try {
|
try {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
} finally {
|
} finally {
|
||||||
builder = UserAndTemporaryCredentials.builder();
|
builder = UserAndSessionCredentials.builder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.ContextBuilder;
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.aws.xml.TemporaryCredentialsHandlerTest;
|
import org.jclouds.aws.xml.SessionCredentialsHandlerTest;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
@ -84,7 +84,7 @@ public class FormSignerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAddsSecurityToken() {
|
void testAddsSecurityToken() {
|
||||||
HttpRequest filtered = filter(new TemporaryCredentialsHandlerTest().expected()).filter(request);
|
HttpRequest filtered = filter(new SessionCredentialsHandlerTest().expected()).filter(request);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
filtered.getPayload().getRawContent(),
|
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");
|
"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");
|
||||||
|
|
|
@ -22,8 +22,8 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.jclouds.aws.domain.TemporaryCredentials;
|
import org.jclouds.aws.domain.SessionCredentials;
|
||||||
import org.jclouds.aws.xml.TemporaryCredentialsHandler;
|
import org.jclouds.aws.xml.SessionCredentialsHandler;
|
||||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -32,16 +32,16 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||||
@Test(groups = "unit", testName = "TemporaryCredentialsHandlerTest")
|
@Test(groups = "unit", testName = "SessionCredentialsHandlerTest")
|
||||||
public class TemporaryCredentialsHandlerTest extends BaseHandlerTest {
|
public class SessionCredentialsHandlerTest extends BaseHandlerTest {
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
InputStream is = getClass().getResourceAsStream("/credentials.xml");
|
InputStream is = getClass().getResourceAsStream("/credentials.xml");
|
||||||
|
|
||||||
TemporaryCredentials expected = expected();
|
SessionCredentials expected = expected();
|
||||||
|
|
||||||
TemporaryCredentialsHandler handler = injector.getInstance(TemporaryCredentialsHandler.class);
|
SessionCredentialsHandler handler = injector.getInstance(SessionCredentialsHandler.class);
|
||||||
TemporaryCredentials result = factory.create(handler).parse(is);
|
SessionCredentials result = factory.create(handler).parse(is);
|
||||||
|
|
||||||
assertEquals(result, expected);
|
assertEquals(result, expected);
|
||||||
assertEquals(result.getAccessKeyId(), expected.getAccessKeyId());
|
assertEquals(result.getAccessKeyId(), expected.getAccessKeyId());
|
||||||
|
@ -50,8 +50,8 @@ public class TemporaryCredentialsHandlerTest extends BaseHandlerTest {
|
||||||
assertEquals(result.getExpiration(), expected.getExpiration());
|
assertEquals(result.getExpiration(), expected.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TemporaryCredentials expected() {
|
public SessionCredentials expected() {
|
||||||
return TemporaryCredentials.builder()
|
return SessionCredentials.builder()
|
||||||
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
|
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
|
||||||
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
|
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
|
||||||
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")
|
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")
|
|
@ -20,7 +20,7 @@ package org.jclouds.sts;
|
||||||
|
|
||||||
import static org.jclouds.sts.options.AssumeRoleOptions.Builder.externalId;
|
import static org.jclouds.sts.options.AssumeRoleOptions.Builder.externalId;
|
||||||
import static org.jclouds.sts.options.FederatedUserOptions.Builder.policy;
|
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 static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
|
@ -22,12 +22,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import org.jclouds.aws.domain.TemporaryCredentials;
|
import org.jclouds.aws.domain.SessionCredentials;
|
||||||
import org.jclouds.sts.domain.UserAndTemporaryCredentials;
|
import org.jclouds.sts.domain.UserAndSessionCredentials;
|
||||||
import org.jclouds.sts.internal.BaseSTSApiLiveTest;
|
import org.jclouds.sts.internal.BaseSTSApiLiveTest;
|
||||||
import org.jclouds.sts.options.AssumeRoleOptions;
|
import org.jclouds.sts.options.AssumeRoleOptions;
|
||||||
import org.jclouds.sts.options.FederatedUserOptions;
|
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.SkipException;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ public class STSApiLiveTest extends BaseSTSApiLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
protected void testCreateTemporaryCredentials() {
|
protected void testCreateTemporaryCredentials() {
|
||||||
TemporaryCredentials creds = api().createTemporaryCredentials(
|
SessionCredentials creds = api().createTemporaryCredentials(
|
||||||
new TemporaryCredentialsOptions().durationSeconds(MINUTES.toSeconds(15)));
|
new SessionCredentialsOptions().durationSeconds(MINUTES.toSeconds(15)));
|
||||||
checkTemporaryCredentials(creds);
|
checkTemporaryCredentials(creds);
|
||||||
// TODO: actually login to some service
|
// TODO: actually login to some service
|
||||||
//
|
//
|
||||||
|
@ -53,7 +53,7 @@ public class STSApiLiveTest extends BaseSTSApiLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
protected void testCreateFederatedUser() {
|
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());
|
checkTemporaryCredentials(user.getCredentials());
|
||||||
assertTrue(user.getUser().getId().contains("Bob"), user + " id incorrect");
|
assertTrue(user.getUser().getId().contains("Bob"), user + " id incorrect");
|
||||||
assertTrue(user.getUser().getArn().contains("Bob"), user + " arn incorrect");
|
assertTrue(user.getUser().getArn().contains("Bob"), user + " arn incorrect");
|
||||||
|
@ -63,7 +63,7 @@ public class STSApiLiveTest extends BaseSTSApiLiveTest {
|
||||||
@Test
|
@Test
|
||||||
protected void testAssumeRole() {
|
protected void testAssumeRole() {
|
||||||
String arnToAssume = getTestArn();
|
String arnToAssume = getTestArn();
|
||||||
UserAndTemporaryCredentials role = api().assumeRole(arnToAssume, "session",
|
UserAndSessionCredentials role = api().assumeRole(arnToAssume, "session",
|
||||||
new AssumeRoleOptions().durationSeconds(MINUTES.toSeconds(15)));
|
new AssumeRoleOptions().durationSeconds(MINUTES.toSeconds(15)));
|
||||||
checkTemporaryCredentials(role.getCredentials());
|
checkTemporaryCredentials(role.getCredentials());
|
||||||
assertTrue(role.getUser().getId().contains("session"), role + " id incorrect");
|
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");
|
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.getAccessKeyId(), "AccessKeyId cannot be null for TemporaryCredentials.");
|
||||||
checkNotNull(creds.getSecretAccessKey(), "SecretAccessKey cannot be null for TemporaryCredentials.");
|
checkNotNull(creds.getSecretAccessKey(), "SecretAccessKey cannot be null for TemporaryCredentials.");
|
||||||
checkNotNull(creds.getSessionToken(), "SessionToken cannot be null for TemporaryCredentials.");
|
checkNotNull(creds.getSessionToken(), "SessionToken cannot be null for TemporaryCredentials.");
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.sts.options;
|
package org.jclouds.sts.options;
|
||||||
|
|
||||||
import static org.jclouds.sts.options.TemporaryCredentialsOptions.Builder.serialNumber;
|
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.serialNumber;
|
||||||
import static org.jclouds.sts.options.TemporaryCredentialsOptions.Builder.durationSeconds;
|
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.durationSeconds;
|
||||||
import static org.jclouds.sts.options.TemporaryCredentialsOptions.Builder.tokenCode;
|
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.tokenCode;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -31,36 +31,36 @@ import com.google.common.collect.ImmutableSet;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "TemporaryCredentialsOptionsTest")
|
@Test(groups = "unit", testName = "SessionCredentialsOptionsTest")
|
||||||
public class TemporaryCredentialsOptionsTest {
|
public class SessionCredentialsOptionsTest {
|
||||||
|
|
||||||
public void testSerialNumber() {
|
public void testSerialNumber() {
|
||||||
TemporaryCredentialsOptions options = new TemporaryCredentialsOptions().serialNumber("YourMFADeviceSerialNumber");
|
SessionCredentialsOptions options = new SessionCredentialsOptions().serialNumber("YourMFADeviceSerialNumber");
|
||||||
assertEquals(ImmutableSet.of("YourMFADeviceSerialNumber"), options.buildFormParameters().get("SerialNumber"));
|
assertEquals(ImmutableSet.of("YourMFADeviceSerialNumber"), options.buildFormParameters().get("SerialNumber"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSerialNumberStatic() {
|
public void testSerialNumberStatic() {
|
||||||
TemporaryCredentialsOptions options = serialNumber("YourMFADeviceSerialNumber");
|
SessionCredentialsOptions options = serialNumber("YourMFADeviceSerialNumber");
|
||||||
assertEquals(ImmutableSet.of("YourMFADeviceSerialNumber"), options.buildFormParameters().get("SerialNumber"));
|
assertEquals(ImmutableSet.of("YourMFADeviceSerialNumber"), options.buildFormParameters().get("SerialNumber"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDurationSeconds() {
|
public void testDurationSeconds() {
|
||||||
TemporaryCredentialsOptions options = new TemporaryCredentialsOptions().durationSeconds(3600);
|
SessionCredentialsOptions options = new SessionCredentialsOptions().durationSeconds(3600);
|
||||||
assertEquals(ImmutableSet.of("3600"), options.buildFormParameters().get("DurationSeconds"));
|
assertEquals(ImmutableSet.of("3600"), options.buildFormParameters().get("DurationSeconds"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDurationSecondsStatic() {
|
public void testDurationSecondsStatic() {
|
||||||
TemporaryCredentialsOptions options = durationSeconds(3600);
|
SessionCredentialsOptions options = durationSeconds(3600);
|
||||||
assertEquals(ImmutableSet.of("3600"), options.buildFormParameters().get("DurationSeconds"));
|
assertEquals(ImmutableSet.of("3600"), options.buildFormParameters().get("DurationSeconds"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTokenCode() {
|
public void testTokenCode() {
|
||||||
TemporaryCredentialsOptions options = new TemporaryCredentialsOptions().tokenCode("123456");
|
SessionCredentialsOptions options = new SessionCredentialsOptions().tokenCode("123456");
|
||||||
assertEquals(ImmutableSet.of("123456"), options.buildFormParameters().get("TokenCode"));
|
assertEquals(ImmutableSet.of("123456"), options.buildFormParameters().get("TokenCode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTokenCodeStatic() {
|
public void testTokenCodeStatic() {
|
||||||
TemporaryCredentialsOptions options = tokenCode("123456");
|
SessionCredentialsOptions options = tokenCode("123456");
|
||||||
assertEquals(ImmutableSet.of("123456"), options.buildFormParameters().get("TokenCode"));
|
assertEquals(ImmutableSet.of("123456"), options.buildFormParameters().get("TokenCode"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
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.domain.User;
|
||||||
import org.jclouds.sts.xml.UserAndTemporaryCredentialsHandler;
|
import org.jclouds.sts.xml.UserAndSessionCredentialsHandler;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,18 +38,18 @@ public class AssumeRoleResponseTest extends BaseHandlerTest {
|
||||||
public void test() {
|
public void test() {
|
||||||
InputStream is = getClass().getResourceAsStream("/assume_role.xml");
|
InputStream is = getClass().getResourceAsStream("/assume_role.xml");
|
||||||
|
|
||||||
UserAndTemporaryCredentials expected = expected();
|
UserAndSessionCredentials expected = expected();
|
||||||
|
|
||||||
UserAndTemporaryCredentialsHandler handler = injector.getInstance(UserAndTemporaryCredentialsHandler.class);
|
UserAndSessionCredentialsHandler handler = injector.getInstance(UserAndSessionCredentialsHandler.class);
|
||||||
UserAndTemporaryCredentials result = factory.create(handler).parse(is);
|
UserAndSessionCredentials result = factory.create(handler).parse(is);
|
||||||
|
|
||||||
assertEquals(result, expected);
|
assertEquals(result, expected);
|
||||||
assertEquals(result.getUser(), expected.getUser());
|
assertEquals(result.getUser(), expected.getUser());
|
||||||
assertEquals(result.getPackedPolicySize(), expected.getPackedPolicySize());
|
assertEquals(result.getPackedPolicySize(), expected.getPackedPolicySize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserAndTemporaryCredentials expected() {
|
public UserAndSessionCredentials expected() {
|
||||||
return UserAndTemporaryCredentials.builder()
|
return UserAndSessionCredentials.builder()
|
||||||
.credentials(new GetSessionTokenResponseTest().expected())
|
.credentials(new GetSessionTokenResponseTest().expected())
|
||||||
.user(User.fromIdAndArn("ARO123EXAMPLE123:Bob", "arn:aws:sts::123456789012:assumed-role/demo/Bob"))
|
.user(User.fromIdAndArn("ARO123EXAMPLE123:Bob", "arn:aws:sts::123456789012:assumed-role/demo/Bob"))
|
||||||
.packedPolicySize(6).build();
|
.packedPolicySize(6).build();
|
||||||
|
|
|
@ -23,9 +23,9 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
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.domain.User;
|
||||||
import org.jclouds.sts.xml.UserAndTemporaryCredentialsHandler;
|
import org.jclouds.sts.xml.UserAndSessionCredentialsHandler;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,18 +38,18 @@ public class GetFederationTokenResponseTest extends BaseHandlerTest {
|
||||||
public void test() {
|
public void test() {
|
||||||
InputStream is = getClass().getResourceAsStream("/federation_token.xml");
|
InputStream is = getClass().getResourceAsStream("/federation_token.xml");
|
||||||
|
|
||||||
UserAndTemporaryCredentials expected = expected();
|
UserAndSessionCredentials expected = expected();
|
||||||
|
|
||||||
UserAndTemporaryCredentialsHandler handler = injector.getInstance(UserAndTemporaryCredentialsHandler.class);
|
UserAndSessionCredentialsHandler handler = injector.getInstance(UserAndSessionCredentialsHandler.class);
|
||||||
UserAndTemporaryCredentials result = factory.create(handler).parse(is);
|
UserAndSessionCredentials result = factory.create(handler).parse(is);
|
||||||
|
|
||||||
assertEquals(result, expected);
|
assertEquals(result, expected);
|
||||||
assertEquals(result.getUser(), expected.getUser());
|
assertEquals(result.getUser(), expected.getUser());
|
||||||
assertEquals(result.getPackedPolicySize(), expected.getPackedPolicySize());
|
assertEquals(result.getPackedPolicySize(), expected.getPackedPolicySize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserAndTemporaryCredentials expected() {
|
public UserAndSessionCredentials expected() {
|
||||||
return UserAndTemporaryCredentials.builder()
|
return UserAndSessionCredentials.builder()
|
||||||
.credentials(new GetSessionTokenResponseTest().expected())
|
.credentials(new GetSessionTokenResponseTest().expected())
|
||||||
.user(User.fromIdAndArn("123456789012:Bob", "arn:aws:sts::123456789012:federated-user/Bob"))
|
.user(User.fromIdAndArn("123456789012:Bob", "arn:aws:sts::123456789012:federated-user/Bob"))
|
||||||
.packedPolicySize(6).build();
|
.packedPolicySize(6).build();
|
||||||
|
|
|
@ -22,8 +22,8 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.jclouds.aws.domain.TemporaryCredentials;
|
import org.jclouds.aws.domain.SessionCredentials;
|
||||||
import org.jclouds.aws.xml.TemporaryCredentialsHandler;
|
import org.jclouds.aws.xml.SessionCredentialsHandler;
|
||||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -38,10 +38,10 @@ public class GetSessionTokenResponseTest extends BaseHandlerTest {
|
||||||
public void test() {
|
public void test() {
|
||||||
InputStream is = getClass().getResourceAsStream("/session_token.xml");
|
InputStream is = getClass().getResourceAsStream("/session_token.xml");
|
||||||
|
|
||||||
TemporaryCredentials expected = expected();
|
SessionCredentials expected = expected();
|
||||||
|
|
||||||
TemporaryCredentialsHandler handler = injector.getInstance(TemporaryCredentialsHandler.class);
|
SessionCredentialsHandler handler = injector.getInstance(SessionCredentialsHandler.class);
|
||||||
TemporaryCredentials result = factory.create(handler).parse(is);
|
SessionCredentials result = factory.create(handler).parse(is);
|
||||||
|
|
||||||
assertEquals(result, expected);
|
assertEquals(result, expected);
|
||||||
assertEquals(result.getAccessKeyId(), expected.getAccessKeyId());
|
assertEquals(result.getAccessKeyId(), expected.getAccessKeyId());
|
||||||
|
@ -50,8 +50,8 @@ public class GetSessionTokenResponseTest extends BaseHandlerTest {
|
||||||
assertEquals(result.getExpiration(), expected.getExpiration());
|
assertEquals(result.getExpiration(), expected.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TemporaryCredentials expected() {
|
public SessionCredentials expected() {
|
||||||
return TemporaryCredentials.builder()
|
return SessionCredentials.builder()
|
||||||
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
|
.accessKeyId("AKIAIOSFODNN7EXAMPLE")
|
||||||
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
|
.secretAccessKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")
|
||||||
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")
|
.sessionToken("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT")
|
||||||
|
|
Loading…
Reference in New Issue