【问题标题】:No content in 401 response after upgrade springBoot to 2.6.2springBoot 升级到 2.6.2 后 401 响应没有内容
【发布时间】:2022-01-07 15:52:56
【问题描述】:

默认错误处理不会返回正确的信息; 我将SpringBoot版本从2.5.2升级到2.6.2 案例场景: 发送没有认证的get方法:

邮递员对 springBoot 2.6.2 的回应: springBoot version 2.6.2

邮递员对 springBoot 2.5.2 的回应: springBoot version 2.5.2

缺少返回内容是预期的行为吗? 我打算使用@ControllerAdvice 来解决这个问题。

项目详情:

 <properties>
    <java.version>17</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

【问题讨论】:

  • Spring Boot 2.6.2 更新后的响应代码是什么? 401500?

标签: spring-boot security error-handling


【解决方案1】:

这个问题是由Spring 2.6.2 附带的新过滤器ErrorPageSecurityFilter 引起的。 Here你可以找到尝试过各种情况的人解决同样的问题。

在另一个ErrorPageSecurityFilter相关问题中,有人说:

ErrorPageSecurityFilter 使用 HttpServletRequest.getRequestURI() 作为包含上下文路径的 WebInvocationPrivilegeEvaluator.isAllowed(uri, authentication) 方法的 uri 参数。 JavaDoc 指出,应该在 uri 参数中排除上下文路径。

我认为这是因为 context-path 没有像描述 here 中那样在 uri 参数中排除。

也许看看here的建议会对你有所帮助。

【讨论】:

    猜你喜欢
    • 2023-01-20
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    相关资源
    最近更新 更多