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][broker] Fix authenticate order in AuthenticationProviderList #23111

Merged
merged 1 commit into from
Aug 5, 2024
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 @@ -120,7 +120,8 @@ public CompletableFuture<AuthData> authenticateAsync(AuthData authData) {
if (log.isDebugEnabled()) {
log.debug("Authentication failed for auth provider " + authState.getClass() + ": ", ex);
}
authenticateRemainingAuthStates(authChallengeFuture, authData, ex, states.size() - 1);
authenticateRemainingAuthStates(authChallengeFuture, authData, ex,
states.isEmpty() ? -1 : 0);
}
});
return authChallengeFuture;
Expand All @@ -130,7 +131,7 @@ private void authenticateRemainingAuthStates(CompletableFuture<AuthData> authCha
AuthData clientAuthData,
Throwable previousException,
int index) {
if (index < 0) {
if (index < 0 || index >= states.size()) {
if (previousException == null) {
previousException = new AuthenticationException("Authentication required");
}
Expand All @@ -142,7 +143,7 @@ private void authenticateRemainingAuthStates(CompletableFuture<AuthData> authCha
AuthenticationState state = states.get(index);
if (state == authState) {
// Skip the current auth state
authenticateRemainingAuthStates(authChallengeFuture, clientAuthData, null, index - 1);
authenticateRemainingAuthStates(authChallengeFuture, clientAuthData, null, index + 1);
} else {
state.authenticateAsync(clientAuthData)
.whenComplete((authChallenge, ex) -> {
Expand All @@ -155,7 +156,7 @@ private void authenticateRemainingAuthStates(CompletableFuture<AuthData> authCha
log.debug("Authentication failed for auth provider "
+ authState.getClass() + ": ", ex);
}
authenticateRemainingAuthStates(authChallengeFuture, clientAuthData, ex, index - 1);
authenticateRemainingAuthStates(authChallengeFuture, clientAuthData, ex, index + 1);
}
});
}
Expand Down Expand Up @@ -228,15 +229,15 @@ public String getAuthMethodName() {
@Override
public CompletableFuture<String> authenticateAsync(AuthenticationDataSource authData) {
CompletableFuture<String> roleFuture = new CompletableFuture<>();
authenticateRemainingAuthProviders(roleFuture, authData, null, providers.size() - 1);
authenticateRemainingAuthProviders(roleFuture, authData, null, providers.isEmpty() ? -1 : 0);
return roleFuture;
}

private void authenticateRemainingAuthProviders(CompletableFuture<String> roleFuture,
AuthenticationDataSource authData,
Throwable previousException,
int index) {
if (index < 0) {
if (index < 0 || index >= providers.size()) {
if (previousException == null) {
previousException = new AuthenticationException("Authentication required");
}
Expand All @@ -254,7 +255,7 @@ private void authenticateRemainingAuthProviders(CompletableFuture<String> roleFu
if (log.isDebugEnabled()) {
log.debug("Authentication failed for auth provider " + provider.getClass() + ": ", ex);
}
authenticateRemainingAuthProviders(roleFuture, authData, ex, index - 1);
authenticateRemainingAuthProviders(roleFuture, authData, ex, index + 1);
}
});
}
Expand Down
Loading