本文整理汇总了Java中com.amazonaws.auth.BasicSessionCredentials类的典型用法代码示例。如果您正苦于以下问题:Java BasicSessionCredentials类的具体用法?Java BasicSessionCredentials怎么用?Java BasicSessionCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicSessionCredentials类属于com.amazonaws.auth包,在下文中一共展示了BasicSessionCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCredentials
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
@Override
public AWSCredentials getCredentials() {
AWSCredentialsProvider credentialsProvider = AWSClientFactory.getBasicCredentialsOrDefaultChain(accessKey, secretKey);
AWSCredentials initialCredentials = credentialsProvider.getCredentials();
if (iamRoleArn.isEmpty()) {
return initialCredentials;
} else {
AssumeRoleRequest assumeRequest = new AssumeRoleRequest()
.withRoleArn(iamRoleArn)
.withExternalId(externalId)
.withDurationSeconds(3600)
.withRoleSessionName("CodeBuild-Jenkins-Plugin");
AssumeRoleResult assumeResult = new AWSSecurityTokenServiceClient(initialCredentials).assumeRole(assumeRequest);
return new BasicSessionCredentials(
assumeResult.getCredentials().getAccessKeyId(),
assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
}
}
示例2: setupTest
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
/**
* Do any initialization required by this client. In this case,
* initialization consists of getting the value of the AWS region
* and credentials parameters.
*
* @param context
* the context to run with. This provides access to
* initialization parameters.
*/
@Override
public void setupTest(JavaSamplerContext context) {
apigatewayBaseUrl = context.getParameter("APIGATEWAY_BASE_URL");
accessKeyId = context.getParameter("ACCESS_KEY_ID");
secretKey = context.getParameter("SECRET_KEY");
sessionToken = context.getParameter("SESSION_TOKEN");
AWSCredentials awsCredentials = new BasicSessionCredentials(accessKeyId, secretKey,
sessionToken);
AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
awsCredentials);
String region = context.getParameter("REGION");
client = Squash.builder().iamRegion(region)
.iamCredentials((AWSCredentialsProvider) awsStaticCredentialsProvider).build();
samplerName = context.getParameter(TestElement.NAME);
bookingName = context.getParameter("BOOKING_NAME");
court = context.getParameter("COURT");
courtSpan = context.getParameter("COURTSPAN");
slot = context.getParameter("SLOT");
slotSpan = context.getParameter("SLOTSPAN");
date = context.getParameter("DATE");
putOrDelete = context.getParameter("PUT_OR_DELETE");
}
示例3: getS3Client
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
public static AmazonS3 getS3Client(final String region, final String roleArn) {
final Regions awsRegion = StringUtils.isNullOrEmpty(region) ? Regions.US_EAST_1 : Regions.fromName(region);
if (StringUtils.isNullOrEmpty(roleArn)) {
return AmazonS3ClientBuilder.standard().withRegion(awsRegion).build();
} else {
final AssumeRoleRequest assumeRole = new AssumeRoleRequest().withRoleArn(roleArn).withRoleSessionName("io-klerch-mp3-converter");
final AWSSecurityTokenService sts = AWSSecurityTokenServiceClientBuilder.standard().withRegion(awsRegion).build();
final Credentials credentials = sts.assumeRole(assumeRole).getCredentials();
final BasicSessionCredentials sessionCredentials = new BasicSessionCredentials(
credentials.getAccessKeyId(),
credentials.getSecretAccessKey(),
credentials.getSessionToken());
return AmazonS3ClientBuilder.standard().withRegion(awsRegion).withCredentials(new AWSStaticCredentialsProvider(sessionCredentials)).build();
}
}
示例4: getInstanceClient
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
AWSSecurityTokenServiceClient getInstanceClient(AWSAttestationData info) {
String access = info.getAccess();
if (access == null || access.isEmpty()) {
LOGGER.error("getInstanceClient: No access key id available in instance document");
return null;
}
String secret = info.getSecret();
if (secret == null || secret.isEmpty()) {
LOGGER.error("getInstanceClient: No secret access key available in instance document");
return null;
}
String token = info.getToken();
if (token == null || token.isEmpty()) {
LOGGER.error("getInstanceClient: No token available in instance document");
return null;
}
BasicSessionCredentials creds = new BasicSessionCredentials(access, secret, token);
return new AWSSecurityTokenServiceClient(creds);
}
示例5: get
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
@Override
public Credentials get() {
if (getIdentity() == null || getIdentity().trim().isEmpty() || getCredential() == null || getCredential().trim().isEmpty()) {
DefaultAWSCredentialsProviderChain chain = new DefaultAWSCredentialsProviderChain();
AWSCredentials cred = chain.getCredentials();
if (cred instanceof BasicSessionCredentials) {
BasicSessionCredentials sesCred = (BasicSessionCredentials)cred;
return new SessionCredentials.Builder()
.identity(sesCred.getAWSAccessKeyId())
.credential(sesCred.getAWSSecretKey())
.sessionToken(sesCred.getSessionToken())
.build();
} else {
return new Credentials.Builder<>()
.identity(cred.getAWSAccessKeyId())
.credential(cred.getAWSSecretKey())
.build();
}
}
return super.get();
}
示例6: load
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
public Optional<BasicSessionCredentials> load() {
if (!file.exists()) {
return Optional.empty();
}
try {
SessionCacheSchema cache = objectMapper.readValue(file, SessionCacheSchema.class);
if (ZonedDateTime.now().plusSeconds(EXPIRATION_THRESHOLD_IN_SECONDS).isBefore(cache.credentials.getExpiration())) {
return Optional.of(new BasicSessionCredentials(cache.credentials.accessKeyId, cache.credentials.secretAccessKey, cache.credentials.sessionToken));
} else {
return Optional.empty();
}
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to load session cache from '%s'", file.getAbsolutePath()), e);
}
}
示例7: getEc2Client
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
/**
* Creates a client for accessing Amazon EC2 service.
*
* @param awsParamsDto the AWS related parameters DTO that includes optional AWS credentials and proxy information
*
* @return the Amazon EC2 client
*/
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public AmazonEC2Client getEc2Client(AwsParamsDto awsParamsDto)
{
// Get client configuration.
ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto);
// If specified, use the AWS credentials passed in.
if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId()))
{
return new AmazonEC2Client(
new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(), awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken()),
clientConfiguration);
}
// Otherwise, use the default AWS credentials provider chain.
else
{
return new AmazonEC2Client(clientConfiguration);
}
}
示例8: getEmrClient
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
/**
* Creates a client for accessing Amazon EMR service.
*
* @param awsParamsDto the AWS related parameters DTO that includes optional AWS credentials and proxy information
*
* @return the Amazon EMR client
*/
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public AmazonElasticMapReduceClient getEmrClient(AwsParamsDto awsParamsDto)
{
// Get client configuration.
ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto);
// If specified, use the AWS credentials passed in.
if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId()))
{
return new AmazonElasticMapReduceClient(
new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(), awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken()),
clientConfiguration);
}
// Otherwise, use the default AWS credentials provider chain.
else
{
return new AmazonElasticMapReduceClient(clientConfiguration);
}
}
示例9: sessionToken
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
@Test
public void sessionToken() {
S3ClientProvider provider = new S3ClientProvider();
S3Configuration s3Configuration = new S3Configuration("fakeProvidedKeyId",
"fakeProvidedSecretKey",
false,
"fakeProvidedSessionToken",
null,
5,
"s3-transfer-manager-worker-",
100);
ReflectionTestUtils.setField(provider, "s3Configuration", s3Configuration);
BasicSessionCredentials credentials = (BasicSessionCredentials) provider.getAwsCredentials();
assertEquals("fakeProvidedKeyId", credentials.getAWSAccessKeyId());
assertEquals("fakeProvidedSecretKey", credentials.getAWSSecretKey());
assertEquals("fakeProvidedSessionToken", credentials.getSessionToken());
}
示例10: getClientForAccount
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
private AmazonEC2Client getClientForAccount(final String accountId, final Region region) {
final AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider());
final AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(
"arn:aws:iam::ACCOUNT_ID:role/fullstop-role")
.withDurationSeconds(3600).withRoleSessionName(
"fullstop-role");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
final BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
assumeResult.getCredentials()
.getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
final AmazonEC2Client amazonEC2Client = new AmazonEC2Client(temporaryCredentials);
amazonEC2Client.setRegion(region);
return amazonEC2Client;
}
示例11: getCredentials
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
public AWSCredentials getCredentials() {
AWSCredentials initialCredentials = new BasicAWSCredentials(accessKey, secretKey.getPlainText());
if (StringUtils.isBlank(iamRoleArn)) {
return initialCredentials;
} else {
// Handle the case of delegation to instance profile
if (StringUtils.isBlank(accessKey) && StringUtils.isBlank(secretKey.getPlainText()) ) {
initialCredentials = (new InstanceProfileCredentialsProvider()).getCredentials();
}
AssumeRoleRequest assumeRequest = createAssumeRoleRequest(iamRoleArn);
AssumeRoleResult assumeResult = new AWSSecurityTokenServiceClient(initialCredentials).assumeRole(assumeRequest);
return new BasicSessionCredentials(
assumeResult.getCredentials().getAccessKeyId(),
assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
}
}
示例12: provideCredentials
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
public synchronized void provideCredentials(@NonNull String bucket,
@NonNull String bucketPath,
@NonNull String awsKey,
@NonNull String awsSecret,
@NonNull String awsSessionToken) {
if (hasCredentials()) {
Timber.w("Credentials already provided");
return;
}
Timber.d("Credentials provided");
this.bucket = bucket;
this.bucketPath = bucketPath;
this.credentials = new BasicSessionCredentials(awsKey, awsSecret, awsSessionToken);
this.s3 = new AmazonS3Client(credentials);
this.transferUtility = new TransferUtility(s3, context);
executeQueuedUploads();
}
示例13: loginWithAssumeRoleWithWebIdentity
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
@Override
public WifResponseDTO loginWithAssumeRoleWithWebIdentity(String token, IdentityProviderEnum identityProvider)
{
/*
* The token returned by GetOpenIdToken can be passed to the STS operation
* AssumeRoleWithWebIdentity to retrieve AWS credentials.
*
* The ProviderId parameter for an STS call with a Cognito OpenID token is
* cognito-identity.amazonaws.com.
*/
final AssumeRoleWithWebIdentityRequest request = new AssumeRoleWithWebIdentityRequest()
.withWebIdentityToken(token)
.withProviderId(identityProvider.getValueAsString())
.withRoleArn(ROLE_ARN)
.withRoleSessionName("wifSession")
.withDurationSeconds(300);
final AssumeRoleWithWebIdentityResult result = awsSecurityTokenServiceClient.assumeRoleWithWebIdentity(request);
final Credentials stsCredentials = result.getCredentials();
final BasicSessionCredentials credentials = new BasicSessionCredentials(stsCredentials.getAccessKeyId(),
stsCredentials.getSecretAccessKey(),
stsCredentials.getSessionToken());
return new WifResponseDTO(result.getSubjectFromWebIdentityToken(), new AmazonS3Client(credentials));
}
示例14: onGotStreamResponse
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
private void onGotStreamResponse(HlsStream stream) {
mStream = stream;
if (mConfig.shouldAttachLocation()) {
Kickflip.addLocationToStream(mContext, mStream, mEventBus);
}
mStream.setTitle(mConfig.getTitle());
mStream.setDescription(mConfig.getDescription());
mStream.setExtraInfo(mConfig.getExtraInfo());
mStream.setIsPrivate(mConfig.isPrivate());
if (VERBOSE) Log.i(TAG, "Got hls start stream " + stream);
mS3Manager = new S3BroadcastManager(this,
new BasicSessionCredentials(mStream.getAwsKey(), mStream.getAwsSecret(), mStream.getToken()));
mS3Manager.setRegion(mStream.getRegion());
mS3Manager.addRequestInterceptor(mS3RequestInterceptor);
mReadyToBroadcast = true;
submitQueuedUploadsToS3();
mEventBus.post(new BroadcastIsBufferingEvent());
if (mBroadcastListener != null) {
mBroadcastListener.onBroadcastStart();
}
}
示例15: create
import com.amazonaws.auth.BasicSessionCredentials; //导入依赖的package包/类
private void create()
{
AssumeRoleResult result =
sts.assumeRole( new AssumeRoleRequest().withRoleArn( assumedRoleArn ).withExternalId( AgentConfig.ROLE_EXTERNAL_ID ).withRoleSessionName( "rs-"
+ RandomStringUtils.randomAlphabetic( 8 ) ) );
synchronized ( this )
{
expirationDate =
result.getCredentials().getExpiration().getTime();
creds =
new BasicSessionCredentials(
result.getCredentials().getAccessKeyId(),
result.getCredentials().getSecretAccessKey(),
result.getCredentials().getSessionToken() );
}
}