diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java index 1d0d64ec3b0b8..1ca4f2501914f 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java @@ -655,9 +655,23 @@ protected void handleConnect(CommandConnect connect) { // 2. we require to validate the original credentials // 3. no credentials were passed if (connect.hasOriginalPrincipal() && service.getPulsar().getConfig().isAuthenticateOriginalAuthData()) { + // init authentication + String originalAuthMethod; + if (connect.hasOriginalAuthMethod()) { + originalAuthMethod = connect.getOriginalAuthMethod(); + } else { + originalAuthMethod = "none"; + } + AuthenticationProvider originalAuthenticationProvider = getBrokerService() .getAuthenticationService() - .getAuthenticationProvider(authMethod); + .getAuthenticationProvider(originalAuthMethod); + + if (originalAuthenticationProvider == null) { + throw new AuthenticationException(String.format("Can't find AuthenticationProvider for original role" + + " using auth method [%s] is not available", originalAuthMethod)); + } + originalAuthState = originalAuthenticationProvider.newAuthState( AuthData.of(connect.getOriginalAuthData().getBytes()), remoteAddress,