|
41 | 41 | import org.apache.logging.log4j.LogManager;
|
42 | 42 | import org.apache.logging.log4j.Logger;
|
43 | 43 |
|
| 44 | +import java.util.stream.Collectors; |
| 45 | + |
44 | 46 | import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
45 | 47 | import com.amazonaws.auth.AnonymousAWSCredentials;
|
46 | 48 | import com.amazonaws.client.builder.AwsClientBuilder;
|
|
57 | 59 | import com.amazonaws.services.securitytoken.model.GetCallerIdentityResult;
|
58 | 60 | import com.amazonaws.services.securitytoken.model.GetSessionTokenRequest;
|
59 | 61 | import com.amazonaws.services.securitytoken.model.GetSessionTokenResult;
|
| 62 | +import com.amazonaws.services.securitytoken.model.Tag; |
60 | 63 | import com.auth0.jwt.JWT;
|
61 | 64 | import com.auth0.jwt.exceptions.JWTDecodeException;
|
62 | 65 |
|
@@ -100,7 +103,7 @@ public String validate(final Credentials credentials) throws BackgroundException
|
100 | 103 | }
|
101 | 104 |
|
102 | 105 | public TemporaryAccessTokens getSessionToken(final Credentials credentials) throws BackgroundException {
|
103 |
| - final PreferencesReader settings = new ProxyPreferencesReader(bookmark, credentials); |
| 106 | + final PreferencesReader settings = new ProxyPreferencesReader(credentials, bookmark); |
104 | 107 | // The purpose of the sts:GetSessionToken operation is to authenticate the user using MFA.
|
105 | 108 | final GetSessionTokenRequest request = new GetSessionTokenRequest()
|
106 | 109 | .withRequestCredentialsProvider(S3CredentialsStrategy.toCredentialsProvider(credentials));
|
@@ -170,12 +173,15 @@ public TemporaryAccessTokens getSessionToken(final Credentials credentials) thro
|
170 | 173 | * @see Profile#STS_MFA_ARN_PROPERTY_KEY
|
171 | 174 | */
|
172 | 175 | public TemporaryAccessTokens assumeRole(final Credentials credentials) throws BackgroundException {
|
173 |
| - final PreferencesReader settings = new ProxyPreferencesReader(bookmark, credentials); |
| 176 | + final PreferencesReader settings = new ProxyPreferencesReader(credentials, bookmark); |
174 | 177 | final AssumeRoleRequest request = new AssumeRoleRequest()
|
175 | 178 | .withRequestCredentialsProvider(S3CredentialsStrategy.toCredentialsProvider(credentials));
|
176 | 179 | if(StringUtils.isNotBlank(settings.getProperty("s3.assumerole.durationseconds", Profile.STS_DURATION_SECONDS_PROPERTY_KEY))) {
|
177 | 180 | request.setDurationSeconds(PreferencesReader.toInteger(settings.getProperty("s3.assumerole.durationseconds", Profile.STS_DURATION_SECONDS_PROPERTY_KEY)));
|
178 | 181 | }
|
| 182 | + request.setTags(settings.getMap(Profile.STS_TAGS_PROPERTY_KEY).entrySet().stream().map( |
| 183 | + entry -> new Tag().withKey(entry.getKey()).withValue(entry.getValue())).collect(Collectors.toList()) |
| 184 | + ); |
179 | 185 | final String roleArn = settings.getProperty(Profile.STS_ROLE_ARN_PROPERTY_KEY, "s3.assumerole.rolearn");
|
180 | 186 | if(StringUtils.isNotBlank(roleArn)) {
|
181 | 187 | log.debug("Found Role ARN {} for {}", roleArn, bookmark);
|
@@ -257,7 +263,7 @@ public TemporaryAccessTokens assumeRole(final Credentials credentials) throws Ba
|
257 | 263 | }
|
258 | 264 |
|
259 | 265 | public TemporaryAccessTokens assumeRoleWithSAML(final Credentials credentials) throws BackgroundException {
|
260 |
| - final PreferencesReader settings = new ProxyPreferencesReader(bookmark, credentials); |
| 266 | + final PreferencesReader settings = new ProxyPreferencesReader(credentials, bookmark); |
261 | 267 | final AssumeRoleWithSAMLRequest request = new AssumeRoleWithSAMLRequest().withSAMLAssertion(credentials.getToken());
|
262 | 268 | if(StringUtils.isNotBlank(settings.getProperty("s3.assumerole.durationseconds", Profile.STS_DURATION_SECONDS_PROPERTY_KEY))) {
|
263 | 269 | request.setDurationSeconds(PreferencesReader.toInteger(settings.getProperty("s3.assumerole.durationseconds", Profile.STS_DURATION_SECONDS_PROPERTY_KEY)));
|
@@ -288,7 +294,7 @@ public TemporaryAccessTokens assumeRoleWithSAML(final Credentials credentials) t
|
288 | 294 | * @return Temporary access tokens for the assumed role
|
289 | 295 | */
|
290 | 296 | public TemporaryAccessTokens assumeRoleWithWebIdentity(final Credentials credentials) throws BackgroundException {
|
291 |
| - final PreferencesReader settings = new ProxyPreferencesReader(bookmark, credentials); |
| 297 | + final PreferencesReader settings = new ProxyPreferencesReader(credentials, bookmark); |
292 | 298 | final AssumeRoleWithWebIdentityRequest request = new AssumeRoleWithWebIdentityRequest();
|
293 | 299 | log.debug("Assume role with OIDC Id token for {}", bookmark);
|
294 | 300 | final String webIdentityToken = this.getWebIdentityToken(credentials.getOauth());
|
|
0 commit comments