java - Spring Security 自定义消息 "Authentication method not supported: GET"

标签 java spring spring-mvc spring-security

如何覆盖Spring安全消息“不支持身份验证方法:GET”?

在 spring-security-code-3.1.0.RELEASE.jar->org/springframework/security/messages.properties 中,没有可以覆盖此消息的 key 。

还有其他方法可以覆盖此消息吗?

我只允许服务器使用 post 方法进行身份验证。但是当我使用 get message 直接调用/j_spring_security_check 时,服务器返回上述消息。

提前致谢。

最佳答案

更改消息覆盖 attemptAuthentication方法UsernamePasswordAuthenticationFilter类,并设置自定义消息,其中 AuthenticationServiceException抛出。

引用号:Spring Source Code Link

--或--

要覆盖 spring security 对于 postOnly 请求的默认行为,如果您不想要特定消息,请使用以下方法: org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler将处理所有与身份验证相关的异常。哪个将处理org.springframework.security.authentication.AuthenticationServiceException当 spring security 配置为 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>

关于java - Spring Security 自定义消息 "Authentication method not supported: GET",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21935693/

相关文章:

java - 当对三个整数使用两次 = 运算符时,会发生什么?

Java从数组中拆分字符串

spring - 在 Spring Boot Rest 中检索查询参数的正确方法?

java - Spring Cloud 配置刷新后如何执行自定义逻辑?

java - Spring Web MVC Hibernate 集成错误

java - 将对象从下拉列表 (.jsp) 传递到 Controller

java - 比较java中的两个字符串并识别重复的单词

java - Spring并发 session 控制错误页面刷新后消失

java - Spring boot,可能导致View无法解决的问题

java - 无法在 eclipse 中将数据从 servlet 发送到 jsp 页面。怎么解决这个问题?