有人可以帮助我自定义 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"
}
真的很期待 谢谢...
最佳答案
您可以在配置 HttpSecurity 时针对 403 执行此操作:
.exceptionHandling()
.accessDeniedHandler(myCoolAccessDeniedHandler())
如 documentation 中指定的那样
其他两个可能会被您定义的某些 ExceptionHandler 捕获和处理:
public class MyExceptionHandlingController extends ResponseEntityExceptionHandler implements ErrorController
关于java - SpringBoot OAuth2 自定义异常响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61500860/