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

Fixed Azure Active Directory user name cache matching to be case insensitive #1923

Merged
merged 2 commits into from
Jan 24, 2023
Merged
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 @@ -168,6 +168,16 @@ static SqlFedAuthToken getSqlFedAuthTokenInteractive(SqlFedAuthInfo fedAuthInfo,
// try to acquire token silently if user account found in cache
try {
Set<IAccount> 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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -221,7 +234,7 @@ static SqlFedAuthToken getSqlFedAuthTokenInteractive(SqlFedAuthInfo fedAuthInfo,
private static IAccount getAccountByUsername(Set<IAccount> accounts, String username) {
if (!accounts.isEmpty()) {
for (IAccount account : accounts) {
if (account.username().equals(username)) {
if (account.username().equalsIgnoreCase(username)) {
return account;
}
}
Expand Down