diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMSAL4JUtils.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMSAL4JUtils.java index 153166859..553862e6a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMSAL4JUtils.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMSAL4JUtils.java @@ -168,6 +168,16 @@ static SqlFedAuthToken getSqlFedAuthTokenInteractive(SqlFedAuthInfo fedAuthInfo, // try to acquire token silently if user account found in cache try { Set accountsInCache = pca.getAccounts().join(); + if (logger.isLoggable(Level.FINE)) { + StringBuilder acc = new StringBuilder(); + if (accountsInCache != null) { + for (IAccount account : accountsInCache) { + if (acc.length() != 0) acc.append(", "); + acc.append(account.username()); + } + } + logger.fine(logger.toString() + "Accounts in cache = " + acc + ", size = " + (accountsInCache == null ? null : accountsInCache.size()) + ", user = " + user); + } if (null != accountsInCache && !accountsInCache.isEmpty() && null != user && !user.isEmpty()) { IAccount account = getAccountByUsername(accountsInCache, user); if (null != account) { @@ -182,6 +192,9 @@ static SqlFedAuthToken getSqlFedAuthTokenInteractive(SqlFedAuthInfo fedAuthInfo, } } catch (MsalInteractionRequiredException e) { // not an error, need to get token interactively + if (logger.isLoggable(Level.FINE)) { + logger.log(Level.FINE, e, () -> logger.toString() + "Need to get token interactively"); + } } if (null != future) { @@ -221,7 +234,7 @@ static SqlFedAuthToken getSqlFedAuthTokenInteractive(SqlFedAuthInfo fedAuthInfo, private static IAccount getAccountByUsername(Set accounts, String username) { if (!accounts.isEmpty()) { for (IAccount account : accounts) { - if (account.username().equals(username)) { + if (account.username().equalsIgnoreCase(username)) { return account; } }