如何在jsp中显示spring security auth exception的自定义错误消息 [英] how to display custom error message in jsp for spring security auth exception
问题描述
我想在jsp中显示春季安全认证例外的自定义错误消息。
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
推荐答案
重新定义 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.
在Salvin Francis:
- 将myMessages.properties添加到WEB-INF / classes中的WAR文件。
- 将此bean添加到spring上下文配置文件
消息来源豆
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>myMessages</value>
</list>
</property>
</bean>
这篇关于如何在jsp中显示spring security auth exception的自定义错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!