Spring Security customizing status code, and prevent other codes overridden by 403
The Spring Security will override all errors like 400, 405, and 500 to 403, and we may want to use 401 for unauthorized requests. This article will solve this problem by customizing an AuthenticationEntryPoint.
Background
- I folled this video to setup Spring Security and JWT authorization:
- Also referred to this answer: https://stackoverflow.com/a/47507342/19420247
- Based on the above, due to the version updating may make some changes, please note that the article time is not too old
解决方案
Add exceptionHandling
to SecurityFilterChain
.
1 |
|
Spring Security customizing status code, and prevent other codes overridden by 403
https://blog.zhanganzhi.com/en/2023/07/d7099ff451fa/