#18252 - [REQ] add sessionToken support to AWS4Auth (#18253)

This commit is contained in:
Mike Friesen 2024-04-10 22:56:40 -05:00 committed by GitHub
parent 44ae981830
commit 97c1dc8a1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 197 additions and 0 deletions

View File

@ -652,6 +652,29 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
{{#withAWSV4Signature}}
for (Authentication auth : authentications.values()) {
if (auth instanceof AWS4Auth) {
((AWS4Auth) auth).setCredentials(accessKey, secretKey, sessionToken);
((AWS4Auth) auth).setRegion(region);
((AWS4Auth) auth).setService(service);
return;
}
}
{{/withAWSV4Signature}}
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -16,6 +16,7 @@ import java.util.stream.Collectors;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.signer.Aws4Signer;
import software.amazon.awssdk.auth.signer.params.Aws4SignerParams;
@ -41,6 +42,10 @@ public class AWS4Auth implements Authentication {
this.credentials = AwsBasicCredentials.create(accessKey, secretKey);
}
public void setCredentials(String accessKey, String secretKey, String sessionToken) {
this.credentials = AwsSessionCredentials.create(accessKey, secretKey, sessionToken);
}
public void setRegion(String region) {
this.region = region;
}

View File

@ -491,6 +491,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -465,6 +465,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -465,6 +465,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -547,6 +547,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -559,6 +559,27 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
for (Authentication auth : authentications.values()) {
if (auth instanceof AWS4Auth) {
((AWS4Auth) auth).setCredentials(accessKey, secretKey, sessionToken);
((AWS4Auth) auth).setRegion(region);
((AWS4Auth) auth).setService(service);
return;
}
}
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -27,6 +27,7 @@ import java.util.stream.Collectors;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.signer.Aws4Signer;
import software.amazon.awssdk.auth.signer.params.Aws4SignerParams;
@ -52,6 +53,10 @@ public class AWS4Auth implements Authentication {
this.credentials = AwsBasicCredentials.create(accessKey, secretKey);
}
public void setCredentials(String accessKey, String secretKey, String sessionToken) {
this.credentials = AwsSessionCredentials.create(accessKey, secretKey, sessionToken);
}
public void setRegion(String region) {
this.region = region;
}

View File

@ -564,6 +564,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -547,6 +547,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -550,6 +550,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -553,6 +553,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -547,6 +547,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -547,6 +547,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*

View File

@ -621,6 +621,19 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
throw new RuntimeException("No AWS4 authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*