how to display custom error message in jsp for spring security auth exception

java, spring, spring-mvc, spring-security

Solution

Redefine the properties in messages.properties inside spring security jar. For example add to the classpath myMessages.properties and add a message source to the context:

AbstractUserDetailsAuthenticationProvider.badCredentials=Username/Password entered is incorrect.
AbstractUserDetailsAuthenticationProvider.disabled=Your account is diabled, please contact administrator.

At Salvin Francis:

- Add myMessages.properties to the WAR file inside WEB-INF/classes.

- Add this bean to spring context config file

Message Source Bean

<bean id="messageSource"   
    class="org.springframework.context.support.ResourceBundleMessageSource">  
    <property name="basenames">  
        <list>
            <value>myMessages</value>
        </list>
    </property>
</bean>

Problem

I want to display custom error message in jsp for spring security authentication exceptions. For wrong username or password, ``` spring displays : Bad credentials what I need : Username/Password entered is incorrect. ``` For user is disabled, ``` spring displays : User is disabled what I need : Your account is diabled, please contact administrator. ``` Do I need to override AuthenticationProcessingFilter just for this ? or else can I do something in jsp itself to find the authentication exception key and display different message

Original source