Environment details
- OS type and version: All
- Java version: 1.8
- version(s): 1.7.0 and before
Steps to reproduce
- Set the
TZ environment variable to America/Los_Angeles (or any other timezone that is not GMT)
- Retrieve an access token with the AWS workload identity federation credentials
- Expiration time of the OAuth2 token will be incorrectly saved as 8 hours (or other value depending on the timezone set previously) from the moment it was requested instead of 1 hour, which is the actual requested lifetime.
Code example
There's an integration test for AWS workload identity federation here
External references such as API reference guides
Additional information
The cause of the issue was traced to the following constant
private static final String RFC3339 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
Since the constant defines the format to expect a literal 'Z' in the text string, it is ignoring whatever timezone definition is present in the input string returned from the STS response.
According to the javadoc for SimpleDateFormat (see), the correct value for this constant should be "yyyy-MM-dd'T'HH:mm:ssX", as shown in this jshell session (note my machine timezone is CEST):
jshell> var format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
format ==> java.text.SimpleDateFormat@fe8ba6fa
jshell> format.parse("2022-06-22T11:14:52Z")
$3 ==> Wed Jun 22 11:14:52 CEST 2022 <-------- Zulu timezone ignored, local tz is assumed
jshell> var format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX")
format ==> java.text.SimpleDateFormat@faabb35e
jshell> format.parse("2022-06-22T11:14:52Z")
$5 ==> Wed Jun 22 13:14:52 CEST 2022 <------- Zulu timezone is assumed
Will create a PR with the small change. Thanks!
Environment details
Steps to reproduce
TZenvironment variable toAmerica/Los_Angeles(or any other timezone that is not GMT)Code example
There's an integration test for AWS workload identity federation here
External references such as API reference guides
Additional information
The cause of the issue was traced to the following constant
private static final String RFC3339 = "yyyy-MM-dd'T'HH:mm:ss'Z'";Since the constant defines the format to expect a literal 'Z' in the text string, it is ignoring whatever timezone definition is present in the input string returned from the STS response.
According to the javadoc for SimpleDateFormat (see), the correct value for this constant should be
"yyyy-MM-dd'T'HH:mm:ssX", as shown in thisjshellsession (note my machine timezone is CEST):Will create a PR with the small change. Thanks!