Skip to content

Commit

Permalink
Added fine logging for access token expiry (#1875)
Browse files Browse the repository at this point in the history
* Added fine logging for access token expiry

* Changed logging to finest
  • Loading branch information
tkyc committed Aug 9, 2022
1 parent eb88b70 commit 8bb2395
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo, String use
.build());

final IAuthenticationResult authenticationResult = future.get();

if (logger.isLoggable(Level.FINEST)) {
logger.finest(logger.toString() + "Access token expires on the following date: " + authenticationResult.expiresOnDate());
}

return new SqlFedAuthToken(authenticationResult.accessToken(), authenticationResult.expiresOnDate());
} catch (MalformedURLException | InterruptedException e) {
// re-interrupt thread
Expand Down Expand Up @@ -87,6 +92,11 @@ static SqlFedAuthToken getSqlFedAuthTokenPrincipal(SqlFedAuthInfo fedAuthInfo, S
final CompletableFuture<IAuthenticationResult> future = clientApplication
.acquireToken(ClientCredentialParameters.builder(scopes).build());
final IAuthenticationResult authenticationResult = future.get();

if (logger.isLoggable(Level.FINEST)) {
logger.finest(logger.toString() + "Access token expires on the following date: " + authenticationResult.expiresOnDate());
}

return new SqlFedAuthToken(authenticationResult.accessToken(), authenticationResult.expiresOnDate());
} catch (MalformedURLException | InterruptedException e) {
// re-interrupt thread
Expand Down Expand Up @@ -124,6 +134,11 @@ static SqlFedAuthToken getSqlFedAuthTokenIntegrated(SqlFedAuthInfo fedAuthInfo,
.builder(Collections.singleton(fedAuthInfo.spn + SLASH_DEFAULT), user).build());

final IAuthenticationResult authenticationResult = future.get();

if (logger.isLoggable(Level.FINEST)) {
logger.finest(logger.toString() + "Access token expires on the following date: " + authenticationResult.expiresOnDate());
}

return new SqlFedAuthToken(authenticationResult.accessToken(), authenticationResult.expiresOnDate());
} catch (InterruptedException | IOException e) {
// re-interrupt thread
Expand Down Expand Up @@ -185,6 +200,10 @@ static SqlFedAuthToken getSqlFedAuthTokenInteractive(SqlFedAuthInfo fedAuthInfo,
authenticationResult = future.get();
}

if (logger.isLoggable(Level.FINEST)) {
logger.finest(logger.toString() + "Access token expires on the following date: " + authenticationResult.expiresOnDate());
}

return new SqlFedAuthToken(authenticationResult.accessToken(), authenticationResult.expiresOnDate());
} catch (MalformedURLException | InterruptedException | URISyntaxException e) {
// re-interrupt thread
Expand Down

0 comments on commit 8bb2395

Please sign in to comment.