You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by mi...@apache.org on 2025/01/16 11:06:26 UTC
(kafka) branch 3.7 updated: MINOR: Adjust logging in SerializedJwt (#18523)
This is an automated email from the ASF dual-hosted git repository.
mimaison pushed a commit to branch 3.7
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/3.7 by this push:
new bda90752607 MINOR: Adjust logging in SerializedJwt (#18523)
bda90752607 is described below
commit bda907526079849510ff6514f79bd6bf141fb4c4
Author: Mickael Maison <mi...@users.noreply.github.com>
AuthorDate: Thu Jan 16 09:58:13 2025 +0100
MINOR: Adjust logging in SerializedJwt (#18523)
Reviewers: Luke Chen <sh...@gmail.com>, Chia-Ping Tsai <ch...@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