mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-01 09:42:13 +00:00
Extract errorMessage from generateLoginPageHtml
This commit is contained in:
parent
ae23e3f5f4
commit
28d353d731
@ -189,15 +189,7 @@ public class DefaultLoginPageGeneratingFilter extends GenericFilterBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String generateLoginPageHtml(HttpServletRequest request, boolean loginError, boolean logoutSuccess) {
|
private String generateLoginPageHtml(HttpServletRequest request, boolean loginError, boolean logoutSuccess) {
|
||||||
String errorMsg = "Invalid credentials";
|
String errorMsg = loginError ? getLoginErrorMessage(request) : "Invalid credentials";
|
||||||
if (loginError) {
|
|
||||||
HttpSession session = request.getSession(false);
|
|
||||||
if (session != null) {
|
|
||||||
AuthenticationException ex = (AuthenticationException) session
|
|
||||||
.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
|
||||||
errorMsg = (ex != null) ? ex.getMessage() : "Invalid credentials";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String contextPath = request.getContextPath();
|
String contextPath = request.getContextPath();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("<!DOCTYPE html>\n");
|
sb.append("<!DOCTYPE html>\n");
|
||||||
@ -272,6 +264,15 @@ public class DefaultLoginPageGeneratingFilter extends GenericFilterBean {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getLoginErrorMessage(HttpServletRequest request) {
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
if (session != null &&
|
||||||
|
session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION) instanceof AuthenticationException exception) {
|
||||||
|
return exception.getMessage();
|
||||||
|
}
|
||||||
|
return "Invalid credentials";
|
||||||
|
}
|
||||||
|
|
||||||
private String renderHiddenInputs(HttpServletRequest request) {
|
private String renderHiddenInputs(HttpServletRequest request) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Map.Entry<String, String> input : this.resolveHiddenInputs.apply(request).entrySet()) {
|
for (Map.Entry<String, String> input : this.resolveHiddenInputs.apply(request).entrySet()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user