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:
Luke Taylor 2008-02-01 16:00:46 +00:00
parent 842dec0180
commit abe62f9146

View File

@ -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;