Skip to content

Commit 49e1516

Browse files
authored
task(logging): do not spit noise into logs when using API key: (#32124)
This pull request introduces a change to the `JWToken` interface to handle a specific case for `ApiToken` instances when retrieving the active user. The update ensures that the `subjectString` is used directly for `ApiToken` instances, bypassing decryption. Most importantly - this pr stops the unnecessary log messages when using an API key to access dotCMS. ### Key change: * Updated the `getActiveUser` method in `JWToken` to check if the current instance is of type `ApiToken`. If so, it directly uses the `subjectString` without attempting decryption, improving compatibility and avoiding unnecessary decryption for `ApiToken` instances. (`[dotCMS/src/main/java/com/dotcms/auth/providers/jwt/beans/JWToken.javaL74-R76](diffhunk://#diff-9e1faef3f8c5f2b7d61c08596157ffcfd27185c34be59a2916175507e8a97f54L74-R76)`)
1 parent 34ee618 commit 49e1516

File tree

1 file changed

+3
-1
lines changed
  • dotCMS/src/main/java/com/dotcms/auth/providers/jwt/beans

1 file changed

+3
-1
lines changed

dotCMS/src/main/java/com/dotcms/auth/providers/jwt/beans/JWToken.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public interface JWToken extends Serializable {
7171
default Optional<User> getActiveUser() {
7272
String subjectString = getUserId();
7373

74-
String userIdString = Try.of(()-> PublicEncryptionFactory.decryptString(subjectString)).onFailure(e-> Logger.warnAndDebug(JWToken.class,"Subject Not Encrypted:" + e,e)).getOrElse(subjectString);
74+
String userIdString = (this instanceof ApiToken)
75+
? subjectString
76+
: Try.of(()-> PublicEncryptionFactory.decryptString(subjectString)).onFailure(e-> Logger.debug(JWToken.class,"Subject Not Encrypted:" + e,e)).getOrElse(subjectString);
7577
User user = Try.of(() -> APILocator.getUserAPI().loadUserById(userIdString)).getOrNull();
7678
if (user != null && user.isActive()) {
7779
return Optional.of(user);

0 commit comments

Comments
 (0)