m1a2st commented on code in PR #19622:
URL: https://github.com/apache/kafka/pull/19622#discussion_r2085006260
##########
clients/src/main/java/org/apache/kafka/common/security/oauthbearer/OAuthBearerLoginCallbackHandler.java:
##########
@@ -179,55 +180,45 @@ public class OAuthBearerLoginCallbackHandler implements
AuthenticateCallbackHand
private Map<String, Object> moduleOptions;
- private AccessTokenRetriever accessTokenRetriever;
+ private JwtRetriever jwtRetriever;
- private AccessTokenValidator accessTokenValidator;
-
- private boolean isInitialized = false;
+ private JwtValidator jwtValidator;
@Override
public void configure(Map<String, ?> configs, String saslMechanism,
List<AppConfigurationEntry> jaasConfigEntries) {
- moduleOptions = JaasOptionsUtils.getOptions(saslMechanism,
jaasConfigEntries);
- AccessTokenRetriever accessTokenRetriever =
AccessTokenRetrieverFactory.create(configs, saslMechanism, moduleOptions);
- AccessTokenValidator accessTokenValidator =
AccessTokenValidatorFactory.create(configs, saslMechanism);
- init(accessTokenRetriever, accessTokenValidator);
+ Map<String, Object> moduleOptions =
JaasOptionsUtils.getOptions(saslMechanism, jaasConfigEntries);
+ JwtRetriever jwtRetriever = new DefaultJwtRetriever(configs,
saslMechanism, moduleOptions);
+ JwtValidator jwtValidator = new DefaultJwtValidator(configs,
saslMechanism);
+ configure(moduleOptions, jwtRetriever, jwtValidator);
}
- public void init(AccessTokenRetriever accessTokenRetriever,
AccessTokenValidator accessTokenValidator) {
- this.accessTokenRetriever = accessTokenRetriever;
- this.accessTokenValidator = accessTokenValidator;
+ void configure(Map<String, Object> moduleOptions, JwtRetriever
jwtRetriever, JwtValidator jwtValidator) {
+ this.moduleOptions = moduleOptions;
+ this.jwtRetriever = jwtRetriever;
+ this.jwtValidator = jwtValidator;
try {
- this.accessTokenRetriever.init();
+ this.jwtRetriever.init();
} catch (IOException e) {
- throw new KafkaException("The OAuth login configuration
encountered an error when initializing the AccessTokenRetriever", e);
+ throw new KafkaException("The OAuth login callback encountered an
error when initializing the JwtRetriever", e);
}
- isInitialized = true;
- }
-
- /*
- * Package-visible for testing.
- */
-
- AccessTokenRetriever getAccessTokenRetriever() {
- return accessTokenRetriever;
+ try {
+ this.jwtValidator.init();
+ } catch (IOException e) {
+ throw new KafkaException("The OAuth login callback encountered an
error when initializing the JwtValidator", e);
+ }
}
@Override
public void close() {
- if (accessTokenRetriever != null) {
- try {
- this.accessTokenRetriever.close();
- } catch (IOException e) {
- log.warn("The OAuth login configuration encountered an error
when closing the AccessTokenRetriever", e);
- }
- }
+ Utils.closeQuietly(jwtRetriever, "The OAuth login callback encountered
an error when closing the JwtRetriever");
+ Utils.closeQuietly(jwtValidator, "The OAuth login callback encountered
an error when closing the JwtValidator");
Review Comment:
`Utils.closeQuietly` uses a default error message template, so we should
update the string to match that default format.
https://github.com/apache/kafka/blob/62bec20aefcdb94e8a66f5e3f74e40916981912a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java#L1114
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]