This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
back-ported changes from Grails plugin
- Loading branch information
Showing
13 changed files
with
418 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
=== Security Token Service (STS) | ||
|
||
> The AWS Security Token Service (STS) is a web service that enables you to request temporary, limited-privilege credentials for AWS Identity and Access Management (IAM) users or for users that you authenticate (federated users). | ||
|
||
This library provides basic support for Amazon STS using <<Security Token Service>> | ||
|
||
==== Security Token Service | ||
|
||
`SecurityTokenService` provides only one method (with multiple variations) to create credentials | ||
which assumes usage of a certain IAM role. | ||
|
||
Following example shows how to create credentials for assumed role. | ||
|
||
[source,groovy,indent=0,options="nowrap",role="primary"] | ||
.Assume Role | ||
---- | ||
include::../micronaut-aws-sdk/src/test/groovy/com/agorapulse/micronaut/aws/sts/SecurityTokenServiceSpec.groovy[tag=usage] | ||
---- | ||
|
||
Please, see https://agorapulse.github.io/micronaut-libraries/docs/javadoc/micronaut-aws-sdk/com/agorapulse/micronaut/aws/sts/SecurityTokenService.html[SecurityTokenService] for the full reference. | ||
|
||
==== Testing | ||
It is recommended just to mock the `SecurityTokenService` in your tests as it only contains single abstract method. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/sts/DefaultSecurityTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.agorapulse.micronaut.aws.sts; | ||
|
||
import com.amazonaws.services.securitytoken.AWSSecurityTokenService; | ||
import com.amazonaws.services.securitytoken.model.AssumeRoleRequest; | ||
import com.amazonaws.services.securitytoken.model.AssumeRoleResult; | ||
import io.micronaut.context.annotation.Requires; | ||
|
||
import javax.inject.Singleton; | ||
import java.util.function.Consumer; | ||
|
||
@Singleton | ||
@Requires(classes = AWSSecurityTokenService.class) | ||
public class DefaultSecurityTokenService implements SecurityTokenService { | ||
|
||
private final AWSSecurityTokenService client; | ||
|
||
public DefaultSecurityTokenService(AWSSecurityTokenService client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public AssumeRoleResult assumeRole(String sessionName, String roleArn, int durationInSeconds, Consumer<AssumeRoleRequest> additionParameters) { | ||
AssumeRoleRequest request = new AssumeRoleRequest() | ||
.withRoleSessionName(sessionName) | ||
.withRoleArn(roleArn) | ||
.withDurationSeconds(durationInSeconds); | ||
|
||
additionParameters.accept(request); | ||
|
||
return client.assumeRole(request); | ||
} | ||
} |
Oops, something went wrong.