How abdallahelameen/spring-boot-rest-api-with-jwt-authentication-and-user-management works
This is a Spring Boot REST API for user registration, login, and JWT-protected requests. The main workflow is: a client submits credentials or registration data to the user endpoints; registration hashes the password and persists the user, while login authenticates through Spring Security and returns a JWT. Later requests pass through the configured JWT filter, which validates the token and loads the user before protected endpoints run. The source excerpts show these calls; database provisioning and runtime configuration are not included.
Main entry points: UserController.java User endpoints · SecurityConfig.java Security configuration · UserRepo.java User repository · JwtFilter.java JWT request filter
Components 14
REST API
- User endpoints
src/main/java/com/elmn/SecurityLastChance/controller/UserController.java - Home endpoints
src/main/java/com/elmn/SecurityLastChance/controller/HomeController.java
Authentication
- Security configuration
src/main/java/com/elmn/SecurityLastChance/config/SecurityConfig.java - JWT request filter
src/main/java/com/elmn/SecurityLastChance/config/JwtFilter.java - JWT service
src/main/java/com/elmn/SecurityLastChance/service/JwtService.java - User details lookup
src/main/java/com/elmn/SecurityLastChance/service/MyUserDetailsService.java - Authentication manager
User records
- User service
src/main/java/com/elmn/SecurityLastChance/service/UserService.java - User repository
src/main/java/com/elmn/SecurityLastChance/repo/UserRepo.java - User account
src/main/java/com/elmn/SecurityLastChance/model/User.java - Account role
src/main/java/com/elmn/SecurityLastChance/enums/Role.java
Other components
- API client
- Configured database
- Spring application
src/main/java/com/elmn/SecurityLastChance/SecurityLastChanceApplication.java
Connections 16
- API client → User endpoints: sends requests
src/main/java/com/elmn/SecurityLastChance/controller/UserController.java - API client → Home endpoints: requests pages
src/main/java/com/elmn/SecurityLastChance/controller/HomeController.java - User endpoints → User service: registers, lists
src/main/java/com/elmn/SecurityLastChance/controller/UserController.java - User endpoints → Authentication manager: authenticates login
src/main/java/com/elmn/SecurityLastChance/controller/UserController.java - User endpoints → JWT service: creates token
src/main/java/com/elmn/SecurityLastChance/controller/UserController.java - User service → User repository: saves, reads
src/main/java/com/elmn/SecurityLastChance/service/UserService.java - User details lookup → User repository: looks up email
src/main/java/com/elmn/SecurityLastChance/service/MyUserDetailsService.java - User repository → User account: persists entity
src/main/java/com/elmn/SecurityLastChance/repo/UserRepo.java - User account → Account role: uses role
src/main/java/com/elmn/SecurityLastChance/model/User.java - JWT request filter → JWT service: extracts, validates
src/main/java/com/elmn/SecurityLastChance/config/JwtFilter.java - JWT request filter → User details lookup: loads account
src/main/java/com/elmn/SecurityLastChance/config/JwtFilter.java - Security configuration → JWT request filter: registers filter
src/main/java/com/elmn/SecurityLastChance/config/SecurityConfig.java - Security configuration → User details lookup: configures provider
src/main/java/com/elmn/SecurityLastChance/config/SecurityConfig.java - Security configuration → Authentication manager: exposes manager
src/main/java/com/elmn/SecurityLastChance/config/SecurityConfig.java - User repository → Configured database: uses JPA store
- Spring application → Security configuration: starts application