From bd6845c47c45214119f6a49019c446418001e9aa Mon Sep 17 00:00:00 2001 From: Vincenzo Mecca Date: Wed, 22 Nov 2023 17:52:28 +0100 Subject: [PATCH] [DSC-1361] Fixes NPE in ITs --- .../org/dspace/authenticate/PasswordAuthentication.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/authenticate/PasswordAuthentication.java b/dspace-api/src/main/java/org/dspace/authenticate/PasswordAuthentication.java index 8eb29debf7cb..0bf0f9bcbc95 100644 --- a/dspace-api/src/main/java/org/dspace/authenticate/PasswordAuthentication.java +++ b/dspace-api/src/main/java/org/dspace/authenticate/PasswordAuthentication.java @@ -11,6 +11,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -285,8 +286,10 @@ public boolean areSpecialGroupsApplicable(Context context, HttpServletRequest re } private boolean isPasswordAuthenticatedInRequest(Context context, HttpServletRequest request) { - return StringUtils.isBlank(context.getAuthenticationMethod()) && - (Boolean) request.getAttribute(PASSWORD_AUTHENTICATED); + return (context == null || StringUtils.isBlank(context.getAuthenticationMethod())) && + request != null && Optional.ofNullable(request.getAttribute(PASSWORD_AUTHENTICATED)) + .map(Boolean.class::cast) + .orElse(false); } private boolean isPasswordAuthenticationMethodInContext(Context context, HttpServletRequest request) {