Spring Security 6 | How to Create a Login System with Spring Data JPA and JWTs [NEW 2023]

preview_player
Показать описание
Spring Security can be a massive rabbit hole when you get started. This is exactly what happened to me when I started researching how to add encryption to the backend of my Twitter clone here on YouTube. I poured hours and hours of watching tutorials and trying to figure out how to tweak one tutorial to do this, or another tutorial that was outdated to do that. Finally, I stumbled upon some non-outdated tutorials, but they still lacked exactly what I needed and I still had to link multiple different tutorial videos together to get to where I am now. If you have been in my place before, or if you are at where I was right now this is the video for you.

In this video we are going to sit down from the start of an application and build out an entire authenticated backend server with login and register features connected to a database. We are also going to implement the generation of JWT's so you can have a stateless backend, and we will use OAuth2Resource server to verify that the JWT's sent back are valid, and then authorize requests to specific routes based on the users roles. We will do all of this from scratch so you can understand where we started and how we got to the finish line.

I highly recommend that you watch through the entire video for context, however, here is the link to the project code:

~~~ Feeling Generous? Donate to the channel for the all the hard work that made this video ~~~

~~~ Stay Up To Date With My Social Media ~~~

~~~ Background Music Used In My Video ~~~

Astroblk - Nothing Really matters that much to me anymore

Aviscerall - Sanctuary

Cøzybøy - Please Don't Drown

Astroblk - explorer

Knwln Ryan - Can't Replace You

NetNavi - How Can You Tell

Astroblk - Vancouver

Aviscerall - Lullabyes

Cøzybøy - Deep In Snow

Astroblk - Courage

Aviscerall - Coffee Shop

Cøzybøy - I'll Do Anything

Astroblk - Pay Up _____

Aviscerall - Chillin'

Cøzybøy - I Feel Okay Today

Astroblk - fleids

Aviscerall - Progress

Cøzybøy - What Do You know About Love

Astroblk - Geneva

Knwln Ryan - Jupiter

Astroblk - Ginger Spice

Aviscerall - Clockin' Out

Knwln Ryan - Waterfalls

Aviscerall - Feelings

Astroblk - Soul in Seoul

NetNavi - To A Song

Astroblk - Sunrise

Aviscerall - Onett

~~~ Video Content ~~~

0:00:00 - Introduction
0:03:05 - Prerequisites
0:04:34 - Project Diagram
0:06:05 - Project Creation
0:17:04 - Creating the UserController
0:19:56 - Creating the AdminController
0:21:32 - Testing User and Admin Endpoints
0:22:37 - Installing Spring Security
0:24:43 - Utilizing the default Spring Security password
0:25:57 - Unlocking the API
0:28:45 - Creating the Role model
0:32:26 - Creating the ApplicationUser model
0:38:32 - Creating the UserService
0:42:20 - Configuring basic authentication
0:47:38 - Creating the Repository layer
0:51:20 - Loading Roles and Admin User
0:55:13 - Using the UserRepository in the UserService
0:58:05 - Creating the AuthenticationService and registerUser method
1:04:12 - Creating the AuthenticationController and registerUser method
1:09:22 - Configuring all traffic to AuthenticationController
1:11:53 - Creating the KeyGenerator utility class
1:14:37 - Creating the RSAKeyProperties class
1:16:21 - Installing OAuthResourceServer
1:17:29 - Configuring Spring Security to use OAuthResourceServer
1:22:05 - Creating the TokenService
1:26:54 - Creating the LoginResponseDTO class
1:28:37 - Creating the loginUser method in AuthenticationService
1:32:52 - Creating the loginUser method in the AuthenticationController
1:34:11 - Testing user login
1:36:23 - Configuring role based authorization
1:42:44 - Testing role based authorization
1:43:52 - Outro

#unknownkoder #javaprogramming #springsecurity
Рекомендации по теме
Комментарии
Автор

You had me in the first 20 seconds, tutorial hell has brought me here i was almost loosing my mind on spring security

kelvinwarui
Автор

Fantastic Video, Thank you for putting all this together in one place and having it explained very clearly and at a steady pace. Great work!!!

sajithkumarganesan
Автор

What a fantastic to the point video it is, Thank you so much Ethan for sharing valuable knowledge with all of us, my knowledge before and after watching this video has increased very much, looking forward to more of your videos.

I had watched a bunch of videos on this topic, but your explanation made it much easy to follow and code along with you.

aman_deep
Автор

This video is a compilation of everything useful that is said in the other videos, discarding all the other useless things that are said, updating it to the latest versions of spring.
Liked the video, keep it up.

mazogra
Автор

Thank you so much! I highly recommend this video to anyone who wants to learn about Spring Security. It is a comprehensive and informative resource :)

mohssinedardar
Автор

The Best explanation I have even seen for spring security and jwt authentication. Thanks alot.

pranavthakkar
Автор

It was indeed an absolute Behemoth of a video! Great tutorial, loved the pacing and the explanations. My subscribe and like is your good sir.

kheydbeats
Автор

Amazing video! Such a complex topic was explained in a relatively simple way, thank you!

romanlobko
Автор

This video hit the nail on the head, I watched countless other videos from other people before I found this one, and the content was either outdated or poorly explained. I appreciate that you did everything from scratch and explained each step. Wish I found this video about 8 videos earlier, but I finally understand the whole implementation process for Jwt's. 11/10 will watch again.

cydoentis
Автор

All I could say this is an extraordinary tutorial. I tried all of the spring security tutorials but they did not cover the nitty gritty aspects of it like the jwt token creation and authorization but you just were superb. Thank you very much for uploading a gem ❤

vsaihruthikreddy
Автор

Well done. Had some troubles with dependencies but overall your video is quite amazing! Thank you so much!

superkobke
Автор

perfect video, everything will go smoothly without getting any blocker for me, thanks brother for such a nice video😍

pradeepk
Автор

You just revived my passion for spring boot based backend development. Thank you so much. This is the best spring security crash course I've found on YouTube even better than the inspirations you mentioned in this video. The reason is, that you used less jargon and fancy Java. You showed basic Java skills to explain an already complex spring security concept which feels smooth.

Most of the creators from the Java community tend to use a lot of fancy Java design patterns and advanced Java features which causes great difficulty for freshers to understand such complex concepts.


Constructive Criticism:
I have one small suggestion for you, the cutting of your voice is really not good. There are no pauses between your speech, leading to you sounding monotonous even when you're not. Also, it made me rewind many times since I never understood where one sentence ended and the other began.

Love your content. keep going ♥

adarshpandey
Автор

Excellent tutorial. This is just what I needed to get started.

professionalyoutubevideowa
Автор

Great video and working around the deprecated methods wasn’t too bad and was a very good practice of working with documentation. Thanks for putting this all together. 👏🏼👏🏼👏🏼

fetterollie
Автор

Wow, first time I get it right. Thank you! This channel should have much more followers.

I had some issues using Lombok, but when I did all the constructors, getters, setters manually it's finally worked! I guess I need more experience with constructors first, then use lombok.

koffeetalk
Автор

Liked the video! Here's an idea for future tutorials, can you create git branches for each chapter? this way we can go back and forth between different chapters to compare and contrast the changes.

sherlockholmes
Автор

This is a really great tutorial. Thanks for this

maelina
Автор

great content video with proper explanation keep doing contents like this 😍, i was looking for this type content for many days, i just wasted a lot of time but this saved my time and can explain how to save roles in DB annd retrieve it from DB and also about OAuth 2.0

kumar-mhhy
Автор

Thank you so much after searching alot i found this video that covered my ground up spring security and jwt thank you man.

curiosabouttech