本文整理汇总了Java中com.amazonaws.auth.AWSSessionCredentials类的典型用法代码示例。如果您正苦于以下问题:Java AWSSessionCredentials类的具体用法?Java AWSSessionCredentials怎么用?Java AWSSessionCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AWSSessionCredentials类属于com.amazonaws.auth包,在下文中一共展示了AWSSessionCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertEqualCredentials
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
private static void assertEqualCredentials(AWSCredentials expected, AWSCredentials actual) {
assertEquals(expected.getAWSAccessKeyId(),
actual.getAWSAccessKeyId());
assertEquals(expected.getAWSAccessKeyId(),
actual.getAWSAccessKeyId());
if (expected instanceof AWSSessionCredentials) {
assertTrue(actual instanceof AWSSessionCredentials);
AWSSessionCredentials expectedSession = (AWSSessionCredentials)expected;
AWSSessionCredentials actualSession = (AWSSessionCredentials)actual;
assertEquals(expectedSession.getSessionToken(),
actualSession.getSessionToken());
} else {
assertFalse(actual instanceof AWSSessionCredentials);
}
}
示例2: testTwoProfileWithSameName
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
/**
* Tests two profiles having same name. The second profile overrides the first profile. Also
* checks if the AWS Access Key ID and AWS Secret Access Key are mapped properly under the
* profile.
*/
@Test
public void testTwoProfileWithSameName() throws URISyntaxException {
ProfilesConfigFile profile = new ProfilesConfigFile(
ProfileResourceLoader.profilesWithSameProfileName().asFile());
AWSCredentials defaultCred = profile.getCredentials(DEFAULT_PROFILE_NAME);
assertNotNull(defaultCred);
assertTrue(defaultCred instanceof BasicAWSCredentials);
AWSCredentials testCred = profile.getCredentials(PROFILE_NAME_TEST);
assertNotNull(testCred);
assertTrue(testCred instanceof AWSSessionCredentials);
AWSSessionCredentials testSessionCred = (AWSSessionCredentials) testCred;
assertEquals(testSessionCred.getAWSAccessKeyId(), "testProfile2");
assertEquals(testSessionCred.getAWSSecretKey(), "testProfile2");
assertEquals(testSessionCred.getSessionToken(), "testProfile2");
}
示例3: sign
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
public void sign(SignableRequest<?> request, AWSCredentials credentials) throws SdkClientException {
AWSCredentials sanitizedCredentials = sanitizeCredentials(credentials);
if ( sanitizedCredentials instanceof AWSSessionCredentials ) {
addSessionCredentials(request, (AWSSessionCredentials) sanitizedCredentials);
}
String expirationInSeconds = Long.toString(expiration.getTime() / 1000L);
String canonicalString = RestUtils.makeS3CanonicalString(
httpVerb, resourcePath, request, expirationInSeconds);
String signature = super.signAndBase64Encode(canonicalString, sanitizedCredentials.getAWSSecretKey(), SigningAlgorithm.HmacSHA1);
request.addParameter("AWSAccessKeyId", sanitizedCredentials.getAWSAccessKeyId());
request.addParameter("Expires", expirationInSeconds);
request.addParameter("Signature", signature);
}
示例4: credentials
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
/** By default, get credentials from the {@link DefaultAWSCredentialsProviderChain} */
@Bean
@ConditionalOnMissingBean
AWSCredentials.Provider credentials() {
return new AWSCredentials.Provider() {
AWSCredentialsProvider delegate = new DefaultAWSCredentialsProviderChain();
@Override public AWSCredentials get() {
com.amazonaws.auth.AWSCredentials result = delegate.getCredentials();
String sessionToken = result instanceof AWSSessionCredentials
? ((AWSSessionCredentials) result).getSessionToken()
: null;
return new AWSCredentials(
result.getAWSAccessKeyId(),
result.getAWSSecretKey(),
sessionToken
);
}
};
}
示例5: getCopyConfig
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
private String getCopyConfig(Map<String, Object> configInput, boolean maskConfig)
throws IOException
{
TaskRequest taskRequest = testHelper.createTaskRequest(configInput, Optional.absent());
OperatorContext operatorContext = mock(OperatorContext.class);
when(operatorContext.getProjectPath()).thenReturn(testHelper.projectPath());
when(operatorContext.getTaskRequest()).thenReturn(taskRequest);
RedshiftLoadOperatorFactory.RedshiftLoadOperator operator = (RedshiftLoadOperatorFactory.RedshiftLoadOperator) operatorFactory.newOperator(operatorContext);
assertThat(operator, is(instanceOf(RedshiftLoadOperatorFactory.RedshiftLoadOperator.class)));
AWSSessionCredentials credentials = mock(AWSSessionCredentials.class);
when(credentials.getAWSAccessKeyId()).thenReturn("my-access-key-id");
when(credentials.getAWSSecretKey()).thenReturn("my-secret-access-key");
RedshiftConnection.CopyConfig copyConfig = operator.createCopyConfig(testHelper.createConfig(configInput), credentials);
Connection connection = mock(Connection.class);
RedshiftConnection redshiftConnection = new RedshiftConnection(connection);
return redshiftConnection.buildCopyStatement(copyConfig, maskConfig);
}
示例6: getUnloadConfig
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
private String getUnloadConfig(Map<String, Object> configInput, String queryId, boolean maskConfig)
throws IOException
{
TaskRequest taskRequest = testHelper.createTaskRequest(configInput, Optional.absent());
OperatorContext operatorContext = mock(OperatorContext.class);
when(operatorContext.getProjectPath()).thenReturn(testHelper.projectPath());
when(operatorContext.getTaskRequest()).thenReturn(taskRequest);
RedshiftUnloadOperatorFactory.RedshiftUnloadOperator operator = (RedshiftUnloadOperatorFactory.RedshiftUnloadOperator) operatorFactory.newOperator(operatorContext);
assertThat(operator, is(instanceOf(RedshiftUnloadOperatorFactory.RedshiftUnloadOperator.class)));
AWSSessionCredentials credentials = mock(AWSSessionCredentials.class);
when(credentials.getAWSAccessKeyId()).thenReturn("my-access-key-id");
when(credentials.getAWSSecretKey()).thenReturn("my-secret-access-key");
RedshiftConnection.UnloadConfig unloadConfig = operator.createUnloadConfig(testHelper.createConfig(configInput), credentials, queryId);
Connection connection = mock(Connection.class);
RedshiftConnection redshiftConnection = new RedshiftConnection(connection);
return redshiftConnection.buildUnloadStatement(unloadConfig, maskConfig);
}
示例7: serviceWithSessionToken
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
@Test
public void serviceWithSessionToken() throws Exception {
String accessKey = "accessKey";
String secretKey = "secretKey";
String sessionToken = "sessionToken";
new MockUnit(Config.class)
.expect(unit -> {
Config config = unit.get(Config.class);
expect(config.hasPath("aws.s3.accessKey")).andReturn(false);
expect(config.hasPath("aws.s3.secretKey")).andReturn(false);
expect(config.hasPath("aws.s3.sessionToken")).andReturn(false);
expect(config.hasPath("aws.sessionToken")).andReturn(true);
expect(config.getString("aws.accessKey")).andReturn(accessKey);
expect(config.getString("aws.secretKey")).andReturn(secretKey);
expect(config.getString("aws.sessionToken")).andReturn(sessionToken);
})
.run(unit -> {
AWSSessionCredentials creds = (AWSSessionCredentials) new ConfigCredentialsProvider(
unit.get(Config.class))
.service("s3").getCredentials();
assertEquals("accessKey", creds.getAWSAccessKeyId());
assertEquals("secretKey", creds.getAWSSecretKey());
assertEquals("sessionToken", creds.getSessionToken());
});
}
示例8: serviceWithCustomSessionToken
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
@Test
public void serviceWithCustomSessionToken() throws Exception {
String accessKey = "accessKey";
String secretKey = "secretKey";
String sessionToken = "sessionToken";
new MockUnit(Config.class)
.expect(unit -> {
Config config = unit.get(Config.class);
expect(config.hasPath("aws.s3.accessKey")).andReturn(false);
expect(config.hasPath("aws.s3.secretKey")).andReturn(false);
expect(config.hasPath("aws.s3.sessionToken")).andReturn(true);
expect(config.getString("aws.accessKey")).andReturn(accessKey);
expect(config.getString("aws.secretKey")).andReturn(secretKey);
expect(config.getString("aws.s3.sessionToken")).andReturn(sessionToken);
})
.run(unit -> {
AWSSessionCredentials creds = (AWSSessionCredentials) new ConfigCredentialsProvider(
unit.get(Config.class))
.service("s3").getCredentials();
assertEquals("accessKey", creds.getAWSAccessKeyId());
assertEquals("secretKey", creds.getAWSSecretKey());
assertEquals("sessionToken", creds.getSessionToken());
});
}
示例9: Profile
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
public Profile(String profileName, AWSCredentials awsCredentials) {
Map<String, String> properties = new LinkedHashMap<String, String>();
properties.put(ProfileKeyConstants.AWS_ACCESS_KEY_ID, awsCredentials.getAWSAccessKeyId());
properties.put(ProfileKeyConstants.AWS_SECRET_ACCESS_KEY, awsCredentials.getAWSSecretKey());
if (awsCredentials instanceof AWSSessionCredentials) {
AWSSessionCredentials sessionCred = (AWSSessionCredentials)awsCredentials;
properties.put(ProfileKeyConstants.AWS_SESSION_TOKEN, sessionCred.getSessionToken());
}
this.profileName = profileName;
this.properties = properties;
this.awsCredentials = new StaticCredentialsProvider(awsCredentials);
}
示例10: getSignedHeaders
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
public Map<String, String> getSignedHeaders(String uri, String method,
Map<String, String> queryParams,
Map<String, String> headers,
Optional<byte[]> payload) {
final LocalDateTime now = clock.get();
final AWSCredentials credentials = credentialsProvider.getCredentials();
final Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
result.putAll(headers);
if (!result.containsKey(DATE)) {
result.put(X_AMZ_DATE, now.format(BASIC_TIME_FORMAT));
}
if (AWSSessionCredentials.class.isAssignableFrom(credentials.getClass())) {
result.put(SESSION_TOKEN, ((AWSSessionCredentials) credentials).getSessionToken());
}
final StringBuilder headersString = new StringBuilder();
final ImmutableList.Builder<String> signedHeaders = ImmutableList.builder();
for (Map.Entry<String, String> entry : result.entrySet()) {
headersString.append(headerAsString(entry)).append(RETURN);
signedHeaders.add(entry.getKey().toLowerCase());
}
final String signedHeaderKeys = JOINER.join(signedHeaders.build());
final String canonicalRequest = method + RETURN +
uri + RETURN +
queryParamsString(queryParams) + RETURN +
headersString.toString() + RETURN +
signedHeaderKeys + RETURN +
toBase16(hash(payload.orElse(EMPTY.getBytes(Charsets.UTF_8))));
final String stringToSign = createStringToSign(canonicalRequest, now);
final String signature = sign(stringToSign, now, credentials);
final String autorizationHeader = AWS4_HMAC_SHA256_CREDENTIAL + credentials.getAWSAccessKeyId() + SLASH + getCredentialScope(now) +
SIGNED_HEADERS + signedHeaderKeys +
SIGNATURE + signature;
result.put(AUTHORIZATION, autorizationHeader);
return ImmutableMap.copyOf(result);
}
示例11: getCredentials
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
@Override
public AWSSessionCredentials getCredentials() {
if (this.credentials == null || this.lastRefreshedInstant.isBefore(Instant.now().minus(CREDENTIALS_DURATION))) {
refresh();
}
return this.credentials;
}
开发者ID:awslabs,项目名称:aws-codepipeline-plugin-for-jenkins,代码行数:8,代码来源:AWSCodePipelineJobCredentialsProvider.java
示例12: refresh
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
@Override
public synchronized void refresh() {
final GetJobDetailsRequest getJobDetailsRequest = new GetJobDetailsRequest().withJobId(jobId);
final GetJobDetailsResult getJobDetailsResult = codePipelineClient.getJobDetails(getJobDetailsRequest);
final com.amazonaws.services.codepipeline.model.AWSSessionCredentials credentials
= getJobDetailsResult.getJobDetails().getData().getArtifactCredentials();
this.lastRefreshedInstant = Instant.now();
this.credentials = new BasicSessionCredentials(
credentials.getAccessKeyId(),
credentials.getSecretAccessKey(),
credentials.getSessionToken());
}
开发者ID:awslabs,项目名称:aws-codepipeline-plugin-for-jenkins,代码行数:14,代码来源:AWSCodePipelineJobCredentialsProvider.java
示例13: createSessionCredentials
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
private AWSSessionCredentials createSessionCredentials(Config config, SecretProvider secrets, BasicAWSCredentials baseCredential)
{
List<AcceptableUri> acceptableUris = buildAcceptableUriForSessionCredentials(config, baseCredential);
if (!config.get("temp_credentials", Boolean.class, true)) {
return new BasicSessionCredentials(
baseCredential.getAWSAccessKeyId(),
baseCredential.getAWSSecretKey(),
null
);
}
AWSSessionCredentialsFactory sessionCredentialsFactory =
new AWSSessionCredentialsFactory(baseCredential, acceptableUris);
Optional<String> roleArn = getSecretOptionalValue(secrets, "role_arn");
if (roleArn.isPresent()) {
sessionCredentialsFactory.withRoleArn(roleArn.get());
Optional<String> roleSessionName = secrets.getSecretOptional("role_session_name");
if (roleSessionName.isPresent()) {
sessionCredentialsFactory.withRoleSessionName(roleSessionName.get());
}
}
Optional<Integer> durationSeconds = config.getOptional("session_duration", Integer.class);
if (durationSeconds.isPresent()) {
sessionCredentialsFactory.withDurationSeconds(durationSeconds.get());
}
return sessionCredentialsFactory.get();
}
示例14: run
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
@Override
protected TaskResult run(Config params, Config state, RedshiftConnectionConfig connectionConfig)
{
UUID queryId;
// generate query id
if (!state.has(QUERY_ID)) {
// this is the first execution of this task
logger.debug("Generating query id for a new {} task", type());
queryId = UUID.randomUUID();
state.set(QUERY_ID, queryId);
throw TaskExecutionException.ofNextPolling(0, ConfigElement.copyOf(state));
}
queryId = state.get(QUERY_ID, UUID.class);
BasicAWSCredentials baseCredentials = createBaseCredential(context.getSecrets());
AWSSessionCredentials sessionCredentials = createSessionCredentials(params, context.getSecrets(), baseCredentials);
T statementConfig = createStatementConfig(params, sessionCredentials, queryId.toString());
beforeConnect(baseCredentials, statementConfig);
pollingRetryExecutor(TaskState.of(state), "load")
.retryIf(LockConflictException.class, x -> true)
.withErrorMessage("Redshift Load/Unload operation failed")
.runAction(s -> executeTask(params, connectionConfig, statementConfig, queryId));
return TaskResult.defaultBuilder(request).build();
}
示例15: createUnloadConfig
import com.amazonaws.auth.AWSSessionCredentials; //导入依赖的package包/类
@VisibleForTesting
RedshiftConnection.UnloadConfig createUnloadConfig(Config config, AWSSessionCredentials sessionCredentials, String queryId)
{
RedshiftConnection.UnloadConfig uc = new RedshiftConnection.UnloadConfig();
uc.configure(
unloadConfig -> {
unloadConfig.accessKeyId = sessionCredentials.getAWSAccessKeyId();
unloadConfig.secretAccessKey = sessionCredentials.getAWSSecretKey();
if (sessionCredentials.getSessionToken() != null) {
unloadConfig.sessionToken = Optional.of(sessionCredentials.getSessionToken());
}
unloadConfig.query = config.get("query", String.class);
unloadConfig.to = config.get("to", String.class);
unloadConfig.manifest = config.getOptional("manifest", Boolean.class);
unloadConfig.encrypted = config.getOptional("encrypted", Boolean.class);
unloadConfig.allowoverwrite = config.getOptional("allowoverwrite", Boolean.class);
unloadConfig.delimiter = config.getOptional("delimiter", String.class);
unloadConfig.fixedwidth = config.getOptional("fixedwidth", String.class);
unloadConfig.gzip = config.getOptional("gzip", Boolean.class);
unloadConfig.bzip2 = config.getOptional("bzip2", Boolean.class);
unloadConfig.nullAs = config.getOptional("null_as", String.class);
unloadConfig.escape = config.getOptional("escape", Boolean.class);
unloadConfig.addquotes = config.getOptional("addquotes", Boolean.class);
unloadConfig.parallel = config.getOptional("parallel", String.class);
unloadConfig.setupWithPrefixDir(queryId);
}
);
return uc;
}