I had the same problem ... but for obvious reasons I don't like the link code bound to the container.
So, I did to add an exception to the session myself.
First create a ThreadLocal exception store to send an exception between LoginContext and ServletContext:
public final class SecurityThreadLocal { private static final ThreadLocal<Exception> j_exception = new ThreadLocal<Exception>(); public static void setException(Exception e) { j_exception.set(e); } public static Exception getException() { return (Exception)j_exception.get(); } public static void clear() { j_exception.remove(); }
}
Add LoginException to SecurityThreadLocal:
catch (Exception e) {
Add exception to HttpSession using filter:
web.xml
<filter-mapping> <filter-name>SecurityFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
SecurityFilter.java
if (uri.endsWith("<form-error-page>") && session != null){ Exception j_exception = SecurityThreadLocal.getException(); if( j_exception != null) session.setAttribute("j_exception", j_exception); }
But you should know, because I know that this is bad practice and a security crack.
Well .., in my case, the client won ...
source share