Alternatively, you can create a controller that puts the exception on the model and return the VM you want to show (you can use an AbstractController as it doesn't have to do much). In the vm you can check if the exception is empty and if not, print out the message of the exception. You need to specify that controller instead of the VM in the failureURL of the authenticationProcessingFilter and loginFormUrl of the authenticationEntryPoint. Finally, you need to make sure the controller is not secured by the filterInvocationInterceptor.
This is how I got around this problem (and be able to put other things in the model in order to show that in the vm).
Code:
public class LogonController extends AbstractController {
/**
* @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map model = new HashMap();
// Put the authentication exception on the model.
AuthenticationException authenticationException = (AuthenticationException)WebUtils.getSessionAttribute(request, AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY);
if (authenticationException != null) {
model.put("acegiSecurityException", authenticationException);
}
// Do other stuff
// Depending on the exception, return the normal logon page or
// the expired password page.
String view = "logon/logon";
if (authenticationException != null && (authenticationException instanceof PasswordExpiredException)) {
view = "logon/expired";
}
return new ModelAndView(view, model);
}
}
VM:
Code:
#if ($acegiSecurityException)
<font color="red">
Your login attempt was not successful, try again.<BR><BR>
$acegiSecurityException.message()
</font>
#end
Cheers, Stefaan.