Skip to content

Commit 4990373

Browse files
committed
Merge branch '5.8.x' into 6.0.x
Closes gh-14116
2 parents 18c5f43 + 52675c8 commit 4990373

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

web/src/main/java/org/springframework/security/web/authentication/ui/DefaultLoginPageGeneratingFilter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
3535
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
3636
import org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices;
3737
import org.springframework.util.Assert;
38+
import org.springframework.util.StringUtils;
3839
import org.springframework.web.filter.GenericFilterBean;
3940
import org.springframework.web.util.HtmlUtils;
4041

@@ -195,7 +196,8 @@ private String generateLoginPageHtml(HttpServletRequest request, boolean loginEr
195196
if (session != null) {
196197
AuthenticationException ex = (AuthenticationException) session
197198
.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
198-
errorMsg = (ex != null) ? ex.getMessage() : "Invalid credentials";
199+
errorMsg = (ex != null && StringUtils.hasLength(ex.getMessage())) ? ex.getMessage()
200+
: "Invalid credentials";
199201
}
200202
}
201203
String contextPath = request.getContextPath();

web/src/test/java/org/springframework/security/web/authentication/DefaultLoginPageGeneratingFilterTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,18 @@ public void generatesForSaml2LoginAndEscapesClientName() throws Exception {
171171
.contains("<a href=\"/saml/sso/google\">Google &lt; &gt; &quot; &#39; &amp;</a>");
172172
}
173173

174+
// gh-13768
175+
@Test
176+
public void generatesWhenExceptionWithEmptyMessageThenInvalidCredentials() throws Exception {
177+
DefaultLoginPageGeneratingFilter filter = new DefaultLoginPageGeneratingFilter(
178+
new UsernamePasswordAuthenticationFilter());
179+
filter.setLoginPageUrl(DefaultLoginPageGeneratingFilter.DEFAULT_LOGIN_PAGE_URL);
180+
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/login");
181+
request.setQueryString("error");
182+
request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, new BadCredentialsException(null));
183+
MockHttpServletResponse response = new MockHttpServletResponse();
184+
filter.doFilter(request, response, this.chain);
185+
assertThat(response.getContentAsString()).contains("Invalid credentials");
186+
}
187+
174188
}

0 commit comments

Comments
 (0)