Announcement Announcement Module
Collapse
No announcement yet.
Exception Mapping Error Messages, why don't they post error to page on redirect. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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
    Code:
       <bean id="exceptionTranslationFilter" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
        	<property name="defaultFailureUrl" value="/pages/login.jsp?error"/>
    		<property name="exceptionMappings">
            	<props>           
                	<prop key="com.seersoft.springsecurity.authentication.PasswordResetException">/pages/maintenance/passwordreset.jsp?error</prop>
                	<prop key="org.springframework.security.authentication.CredentialsExpiredException">/pages/maintenance/credentialsexpired.jsp?error</prop>
                	<prop key="org.springframework.security.authentication.LockedException">/pages/login.jsp?error</prop>
                	<prop key="org.springframework.secuirty.authentication.DisabledException">/pages/accountdisabled.jsp?error</prop>
            	</props>
            </property>
    	</bean>
    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:
    Code:
    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);
        }
    }

    Comment


    • #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.

      Comment

      Working...
      X