如何覆盖Spring安全消息“不支持身份验证方法:GET”?
在spring-security-code-3.1.0.RELEASE.jar-> org / springframework / security / messages.properties中,没有密钥可以覆盖此消息。
还有其他方法可以覆盖此消息吗?
我只允许服务器使用post方法进行身份验证。但是,当我使用get消息直接调用/ j_spring_security_check时,服务器将返回上述消息。
提前致谢。
要更改类的消息覆盖attemptAuthentication
方法UsernamePasswordAuthenticationFilter
,并在AuthenticationServiceException
引发的地方设置自定义消息。
参考:Spring源代码链接
- 要么 -
要覆盖postOnly请求的默认Spring Security行为,如果您不希望收到特定消息,请使用以下方法:org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler
将处理所有与身份验证相关的异常。org.springframework.security.authentication.AuthenticationServiceException
当spring安全配置为postOnly时,它将处理抛出的异常,因此,当抛出此异常时,只需重定向到页面即可。
要覆盖默认配置,请在中添加以下代码 applicationContext.xml
<bean id="authenticationFailureHandler" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler"> <property name="defaultFailureUrl" value="LOGIN_ERROR_PAGE_URL" /> <property name="exceptionMappings"> <props> <prop key="org.springframework.security.authentication.AuthenticationServiceException">REDIRECT_PAGE_URL</prop> </props> </property> </bean>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句