This is an automated email from the ASF dual-hosted git repository. mimaison pushed a commit to branch 3.8 in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/3.8 by this push: new d04c48d0692 MINOR: Adjust logging in SerializedJwt (#18523) d04c48d0692 is described below commit d04c48d0692dba84fd92a4da0941946ce444a73c Author: Mickael Maison <mimai...@users.noreply.github.com> AuthorDate: Thu Jan 16 09:58:13 2025 +0100 MINOR: Adjust logging in SerializedJwt (#18523) Reviewers: Luke Chen <show...@gmail.com>, Chia-Ping Tsai <chia7...@gmail.com> --- .../oauthbearer/internals/secured/SerializedJwt.java | 17 +++++++---------- .../internals/secured/AccessTokenValidatorTest.java | 8 ++++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/SerializedJwt.java b/clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/SerializedJwt.java index 82c63111d1f..f45865fa638 100644 --- a/clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/SerializedJwt.java +++ b/clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/SerializedJwt.java @@ -39,18 +39,17 @@ public class SerializedJwt { token = token.trim(); if (token.isEmpty()) - throw new ValidateException("Empty JWT provided; expected three sections (header, payload, and signature)"); + throw new ValidateException("Malformed JWT provided; expected three sections (header, payload, and signature)"); String[] splits = token.split("\\."); if (splits.length != 3) - throw new ValidateException(String.format("Malformed JWT provided (%s); expected three sections (header, payload, and signature), but %d sections provided", - token, splits.length)); + throw new ValidateException("Malformed JWT provided; expected three sections (header, payload, and signature)"); this.token = token.trim(); - this.header = validateSection(splits[0], "header"); - this.payload = validateSection(splits[1], "payload"); - this.signature = validateSection(splits[2], "signature"); + this.header = validateSection(splits[0]); + this.payload = validateSection(splits[1]); + this.signature = validateSection(splits[2]); } /** @@ -93,13 +92,11 @@ public class SerializedJwt { return signature; } - private String validateSection(String section, String sectionName) throws ValidateException { + private String validateSection(String section) throws ValidateException { section = section.trim(); if (section.isEmpty()) - throw new ValidateException(String.format( - "Malformed JWT provided; expected at least three sections (header, payload, and signature), but %s section missing", - sectionName)); + throw new ValidateException("Malformed JWT provided; expected three sections (header, payload, and signature)"); return section; } diff --git a/clients/src/test/java/org/apache/kafka/common/security/oauthbearer/internals/secured/AccessTokenValidatorTest.java b/clients/src/test/java/org/apache/kafka/common/security/oauthbearer/internals/secured/AccessTokenValidatorTest.java index dc1027a0c9d..b7ef6c2ea71 100644 --- a/clients/src/test/java/org/apache/kafka/common/security/oauthbearer/internals/secured/AccessTokenValidatorTest.java +++ b/clients/src/test/java/org/apache/kafka/common/security/oauthbearer/internals/secured/AccessTokenValidatorTest.java @@ -38,25 +38,25 @@ public abstract class AccessTokenValidatorTest extends OAuthBearerTest { @Test public void testNull() throws Exception { AccessTokenValidator validator = createAccessTokenValidator(); - assertThrowsWithMessage(ValidateException.class, () -> validator.validate(null), "Empty JWT provided"); + assertThrowsWithMessage(ValidateException.class, () -> validator.validate(null), "Malformed JWT provided; expected three sections (header, payload, and signature)"); } @Test public void testEmptyString() throws Exception { AccessTokenValidator validator = createAccessTokenValidator(); - assertThrowsWithMessage(ValidateException.class, () -> validator.validate(""), "Empty JWT provided"); + assertThrowsWithMessage(ValidateException.class, () -> validator.validate(""), "Malformed JWT provided; expected three sections (header, payload, and signature)"); } @Test public void testWhitespace() throws Exception { AccessTokenValidator validator = createAccessTokenValidator(); - assertThrowsWithMessage(ValidateException.class, () -> validator.validate(" "), "Empty JWT provided"); + assertThrowsWithMessage(ValidateException.class, () -> validator.validate(" "), "Malformed JWT provided; expected three sections (header, payload, and signature)"); } @Test public void testEmptySections() throws Exception { AccessTokenValidator validator = createAccessTokenValidator(); - assertThrowsWithMessage(ValidateException.class, () -> validator.validate(".."), "Malformed JWT provided"); + assertThrowsWithMessage(ValidateException.class, () -> validator.validate(".."), "Malformed JWT provided; expected three sections (header, payload, and signature)"); } @Test