From 8cc04a672412053019bb01f78050eaf34d871a4d Mon Sep 17 00:00:00 2001 From: Douglas Palmer Date: Thu, 29 Jun 2023 12:35:12 -0700 Subject: [PATCH] NullPointerException on reading auth.attemptedUsername in terms template closes #21294 --- .../login/freemarker/model/AuthenticationContextBean.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/src/main/java/org/keycloak/forms/login/freemarker/model/AuthenticationContextBean.java b/services/src/main/java/org/keycloak/forms/login/freemarker/model/AuthenticationContextBean.java index a820724054..cd43f3384a 100644 --- a/services/src/main/java/org/keycloak/forms/login/freemarker/model/AuthenticationContextBean.java +++ b/services/src/main/java/org/keycloak/forms/login/freemarker/model/AuthenticationContextBean.java @@ -60,6 +60,10 @@ public class AuthenticationContextBean { // NOTE: This is called "attemptedUsername" as we won't necessarily display the username of the user, but the "attempted username", which he // used on the login screen (which could be eventually email or something else) public String getAttemptedUsername() { + if (context == null) { + return null; + } + String username = context.getAuthenticationSession().getAuthNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME); // Fallback to real username of the user just if attemptedUsername doesn't exist