【问题标题】:SpringBoot OAuth2 Customizing Exception ResponseSpring Boot OAuth2 自定义异常响应
【发布时间】:2020-04-29 11:35:08
【问题描述】:

有人可以帮我定制 SpringBoot 2 OAuth 2.0 的异常响应吗?基本上我需要将异常响应跟踪到一些自定义应用程序特定的响应中。

{
    "error": "unauthorized",
    "error_description": "Full authentication is required to access this resource"
}

{
    "error": "invalid_token",
    "error_description": "Access token expired: sdfhjkudxnkjjkJJHGhgnbHnmbhJGJH"
}

{
    "timestamp": "2020-04-29T11:30:47.045+0000",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/testf"
}

类似

{
    "status": "error",
    "message": "Full authentication is required to access this resource"
}

真的很期待 谢谢...

【问题讨论】:

    标签: java spring-boot spring-security oauth-2.0 spring-security-oauth2


    【解决方案1】:

    您可以在配置 HttpSecurity 时为 403 执行此操作:

    .exceptionHandling()     
    .accessDeniedHandler(myCoolAccessDeniedHandler())
    

    documentation中指定的一样

    其他两个可能会被您定义的一些 ExceptionHandler 捕获和处理:

    public class MyExceptionHandlingController extends ResponseEntityExceptionHandler implements ErrorController
    

    【讨论】:

      猜你喜欢
      • 2020-05-26
      • 2019-12-10
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 2021-07-10
      • 2015-10-18
      • 1970-01-01
      • 2014-12-16
      相关资源
      最近更新 更多