[Episode 38] Handling Spring Security Exceptions Using @ControllerAdvice

preview_player
Показать описание

In this video, I handled various Spring Security exceptions in a @ControllerAdvice annotated class. I defined several custom classes that implement the AuthenticationEntryPoint interface.

00:00 Introduction to Spring Security Exceptions
01:24 Defining exception handlers in ControllerAdvice for security exceptions
06:30 Testing security exception handling in Postman (Not working as expected)
08:47 Spring Security exceptions are thrown before the controllers start to work
09:37 Handling unsuccessful basic authentication in ControllerAdvice
15:24 Handling unsuccessful JWT authentication in ControllerAdvice
18:11 Handling unsuccessful JWT authorization (access denied exception) in ControllerAdvice
21:30 Testing security exception handling in Postman (Working as expected)

Keep watching. Here are more Spring Security videos:

I don't want to make a super long video so I split it into smaller ones. If you want to learn Spring Boot 3 systematically, please visit the playlist (and save the playlist) for more Spring Boot 3 tutorials.

Feel free to leave a comment if you have any questions.

As always, thanks for watching, and happy learning!
Рекомендации по теме
Комментарии
Автор

Hi Sir. At 17:25, The method and() from the type SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> has been deprecated since version 6.1 and marked for removal. So i use
-> {


}). My Spring Boot version is 3.4.4 and Spring Security version is 6.4.4.

RenaZ-xz
Автор

This is one of the best playlist I have found on the internet. Everything explained so clearly with all the resources provided.
Thanks for this.

RaghavSharma-nthr
Автор

Everything is explained straightforwardly, and the video and sound quality are perfect, it is one of the best without any doubt.

SamanSarafraz
Автор

Thank you so much for creating the amazing video tutorials on Spring Security! Before I stumbled upon your content, my understanding of Spring Security was a complete hodgepodge. Your clear and concise explanations, along with practical examples, have been an absolute game-changer for me. Thanks to your videos, I now have a much better grasp of Spring Security, and I feel much more confident in working with it. Your dedication to sharing knowledge is truly appreciated!

lynx
Автор

For the question asked …getting authorizationdeniedexception but not getting caught in controlleradvice 😢can you please help how to handle that scenario.?

RanjeetKumar-kbig
Автор

Hello @Bingyang Wei. Do you have a video teaching how to create an api with refreshToken and accessToken?

dav.R
Автор

Thanks for the clear explanation. But I want to ask is there any solution to replace HandlerExceptionResolver on webflux?

kienduy
Автор

Hi,

Thanks for that great video. I also want to handle the exception when the request's authorization type is different from "Bearer Token" (likne no auth, basic auth etc.). How can I handle that? Thanks in advance.

akifhasdemir
Автор

When I add the to the SecurityConfig I get the following exception:
null
Any idea why?

joaogoncalves
welcome to shbcf.ru