mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-28 06:42:49 +00:00
Modified to store the login name in the session when login fails, so that it is available to the view (as in AuthenticationProcessingFilter).
This commit is contained in:
parent
842dec0180
commit
abe62f9146
@ -30,6 +30,7 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +66,10 @@ public class OpenIdAuthenticationProcessingFilter extends AbstractProcessingFilt
|
|||||||
String identity = req.getParameter("openid.identity");
|
String identity = req.getParameter("openid.identity");
|
||||||
|
|
||||||
if (!StringUtils.hasText(identity)) {
|
if (!StringUtils.hasText(identity)) {
|
||||||
throw new OpenIdAuthenticationRequiredException("External Authentication Required", obtainUsername(req));
|
// Make the username available to the view
|
||||||
|
String username = obtainUsername(req);
|
||||||
|
setLastUsername(username, req);
|
||||||
|
throw new OpenIdAuthenticationRequiredException("External Authentication Required", username);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -78,13 +82,20 @@ public class OpenIdAuthenticationProcessingFilter extends AbstractProcessingFilt
|
|||||||
Authentication authentication = this.getAuthenticationManager().authenticate(token);
|
Authentication authentication = this.getAuthenticationManager().authenticate(token);
|
||||||
|
|
||||||
if (authentication.isAuthenticated()) {
|
if (authentication.isAuthenticated()) {
|
||||||
req.getSession()
|
setLastUsername(token.getIdentityUrl(), req);
|
||||||
.setAttribute(AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY, token.getIdentityUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return authentication;
|
return authentication;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setLastUsername(String username, HttpServletRequest request) {
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
|
||||||
|
if (session != null || getAllowSessionCreation()) {
|
||||||
|
request.getSession().setAttribute(AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY, username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected String determineFailureUrl(HttpServletRequest request, AuthenticationException failed) {
|
protected String determineFailureUrl(HttpServletRequest request, AuthenticationException failed) {
|
||||||
if (failed instanceof OpenIdAuthenticationRequiredException) {
|
if (failed instanceof OpenIdAuthenticationRequiredException) {
|
||||||
OpenIdAuthenticationRequiredException openIdRequiredException = (OpenIdAuthenticationRequiredException) failed;
|
OpenIdAuthenticationRequiredException openIdRequiredException = (OpenIdAuthenticationRequiredException) failed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user