Skip to content

Commit

Permalink
fix: Prevent NPE when AuthenticatorConfig is null
Browse files Browse the repository at this point in the history
Closes #465

Signed-off-by: Sven-Torben Janus <[email protected]>
  • Loading branch information
sventorben committed Dec 17, 2024
1 parent 805e688 commit 51ad4e9
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.keycloak.services.managers.AuthenticationManager;

import java.util.List;
import java.util.Optional;

final class AuthenticationChallenge {

Expand All @@ -32,7 +33,9 @@ void forceChallenge() {
String rememberMeUsername = rememberMe.getUserName();

if (reauthentication.required() && context.getUser() != null) {
String attribute = context.getAuthenticatorConfig().getConfig().getOrDefault("userAttribute", "username");
String attribute = Optional.ofNullable(context.getAuthenticatorConfig())
.map(it -> it.getConfig().getOrDefault("userAttribute", "email").trim())
.orElse("email");
formData.add(AuthenticationManager.FORM_USERNAME, context.getUser().getFirstAttribute(attribute));
} else {
if (loginHintUsername != null || rememberMeUsername != null) {
Expand Down

0 comments on commit 51ad4e9

Please sign in to comment.