https://github.com/mrrajputh/springboot-jwt-auth
Spring Boot 3 JWT Authentication System
https://github.com/mrrajputh/springboot-jwt-auth
jwt-authentication jwt-authorization jwt-token postgresql-database spring-boot spring-security
Last synced: about 1 month ago
JSON representation
Spring Boot 3 JWT Authentication System
- Host: GitHub
- URL: https://github.com/mrrajputh/springboot-jwt-auth
- Owner: mrRajputh
- Created: 2025-07-09T07:29:28.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-09T08:22:08.000Z (11 months ago)
- Last Synced: 2025-07-09T09:54:40.635Z (11 months ago)
- Topics: jwt-authentication, jwt-authorization, jwt-token, postgresql-database, spring-boot, spring-security
- Language: Java
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Spring Boot JWT Authentication System
This project is a **secure, production-ready JWT Authentication and Authorization system** built using **Spring Boot 3.0**, **Spring Security 6.0**, and **Java 17**. It demonstrates how to implement user registration, login, and role-based access to protected endpoints using JWT tokens.
---
## ๐ Features
- โ
User Registration & Authentication
- ๐ Stateless Security with JWT Tokens
- ๐ Secure Token Generation (256-bit key)
- ๐งโ๐ป Role-Based Access Control (RBAC)
- ๐ Password Encryption using BCrypt
- ๐งฑ Modular Architecture: Controller, Service, Repository
- โ๏ธ Configurable `application.yml`
- ๐งช API Testing via Postman or Swagger UI
---
## ๐งฐ Tech Stack
| Layer | Technology |
|--------------|-------------------------------------|
| Language | Java 17 |
| Framework | Spring Boot 3, Spring Security 6 |
| Build Tool | Maven |
| ORM | JPA, Hibernate |
| DB | PostgreSQL / H2 (for testing) |
| Auth Method | JWT (JJWT Library) |
---
## ๐ Project Structure
src/
โโโ main/
โโโ java/
โโโ com/arjun/sec/
โโโ auth/ # DTOs & AuthService
โโโ config/ # JWT & Security Config
โโโ controller/ # REST endpoints
โโโ entity/ # User entity & roles
โโโ repository/ # Data access layer
โโโ SecApplication.java
---
## ๐ฆ Getting Started
### 1๏ธโฃ Clone the Repo
bash:
git clone https://github.com/mrRajputh/springboot-jwt-auth.git
2๏ธโฃ Configure Your DB (PostgreSQL / H2)
Open src/main/resources/application.yml and set your DB config:
spring:
datasource:
url: jdbc:postgresql://localhost:5432/jwt_security
username: write here your username
password: write here your password
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: create-drop
show-sql: true
properties:
hibernate:
format_sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
๐ JWT 256-bit Secret Key Setup
To securely generate and sign JWT tokens, this project uses a 256-bit secret key.
โ
Generate a 256-bit Key
You can generate a 256-bit key using any of the following methods:
You can use any online 256-bit key generator web site from google
Example:
Visit: https://www.allkeysgenerator.com
Select:
Key size: 256-bit
Output format: Base64
๐Add the Key to JwtService.java
private static final String SECRET_KEY = "your-256-bit-base64-key-goes-here";
3๏ธโฃ Run the Application
bash:
./mvnw spring-boot:run
Or run directly from your IDE (IntelliJ, Eclipse, etc.)
๐ API Endpoints (you can use postman to test api Endpoints )
| Endpoint | Method | Description |
| --------------------------- | ------ | --------------------------- |
| `/api/v1/auth/register` | POST | Register a new user |
| `/api/v1/auth/authenticate` | POST | Login and receive JWT token |
| `/api/v1/demo-controller` | GET | Access protected endpoint |
๐ Future Improvements:
๐ Add Refresh Token functionality
๐งช Unit & Integration Tests
๐งฐ Dockerfile & docker-compose setup
๐ Swagger API Docs
๐ก Monitoring (Prometheus/Grafana)
๐ MFA or OAuth2 integration