TshepoMokgoatjane / tms

TMS (Tenant Management System) Back End
0 stars 0 forks source link

Create a Login Feature that uses MySQL Database, Spring Security, and JWT for Authentication #64

Open TshepoMokgoatjane opened 4 months ago

TshepoMokgoatjane commented 4 months ago

Create a Login Feature that uses MySQL Database, Spring Security, and JWT for Authentication.

We are now going to do away with the hardcoded feature.

Check out the following materials:

Tasks to be completed:

TshepoMokgoatjane commented 4 months ago

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2024-07-11T19:56:21.564+02:00 ERROR 23820 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Parameter 1 of constructor in za.co.tms.service.UserService required a bean of type 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' in your configuration.

TshepoMokgoatjane commented 4 months ago

Made some progress as I'm able to get the structure set up in terms of Performing CRUD

I just need to add the extra business logic to make my application solid especially with password encoding etc...

TshepoMokgoatjane commented 4 months ago

F5103762@FNBUR9009CVG MINGW64 /c/dev/tms (main) $ git status On branch main Your branch is up to date with 'origin/main'.

Untracked files: (use "git add ..." to include in what will be committed) src/main/java/za/co/tms/controller/UserController.java src/main/java/za/co/tms/model/Role.java src/main/java/za/co/tms/model/User.java src/main/java/za/co/tms/repository/RoleRepository.java src/main/java/za/co/tms/repository/UserRepository.java src/main/java/za/co/tms/service/UserService.java

nothing added to commit but untracked files present (use "git add" to track) git F5103762@FNBUR9009CVG MINGW64 /c/dev/tms (main) $ git add src

F5103762@FNBUR9009CVG MINGW64 /c/dev/tms (main) $ git status On branch main Your branch is up to date with 'origin/main'.

Changes to be committed: (use "git restore --staged ..." to unstage) new file: src/main/java/za/co/tms/controller/UserController.java new file: src/main/java/za/co/tms/model/Role.java new file: src/main/java/za/co/tms/model/User.java new file: src/main/java/za/co/tms/repository/RoleRepository.java new file: src/main/java/za/co/tms/repository/UserRepository.java new file: src/main/java/za/co/tms/service/UserService.java

F5103762@FNBUR9009CVG MINGW64 /c/dev/tms (main) $ git commit -m "WIP: Create a Login Feature that uses MySQL Database, Spring Security, and JWT for Authentication #64" [main 1354347] WIP: Create a Login Feature that uses MySQL Database, Spring Security, and JWT for Authentication #64 6 files changed, 246 insertions(+) create mode 100644 src/main/java/za/co/tms/controller/UserController.java create mode 100644 src/main/java/za/co/tms/model/Role.java create mode 100644 src/main/java/za/co/tms/model/User.java create mode 100644 src/main/java/za/co/tms/repository/RoleRepository.java create mode 100644 src/main/java/za/co/tms/repository/UserRepository.java create mode 100644 src/main/java/za/co/tms/service/UserService.java

F5103762@FNBUR9009CVG MINGW64 /c/dev/tms (main) $ git push Enumerating objects: 29, done. Counting objects: 100% (29/29), done. Delta compression using up to 4 threads Compressing objects: 100% (15/15), done. Writing objects: 100% (18/18), 3.04 KiB | 345.00 KiB/s, done. Total 18 (delta 8), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (8/8), completed with 6 local objects. To https://github.com/TshepoMokgoatjane/tms.git dfa6c67..1354347 main -> main

TshepoMokgoatjane commented 2 months ago

Busy following the below Tutorial so I can accomplish my mission:

Spring Boot 3.0 – JWT Authentication with Spring Security using MySQL Database [URL:] (https://www.geeksforgeeks.org/spring-boot-3-0-jwt-authentication-with-spring-security-using-mysql-database/)

The following Dependencies have been added:

Added more dependencies:

TshepoMokgoatjane commented 2 months ago

The overview of the project should look like this as part of an example to which I will need to integrate into my own system.

Spring-Boot-3 0-JWT-Authentication-with-Spring-Security-using-MySQL-Database-1

The Structure will cover the main functionality by using the following:

TshepoMokgoatjane commented 1 month ago

Currently experiencing an error upon running the program:

2024-10-19T10:56:03.673+02:00 ERROR 30220 --- [ restartedMain] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'jwtAuthenticationFilter' defined in file [C:\dev\tms\target\classes\za\co\tms\jwt\JwtAuthenticationFilter.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'jwtTokenService' defined in file [C:\dev\tms\target\classes\za\co\tms\jwt\JwtTokenService.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'org.springframework.security.oauth2.jwt.JwtEncoder' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 2024-10-19T10:56:03.845+02:00 INFO 30220 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2024-10-19T10:56:06.829+02:00 WARN 30220 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server 2024-10-19T10:56:06.863+02:00 INFO 30220 --- [ restartedMain] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2024-10-19T10:56:07.032+02:00 ERROR 30220 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Parameter 0 of constructor in za.co.tms.jwt.JwtTokenService required a bean of type 'org.springframework.security.oauth2.jwt.JwtEncoder' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.security.oauth2.jwt.JwtEncoder' in your configuration.

TshepoMokgoatjane commented 1 month ago

F5103762@FNBUR9009CVG MINGW64 /c/dev/tms (main) $ git push fatal: unable to access 'https://github.com/TshepoMokgoatjane/tms.git/': SSL certificate problem: unable to get local issuer certificate

F5103762@FNBUR9009CVG MINGW64 /c/dev/tms (main) $ git config --global http.sslVerify false

Fixed issue with pushing to my repository on GitHub.