@@ -31,8 +31,9 @@ public class AzureEntraLoginCallbackHandler implements AuthenticateCallbackHandl
31
31
private TokenRequestContext tokenRequestContext ;
32
32
33
33
@ Override
34
- public void configure (
35
- Map <String , ?> configs , String mechanism , List <AppConfigurationEntry > jaasConfigEntries ) {
34
+ public void configure (Map <String , ?> configs ,
35
+ String mechanism ,
36
+ List <AppConfigurationEntry > jaasConfigEntries ) {
36
37
tokenRequestContext = buildTokenRequestContext (configs );
37
38
}
38
39
@@ -45,16 +46,17 @@ private TokenRequestContext buildTokenRequestContext(Map<String, ?> configs) {
45
46
return request ;
46
47
}
47
48
49
+ @ SuppressWarnings ("unchecked" )
48
50
private URI buildEventHubsServerUri (Map <String , ?> configs ) {
49
51
final List <String > bootstrapServers = (List <String >) configs .get (BOOTSTRAP_SERVERS_CONFIG );
50
52
51
- if (null == bootstrapServers ) {
53
+ if (bootstrapServers == null ) {
52
54
final String message = BOOTSTRAP_SERVERS_CONFIG + " is missing from the Kafka configuration." ;
53
55
log .error (message );
54
56
throw new IllegalArgumentException (message );
55
57
}
56
58
57
- if (bootstrapServers .size () != 1 ) {
59
+ if (bootstrapServers .size () > 1 ) {
58
60
final String message =
59
61
BOOTSTRAP_SERVERS_CONFIG
60
62
+ " contains multiple bootstrap servers. Only a single bootstrap server is supported." ;
@@ -72,11 +74,10 @@ private String buildTokenAudience(URI uri) {
72
74
@ Override
73
75
public void handle (Callback [] callbacks ) throws UnsupportedCallbackException {
74
76
for (Callback callback : callbacks ) {
75
- if (callback instanceof OAuthBearerTokenCallback oauthCallback ) {
76
- handleOAuthCallback (oauthCallback );
77
- } else {
77
+ if (!(callback instanceof OAuthBearerTokenCallback oauthCallback )) {
78
78
throw new UnsupportedCallbackException (callback );
79
79
}
80
+ handleOAuthCallback (oauthCallback );
80
81
}
81
82
}
82
83
@@ -91,7 +92,7 @@ private void handleOAuthCallback(OAuthBearerTokenCallback oauthCallback) {
91
92
.block ();
92
93
93
94
oauthCallback .token (token );
94
- } catch (final RuntimeException e ) {
95
+ } catch (RuntimeException e ) {
95
96
final String message =
96
97
"Failed to acquire Azure token for Event Hub Authentication. "
97
98
+ "Please ensure valid Azure credentials are configured." ;
@@ -104,7 +105,7 @@ public void close() {
104
105
// NOOP
105
106
}
106
107
107
- void setTokenCredential (final TokenCredential tokenCredential ) {
108
+ void setTokenCredential (TokenCredential tokenCredential ) {
108
109
AzureEntraLoginCallbackHandler .tokenCredential = tokenCredential ;
109
110
}
110
111
}
0 commit comments