Skip to content

uddishasinghh31/PRODIGY_BWD_03

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Spring Boot JWT Authentication & Authorization REST API

Secure Authentication using Spring Security | JWT | BCrypt | MySQL | Flyway

Java Spring Boot Spring Security JWT MySQL Hibernate Flyway Maven

A production-ready RESTful API implementing secure JWT Authentication & Authorization using Spring Security, BCrypt password encryption, MySQL, Hibernate ORM, and Flyway database migrations.


πŸ“Œ Project Overview

This project was developed as part of the Prodigy InfoTech Internship – Task 3: JWT Authentication & Authorization.

The application extends the previous CRUD REST API by integrating Spring Security and JSON Web Tokens (JWT) to secure all protected endpoints.

Users can register, securely log in, receive a JWT access token, and access protected APIs only after successful authentication. Passwords are encrypted using BCrypt before being stored in the MySQL database.

The project follows Spring Boot best practices with a layered architecture, making it scalable and production-ready.


✨ Features

  • βœ… User Registration
  • βœ… User Login
  • βœ… JWT Authentication
  • βœ… Spring Security Integration
  • βœ… BCrypt Password Encryption
  • βœ… Stateless Authentication
  • βœ… Protected REST APIs
  • βœ… User CRUD Operations
  • βœ… Spring Data JPA
  • βœ… Hibernate ORM
  • βœ… MySQL Integration
  • βœ… Flyway Database Migration
  • βœ… DTO Validation
  • βœ… Global Exception Handling
  • βœ… UUID Primary Keys
  • βœ… Password Hidden from API Responses

πŸ›  Tech Stack

Technology Purpose
Java 21 Programming Language
Spring Boot Backend Framework
Spring Security Authentication & Authorization
JWT Token-Based Authentication
Spring Data JPA Data Access Layer
Hibernate ORM Framework
MySQL Relational Database
Flyway Database Migration
BCrypt Password Encryption
Maven Dependency Management
Postman API Testing
IntelliJ IDEA Development Environment

πŸ— Project Architecture

                    Client (Postman)
                           β”‚
                           β–Ό
                 Authentication Controller
                           β”‚
                           β–Ό
                Authentication Service
                           β”‚
                           β–Ό
                BCrypt Password Encoder
                           β”‚
                           β–Ό
                  User Repository (JPA)
                           β”‚
                           β–Ό
                    Hibernate ORM Layer
                           β”‚
                           β–Ό
                     MySQL Database
                           β–²
                           β”‚
                 JWT Authentication Filter
                           β”‚
                           β–Ό
                  Protected REST APIs

πŸ“‚ Project Structure

basic-rest-api
β”‚
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ main
β”‚   β”‚   β”œβ”€β”€ java
β”‚   β”‚   β”‚   └── com.example.basic_rest_api
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ config
β”‚   β”‚   β”œβ”€β”€ controller
β”‚   β”‚   β”œβ”€β”€ dto
β”‚   β”‚   β”œβ”€β”€ exception
β”‚   β”‚   β”œβ”€β”€ model
β”‚   β”‚   β”œβ”€β”€ repository
β”‚   β”‚   β”œβ”€β”€ security
β”‚   β”‚   β”œβ”€β”€ service
β”‚   β”‚   └── BasicRestApiApplication
β”‚   β”‚
β”‚   β”‚   └── resources
β”‚   β”‚       β”œβ”€β”€ application.properties
β”‚   β”‚       └── db
β”‚   β”‚           └── migration
β”‚
β”œβ”€β”€ pom.xml
β”œβ”€β”€ README.md
└── .gitignore

πŸ” JWT Authentication Flow

              Register User
                    β”‚
                    β–Ό
      Password Encrypted using BCrypt
                    β”‚
                    β–Ό
          Stored in MySQL Database
                    β”‚
                    β–Ό
               User Login
                    β”‚
                    β–Ό
          Credentials Verified
                    β”‚
                    β–Ό
            JWT Token Generated
                    β”‚
                    β–Ό
      Authorization: Bearer <TOKEN>
                    β”‚
                    β–Ό
      JWT Authentication Filter
                    β”‚
                    β–Ό
      Access Protected REST APIs

πŸ—„ Database Details

Property Value
Database MySQL
ORM Hibernate
Repository Spring Data JPA
Migration Tool Flyway
Password Encryption BCrypt
Primary Key UUID

πŸ”— REST API Endpoints

Authentication APIs

Method Endpoint Description
POST /auth/register Register User
POST /auth/login Login User

Protected User APIs

Method Endpoint Description
GET /api/users Retrieve All Users
GET /api/users/{id} Retrieve User by ID
POST /api/users Create User
PUT /api/users/{id} Update User
DELETE /api/users/{id} Delete User

πŸ§ͺ Sample API Requests

Register User

POST /auth/register
{
  "name": "John Doe",
  "email": "john@example.com",
  "age": 24,
  "password": "password123"
}

Login

POST /auth/login
{
  "email": "john@example.com",
  "password": "password123"
}

Login Response

{
  "token": "eyJhbGciOiJIUzI1NiJ9..."
}

Access Protected Endpoint

GET /api/users

Header:

Authorization: Bearer <JWT_TOKEN>

βš™οΈ How to Run the Project

Clone Repository

git clone https://github.com/uddishasinghh31/YOUR_REPOSITORY_NAME.git

Configure MySQL

CREATE DATABASE prodigy_task3_db;

Update application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/prodigy_task3_db
spring.datasource.username=YOUR_USERNAME
spring.datasource.password=YOUR_PASSWORD

jwt.secret=YOUR_SECRET_KEY
jwt.expiration=86400000

Run the Project

mvn spring-boot:run

Or run:

BasicRestApiApplication.java

The application will start on:

http://localhost:8080

πŸ”’ Security Features

  • BCrypt Password Encryption
  • JWT Authentication
  • Stateless Session Management
  • Spring Security Integration
  • JWT Authentication Filter
  • Protected Endpoints
  • Secure Password Storage
  • UUID-Based Primary Keys
  • DTO Validation
  • Global Exception Handling

πŸš€ Future Improvements

  • Refresh Token Support
  • Role-Based Authorization (Admin/User)
  • Swagger / OpenAPI Documentation
  • Docker Containerization
  • Unit & Integration Testing
  • GitHub Actions CI/CD
  • Cloud Deployment (AWS / Railway / Render)

πŸ‘©β€πŸ’» Author

Udisha Singh

Backend Developer | Java | Spring Boot | MySQL

Linkedin: https://www.linkedin.com/in/udisha-singh-47170b338


πŸ“„ Internship Details

Organization: Prodigy InfoTech

  • Task 1: Build a REST API for CRUD Operations
  • Task 2: Integrate Persistent Storage using MySQL, Spring Data JPA, Hibernate, and Flyway
  • Task 3: Implement JWT-Based Authentication & Authorization using Spring Security and JSON Web Tokens

⭐ If you found this project useful, please consider giving it a Star!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages