A secure and scalable JWT Authentication System built with Spring Boot, Spring Security, PostgreSQL, and JWT (JSON Web Token).
- User Registration
- User Login
- JWT Access Token Authentication
- Refresh Token Support
- Role-Based Authorization (USER / ADMIN)
- Password Encryption with BCrypt
- Spring Security Integration
- PostgreSQL Database
- Global Exception Handling
- Request Validation
- RESTful API Architecture
- Java 21
- Spring Boot 3
- Spring Security
- Spring Data JPA
- JWT (JSON Web Token)
- PostgreSQL
- Lombok
- Maven / Gradle
- Access Token
- Refresh Token
- BCrypt Password Hashing
- Stateless Authentication
src
βββ config
βββ controller
βββ dto
βββ entity
βββ exception
βββ repository
βββ security
βββ service
βββ util
git clone https://github.com/IncridableAcuman/jwt-authentication.git
cd jwt-authenticationUpdate your application.yml or application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/jwt_auth
spring.datasource.username=postgres
spring.datasource.password=passwordjwt.secret=your-secret-key
jwt.access-expiration=900000
jwt.refresh-expiration=604800000mvn spring-boot:run./gradlew bootRunPOST /api/auth/registerRequest:
{
"username": "john",
"email": "john@example.com",
"password": "password123"
}POST /api/auth/loginRequest:
{
"email": "john@example.com",
"password": "password123"
}Response:
{
"accessToken": "jwt-access-token",
"refreshToken": "jwt-refresh-token"
}POST /api/auth/refreshRequest:
{
"refreshToken": "jwt-refresh-token"
}GET /api/users/profileHeader:
Authorization: Bearer <access_token>| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register | Register User |
| POST | /api/auth/login | Login User |
| POST | /api/auth/refresh | Refresh Access Token |
| GET | /api/users/profile | Get User Profile |
| GET | /api/admin/dashboard | Admin Access |
Run tests using:
mvn testor
./gradlew test- Passwords are encrypted using BCrypt.
- Access Tokens are short-lived.
- Refresh Tokens are stored securely.
- Authentication is fully stateless.
- Spring Security protects secured endpoints.
- Email Verification
- Password Reset
- Two-Factor Authentication (2FA)
- OAuth2 (Google / GitHub)
- Docker Support
- Redis Token Blacklist
Pull requests are welcome. For major changes, please open an issue first to discuss the proposed changes.
This project is licensed under the MIT License.
Developed by Izzat Abdusharipov