如何在jsp中为spring security auth异常显示自定义错误消息 [英] how to display custom error message in jsp for spring security auth exception
问题描述
我想在jsp中显示spring security认证异常的自定义错误信息.
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.
如果用户被禁用,
spring displays : User is disabled
what I need : Your account is diabled, please contact administrator.
我是否需要为此重写 AuthenticationProcessingFilter ?或者我可以在jsp本身中做一些事情来找到身份验证异常密钥并显示不同的消息
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
推荐答案
重新定义 spring security jar 中 messages.properties 中的属性.例如添加到类路径 myMessages.properties 并将消息源添加到上下文:
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.
在萨尔文·弗朗西斯:
- 将 myMessages.properties 添加到 WEB-INF/classes 内的 WAR 文件中.
- 将此bean添加到spring上下文配置文件
消息源 Bean
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>myMessages</value>
</list>
</property>
</bean>
这篇关于如何在jsp中为spring security auth异常显示自定义错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!