Announcement Announcement Module
No announcement yet.
Exception Mapping Error Messages, why don't they post error to page on redirect. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception Mapping Error Messages, why don't they post error to page on redirect.

    Searching all around for this answer and was wondering why if you changing exception mappings key, that Spring will not allow to post the error message back to jsp page such as login.jsp (the default) or a redirected page. BadCredentialsException, UsernameNotFoundException, and other exceptions that I didn't change the keys are behaveing properly and post their exception msg to jsp. Is the session lost or something when you change the key values? Any help our understanding why would be grateful. From the source code looks like it should post the String msg. Put since it is not the "defaultFailureURL" something is going on. Any help would be appreciated if I post the error message in the redirect from the exception mapping keys to a new URL.

    Here is my security.xml
       <bean id="exceptionTranslationFilter" class="">
        	<property name="defaultFailureUrl" value="/pages/login.jsp?error"/>
    		<property name="exceptionMappings">
                	<prop key="com.seersoft.springsecurity.authentication.PasswordResetException">/pages/maintenance/passwordreset.jsp?error</prop>
                	<prop key="">/pages/maintenance/credentialsexpired.jsp?error</prop>
                	<prop key="">/pages/login.jsp?error</prop>
                	<prop key="org.springframework.secuirty.authentication.DisabledException">/pages/accountdisabled.jsp?error</prop>
    Last edited by aheschel; May 31st, 2013, 02:57 PM.

  • #2
    ExceptionMappingAuthenticationFailureHandler does not save the exception message since you are sending to a unique page for the exception (which means you could have the error message based upon the Exception type). If you want you could extend ExceptionMappingAuthenticationFailureHandler and invoke saveException in onAuthenticationFailure and then invoke the super. For example:
    public class MyAuthenticationFailureHandler extends ExceptionMappingAuthenticationFailureHandler {
        public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
                AuthenticationException exception) throws IOException, ServletException {
            saveException(request, exception);
            super.onAuthenticationFailure(request, response, exception);


    • #3
      Thanks Rob,

      Love the book, my go to on getting this done. What I was looking for and thank for the idea on the super.