diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationService.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationService.java index a512e2d72347a..20d9697c71dc0 100644 --- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationService.java +++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationService.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import javax.naming.AuthenticationException; import javax.servlet.http.HttpServletRequest; @@ -171,20 +172,26 @@ public String authenticateHttpRequest(HttpServletRequest request, Authentication authData = authenticationState.getAuthDataSource(); } // Backward compatible, the authData value was null in the previous implementation - return providerToUse.authenticate(authData); + return providerToUse.authenticateAsync(authData).get(); } catch (AuthenticationException e) { if (LOG.isDebugEnabled()) { LOG.debug("Authentication failed for provider " + providerToUse.getAuthMethodName() + " : " + e.getMessage(), e); } throw e; + } catch (ExecutionException | InterruptedException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Authentication failed for provider " + providerToUse.getAuthMethodName() + " : " + + e.getMessage(), e); + } + throw new RuntimeException(e); } } else { for (AuthenticationProvider provider : providers.values()) { try { AuthenticationState authenticationState = provider.newHttpAuthState(request); - return provider.authenticate(authenticationState.getAuthDataSource()); - } catch (AuthenticationException e) { + return provider.authenticateAsync(authenticationState.getAuthDataSource()).get(); + } catch (ExecutionException | InterruptedException | AuthenticationException e) { if (LOG.isDebugEnabled()) { LOG.debug("Authentication failed for provider " + provider.getAuthMethodName() + ": " + e.getMessage(), e);