I'm using Spring Security with CAS and have the following issue. When the authentication error is thrown from CAS Server (e.g. invalid username/password) it is shown well in form and is displayed correctly using tag:
<form:errors path="*" id="msg" cssClass="alert alert-danger" element="div"/>
But in cases when CAS Server returns success and the AuthenticationException is thrown on CAS Client none of the errors are displayed as basically CAS Client redirects back to http://localhost:8080/cas/login?service=http%3A%2F%2Flocalhost%3A8080%2Fj_spring_cas_security_check
So I can't really display what went wrong on the client side. Is it somehow possible to display an error from client on the same JSP in case it throws AuthenticationException?
Not sure if that's the super clean and right way to do it, but the way I've managed to do that is using cookies.
All I had to do is to extend
SimpleUrlAuthenticationFailureHandler, get there last authentication exception usingrequest.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)and write my custom error code cookie. The code is inScala, but is pretty straightforward:Then, on the
CAS serverside I've displayed error onJSPin the following way:And after the page is loaded and error is shown, I've just removed that cookie in
JS: