KAFKA-7462: Make token optional for OAuthBearerLoginModule (#5733)
OAuthBearerLoginModule is used both on the server-side and client-side (similar to login modules for other mechanisms). OAUTHBEARER tokens are client credentials used only on the client-side to authenticate with servers, but the current implementation requires tokens to be provided on the server-side even if OAUTHBEARER is not used for inter-broker communication. This commit makes tokens optional for server-side login context to allow brokers to be configured without a token when OAUTHBEARER is not used for inter-broker communication.
Reviewers: Ron Dagostino <rndgstn@gmail.com>, Jun Rao <junrao@gmail.com>
@ -248,6 +263,7 @@ public class OAuthBearerLoginModule implements LoginModule {
@@ -248,6 +263,7 @@ public class OAuthBearerLoginModule implements LoginModule {
OAuthBearerSaslClientProvider.initialize();// not part of public API
@ -266,17 +282,29 @@ public class OAuthBearerLoginModule implements LoginModule {
@@ -266,17 +282,29 @@ public class OAuthBearerLoginModule implements LoginModule {
"Already have an uncommitted token with private credential token count=%d",committedTokenCount()));
if(myCommittedToken!=null)
thrownewIllegalStateException(String.format(
else
thrownewIllegalStateException("Already logged in without a token");
}
if(loginState==LoginState.COMMITTED){
if(myCommittedToken!=null)
thrownewIllegalStateException(String.format(
"Already have a committed token with private credential token count=%d; must login on another login context or logout here first before reusing the same login context",
committedTokenCount()));
else
thrownewIllegalStateException("Login has already been committed without a token");
}
identifyToken();
identifyExtensions();
if(tokenRequiringCommit!=null)
identifyExtensions();
else
log.debug("Logged in without a token, this login cannot be used to establish client connections");
loginState=LoginState.LOGGED_IN_NOT_COMMITTED;
log.info("Login succeeded; invoke commit() to commit it; current committed token count={}",
committedTokenCount());
returntrue;
@ -292,7 +320,7 @@ public class OAuthBearerLoginModule implements LoginModule {
@@ -292,7 +320,7 @@ public class OAuthBearerLoginModule implements LoginModule {
@ -322,64 +350,77 @@ public class OAuthBearerLoginModule implements LoginModule {
@@ -322,64 +350,77 @@ public class OAuthBearerLoginModule implements LoginModule {
@ -90,10 +90,10 @@ public class OAuthBearerTokenCallback implements Callback {
@@ -90,10 +90,10 @@ public class OAuthBearerTokenCallback implements Callback {
@ -182,6 +182,14 @@ public class OAuthBearerUnsecuredLoginCallbackHandler implements AuthenticateCal
@@ -182,6 +182,14 @@ public class OAuthBearerUnsecuredLoginCallbackHandler implements AuthenticateCal