response.senderror(状态代码,“错误消息”)在将springboot升级到2.4.4后不工作

62lalag4  于 2021-10-10  发布在  Java
关注(0)|答案(2)|浏览(428)

我正在使用 AuthenticationEntryPoint 处理身份验证问题。将异常原因传递给最终用户。

response.sendError(responseCode, "errorReason")

我最近将spring boot从“2.2.11.release”升级到了“2.4.4”。从那时起,它就不再工作了。它没有在客户现在收到的响应中提供“errorreason”。最近在spring boot中引入了哪些我没有看到的变化?

zbwhf8kr

zbwhf8kr1#

从spring boot 2.3开始,默认情况下,该消息不再包含在错误响应中:
默认情况下,默认错误页面中不再包含错误消息和任何绑定错误。这降低了向客户端泄漏信息的风险。 server.error.include-messageserver.error.include-binding-errors 可以分别用于控制消息的包含和绑定错误。支持的值为 always , on-param ,及 never .
背景 server.error.include-message=always 将恢复spring boot 2.2的行为。

0g0grzrc

0g0grzrc2#

spring boot 2.4.4使用spring security 5.4.5。 AuthenticationException 此版本(链接)中不再有getmessage方法。然而,这仍然是相同的例子 AuthenticationException 您在应用程序中加入的内容。所以你可以用像。。。

if (authException instanceof CustomAuthenticationException) {
    CustomAuthenticationException ex = (CustomAuthenticationException) authException;
    // handle your exception
}

相关问题