@@ -102,13 +102,11 @@ public String getCallerIdentity(final Credentials credentials) throws Background
102102 }
103103 }
104104
105- public TemporaryAccessTokens getSessionToken (final Credentials credentials ) throws BackgroundException {
105+ public TemporaryAccessTokens getSessionToken (final Credentials credentials , final String mfaArn ) throws BackgroundException {
106106 log .debug ("Get session token with credentials {} for {}" , credentials , bookmark );
107- final PreferencesReader settings = new ProxyPreferencesReader (credentials , bookmark );
108107 // The purpose of the sts:GetSessionToken operation is to authenticate the user using MFA.
109108 final GetSessionTokenRequest request = new GetSessionTokenRequest ()
110109 .withRequestCredentialsProvider (S3CredentialsStrategy .toCredentialsProvider (credentials ));
111- final String mfaArn = settings .getProperty (Profile .STS_MFA_ARN_PROPERTY_KEY );
112110 if (StringUtils .isNotBlank (mfaArn )) {
113111 log .debug ("Found MFA ARN {} for {}" , mfaArn , bookmark );
114112 request .setSerialNumber (mfaArn );
@@ -173,9 +171,9 @@ public TemporaryAccessTokens getSessionToken(final Credentials credentials) thro
173171 * @see Profile#STS_ROLE_ARN_PROPERTY_KEY
174172 * @see Profile#STS_MFA_ARN_PROPERTY_KEY
175173 */
176- public TemporaryAccessTokens assumeRole (final Credentials credentials ) throws BackgroundException {
174+ public TemporaryAccessTokens assumeRole (final Credentials credentials , final String roleArn ) throws BackgroundException {
177175 log .debug ("Assume role with credentials {} for {}" , credentials , bookmark );
178- final PreferencesReader settings = new ProxyPreferencesReader (credentials , bookmark );
176+ final PreferencesReader settings = new ProxyPreferencesReader (bookmark , credentials );
179177 final AssumeRoleRequest request = new AssumeRoleRequest ()
180178 .withRequestCredentialsProvider (S3CredentialsStrategy .toCredentialsProvider (credentials ));
181179 if (StringUtils .isNotBlank (settings .getProperty ("s3.assumerole.durationseconds" , Profile .STS_DURATION_SECONDS_PROPERTY_KEY ))) {
@@ -184,7 +182,6 @@ public TemporaryAccessTokens assumeRole(final Credentials credentials) throws Ba
184182 request .setTags (settings .getMap (Profile .STS_TAGS_PROPERTY_KEY ).entrySet ().stream ().map (
185183 entry -> new Tag ().withKey (entry .getKey ()).withValue (entry .getValue ())).collect (Collectors .toList ())
186184 );
187- final String roleArn = settings .getProperty (Profile .STS_ROLE_ARN_PROPERTY_KEY , "s3.assumerole.rolearn" );
188185 if (StringUtils .isNotBlank (roleArn )) {
189186 log .debug ("Found Role ARN {} for {}" , roleArn , bookmark );
190187 request .setRoleArn (roleArn );
@@ -264,15 +261,15 @@ public TemporaryAccessTokens assumeRole(final Credentials credentials) throws Ba
264261 }
265262 }
266263
267- public TemporaryAccessTokens assumeRoleWithSAML (final Credentials credentials ) throws BackgroundException {
268- log .debug ("Assume role with SAML with credentials {} for {}" , credentials , bookmark );
269- final PreferencesReader settings = new ProxyPreferencesReader (credentials , bookmark );
270- final AssumeRoleWithSAMLRequest request = new AssumeRoleWithSAMLRequest ().withSAMLAssertion (credentials .getToken ());
264+ public TemporaryAccessTokens assumeRoleWithSAML (final String samlAssertion , final String roleArn ) throws BackgroundException {
265+ log .debug ("Assume role with SAML with assertion {} for {}" , samlAssertion , bookmark );
266+ final PreferencesReader settings = HostPreferencesFactory .get (bookmark );
267+ final AssumeRoleWithSAMLRequest request = new AssumeRoleWithSAMLRequest ().withSAMLAssertion (samlAssertion )
268+ .withRequestCredentialsProvider (new AWSStaticCredentialsProvider (new AnonymousAWSCredentials ()));
271269 if (StringUtils .isNotBlank (settings .getProperty ("s3.assumerole.durationseconds" , Profile .STS_DURATION_SECONDS_PROPERTY_KEY ))) {
272270 request .setDurationSeconds (PreferencesReader .toInteger (settings .getProperty ("s3.assumerole.durationseconds" , Profile .STS_DURATION_SECONDS_PROPERTY_KEY )));
273271 }
274272 request .setPolicy (settings .getProperty ("s3.assumerole.policy" ));
275- final String roleArn = settings .getProperty (Profile .STS_ROLE_ARN_PROPERTY_KEY , "s3.assumerole.rolearn" );
276273 if (StringUtils .isNotBlank (roleArn )) {
277274 log .debug ("Found Role ARN {} for {}" , roleArn , bookmark );
278275 request .setRoleArn (roleArn );
@@ -293,21 +290,21 @@ public TemporaryAccessTokens assumeRoleWithSAML(final Credentials credentials) t
293290 /**
294291 * Assume role with web identity token
295292 *
296- * @param credentials OIDC tokens
293+ * @param oauth OIDC tokens
297294 * @return Temporary access tokens for the assumed role
298295 */
299- public TemporaryAccessTokens assumeRoleWithWebIdentity (final Credentials credentials ) throws BackgroundException {
300- log .debug ("Assume role with web identity with credentials {} for {}" , credentials , bookmark );
301- final PreferencesReader settings = new ProxyPreferencesReader (credentials , bookmark );
302- final AssumeRoleWithWebIdentityRequest request = new AssumeRoleWithWebIdentityRequest ();
296+ public TemporaryAccessTokens assumeRoleWithWebIdentity (final OAuthTokens oauth , final String roleArn ) throws BackgroundException {
297+ log .debug ("Assume role with web identity {} for {}" , oauth , bookmark );
298+ final PreferencesReader settings = HostPreferencesFactory .get (bookmark );
299+ final AssumeRoleWithWebIdentityRequest request = new AssumeRoleWithWebIdentityRequest ()
300+ .withRequestCredentialsProvider (new AWSStaticCredentialsProvider (new AnonymousAWSCredentials ()));
303301 log .debug ("Assume role with OIDC Id token for {}" , bookmark );
304- final String webIdentityToken = this .getWebIdentityToken (credentials . getOauth () );
302+ final String webIdentityToken = this .getWebIdentityToken (oauth );
305303 request .setWebIdentityToken (webIdentityToken );
306304 if (StringUtils .isNotBlank (settings .getProperty ("s3.assumerole.durationseconds" , Profile .STS_DURATION_SECONDS_PROPERTY_KEY ))) {
307305 request .setDurationSeconds (PreferencesReader .toInteger (settings .getProperty ("s3.assumerole.durationseconds" , Profile .STS_DURATION_SECONDS_PROPERTY_KEY )));
308306 }
309307 request .setPolicy (settings .getProperty ("s3.assumerole.policy" ));
310- final String roleArn = settings .getProperty (Profile .STS_ROLE_ARN_PROPERTY_KEY , "s3.assumerole.rolearn" );
311308 if (StringUtils .isNotBlank (roleArn )) {
312309 request .setRoleArn (roleArn );
313310 }
0 commit comments