diff --git a/api/src/main/java/io/kafbat/ui/config/auth/azure/AzureEntraLoginCallbackHandler.java b/api/src/main/java/io/kafbat/ui/config/auth/azure/AzureEntraLoginCallbackHandler.java index c6c08b6fd..1f0a721e4 100644 --- a/api/src/main/java/io/kafbat/ui/config/auth/azure/AzureEntraLoginCallbackHandler.java +++ b/api/src/main/java/io/kafbat/ui/config/auth/azure/AzureEntraLoginCallbackHandler.java @@ -31,8 +31,9 @@ public class AzureEntraLoginCallbackHandler implements AuthenticateCallbackHandl private TokenRequestContext tokenRequestContext; @Override - public void configure( - Map configs, String mechanism, List jaasConfigEntries) { + public void configure(Map configs, + String mechanism, + List jaasConfigEntries) { tokenRequestContext = buildTokenRequestContext(configs); } @@ -45,16 +46,17 @@ private TokenRequestContext buildTokenRequestContext(Map configs) { return request; } + @SuppressWarnings("unchecked") private URI buildEventHubsServerUri(Map configs) { final List bootstrapServers = (List) configs.get(BOOTSTRAP_SERVERS_CONFIG); - if (null == bootstrapServers) { + if (bootstrapServers == null) { final String message = BOOTSTRAP_SERVERS_CONFIG + " is missing from the Kafka configuration."; log.error(message); throw new IllegalArgumentException(message); } - if (bootstrapServers.size() != 1) { + if (bootstrapServers.size() > 1) { final String message = BOOTSTRAP_SERVERS_CONFIG + " contains multiple bootstrap servers. Only a single bootstrap server is supported."; @@ -72,11 +74,10 @@ private String buildTokenAudience(URI uri) { @Override public void handle(Callback[] callbacks) throws UnsupportedCallbackException { for (Callback callback : callbacks) { - if (callback instanceof OAuthBearerTokenCallback oauthCallback) { - handleOAuthCallback(oauthCallback); - } else { + if (!(callback instanceof OAuthBearerTokenCallback oauthCallback)) { throw new UnsupportedCallbackException(callback); } + handleOAuthCallback(oauthCallback); } } @@ -91,7 +92,7 @@ private void handleOAuthCallback(OAuthBearerTokenCallback oauthCallback) { .block(); oauthCallback.token(token); - } catch (final RuntimeException e) { + } catch (RuntimeException e) { final String message = "Failed to acquire Azure token for Event Hub Authentication. " + "Please ensure valid Azure credentials are configured."; @@ -104,7 +105,7 @@ public void close() { // NOOP } - void setTokenCredential(final TokenCredential tokenCredential) { + void setTokenCredential(TokenCredential tokenCredential) { AzureEntraLoginCallbackHandler.tokenCredential = tokenCredential; } } diff --git a/api/src/main/java/io/kafbat/ui/config/auth/azure/AzureEntraOAuthBearerToken.java b/api/src/main/java/io/kafbat/ui/config/auth/azure/AzureEntraOAuthBearerToken.java index e9c315940..a53ac2552 100644 --- a/api/src/main/java/io/kafbat/ui/config/auth/azure/AzureEntraOAuthBearerToken.java +++ b/api/src/main/java/io/kafbat/ui/config/auth/azure/AzureEntraOAuthBearerToken.java @@ -5,7 +5,6 @@ import com.nimbusds.jwt.JWTParser; import java.text.ParseException; import java.util.Arrays; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import org.apache.kafka.common.errors.SaslAuthenticationException; @@ -14,7 +13,6 @@ public class AzureEntraOAuthBearerToken implements OAuthBearerToken { private final AccessToken accessToken; - private final JWTClaimsSet claims; public AzureEntraOAuthBearerToken(AccessToken accessToken) { @@ -48,7 +46,9 @@ public Set scope() { // https://docs.microsoft.com/azure/active-directory/develop/access-tokens#payload-claims, the // scp // claim is a String which is presented as a space separated list. - return Arrays.stream(((String) claims.getClaim("scp")).split(" ")).collect(Collectors.toSet()); + return Arrays + .stream(((String) claims.getClaim("scp")).split(" ")) + .collect(Collectors.toSet()); } @Override