From 82491ae5d2e3092ff41115a852a13aed46f14661 Mon Sep 17 00:00:00 2001 From: Vlastimil Elias Date: Wed, 17 Mar 2021 11:43:11 +0100 Subject: [PATCH] KEYCLOAK-17446 - Prefill username in "Forgot Your Password" form if called from Login form --- .../login/freemarker/model/AuthenticationContextBean.java | 2 +- .../resources/theme/base/login/login-reset-password.ftl | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) 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 cec110afc7..a820724054 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 @@ -63,7 +63,7 @@ public class AuthenticationContextBean { String username = context.getAuthenticationSession().getAuthNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME); // Fallback to real username of the user just if attemptedUsername doesn't exist - if (username == null) { + if (username == null && context.getUser() != null) { username = context.getUser().getUsername(); } diff --git a/themes/src/main/resources/theme/base/login/login-reset-password.ftl b/themes/src/main/resources/theme/base/login/login-reset-password.ftl index 561d7d2ea7..efb1351230 100755 --- a/themes/src/main/resources/theme/base/login/login-reset-password.ftl +++ b/themes/src/main/resources/theme/base/login/login-reset-password.ftl @@ -9,12 +9,7 @@
- <#if auth?has_content && auth.showUsername()> - - <#else> - - - + <#if messagesPerField.existsError('username')> ${kcSanitize(messagesPerField.get('username'))?no_esc}