Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SqlAuthenticationToken constructor accepting unix epoch #2425

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ static SqlAuthenticationToken getManagedIdentityCredAuthToken(String resource,
} else {
AccessToken accessToken = accessTokenOptional.get();
sqlFedAuthToken = new SqlAuthenticationToken(accessToken.getToken(),
accessToken.getExpiresAt().toEpochSecond());
accessToken.getExpiresAt().toInstant().toEpochMilli());
}

if (logger.isLoggable(java.util.logging.Level.FINEST)) {
Expand Down Expand Up @@ -471,7 +471,7 @@ static SqlAuthenticationToken getDefaultAzureCredAuthToken(String resource,
} else {
AccessToken accessToken = accessTokenOptional.get();
sqlFedAuthToken = new SqlAuthenticationToken(accessToken.getToken(),
accessToken.getExpiresAt().toEpochSecond());
accessToken.getExpiresAt().toInstant().toEpochMilli());
}

return sqlFedAuthToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public class SqlAuthenticationToken implements Serializable {
private final String accessToken;

/**
* Contructs a SqlAuthentication token.
* Constructs a SqlAuthentication token.
*
* @param accessToken
* The access token string.
* @param expiresOn
* The expiration date in seconds since the unix epoch.
* The expiration date in milliseconds since the unix epoch.
*/
public SqlAuthenticationToken(String accessToken, long expiresOn) {
this.accessToken = accessToken;
this.expiresOn = new Date(expiresOn);
}

/**
* Contructs a SqlAuthentication token.
* Constructs a SqlAuthentication token.
*
* @param accessToken
* The access token string.
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public SqlAuthenticationToken getAccessToken(String spn, String stsurl) {

if (expireTokenToggle) {
Date now = new Date();
long minutesToExpireWithin = TEST_TOKEN_EXPIRY_SECONDS * 1000; // Expire within 2 minutes
return new SqlAuthenticationToken(accessToken, now.getTime() + minutesToExpireWithin);
long millisecondsToExpireWithin = TEST_TOKEN_EXPIRY_SECONDS * 1000; // Expire within 2 minutes
return new SqlAuthenticationToken(accessToken, now.getTime() + millisecondsToExpireWithin);
} else {
return new SqlAuthenticationToken(accessToken, expiresOn);
}
Expand Down
Loading