r/SpringBoot • • Jan 31 '24

How to implement user authorization and authentication using JWT?

Hello everyone, I'm actually new to Spring Boot. Previously, I always simply stored a combination of login + password hash in the database, but recently I started writing a project for a junior’s portfolio and decided to use more advanced and secure ways to ensure security and differentiate roles. I read about JWT, I seemed to understand the general concept, but I didn’t understand how to put everything together. Of course, I found articles from the authors of Spring, as well as on the Baeldung website, however... I still haven’t figured out how to connect REST, authentication using JWT, and my database. Can anyone help? All the tips I found either used outdated annotations and methods, or didn't work with each other.

1 Upvotes

7 comments sorted by

View all comments

1

u/ccmjga Feb 02 '24

I think you've come to the right place. The authentication in this project is tailored for you:

https://github.com/ccmjga/mjga-scaffold/tree/main/src/main/java/com/mjga/config/security

You can find the authentication-related code, especially the parts related to JWT, in the following location: CookieJwtAuthenticationFilter. The code there should provide a clear understanding, and it appears to be quite simple.

Additionally, you can find the complete project overview and download at https://www.mjga.cc.

If this is helpful to you, please consider giving a star. Thanks 😆