A production-ready RESTful API implementing secure JWT Authentication & Authorization using Spring Security, BCrypt password encryption, MySQL, Hibernate ORM, and Flyway database migrations.
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.
- β 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
| 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 |
Client (Postman)
β
βΌ
Authentication Controller
β
βΌ
Authentication Service
β
βΌ
BCrypt Password Encoder
β
βΌ
User Repository (JPA)
β
βΌ
Hibernate ORM Layer
β
βΌ
MySQL Database
β²
β
JWT Authentication Filter
β
βΌ
Protected REST APIs
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
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
| Property | Value |
|---|---|
| Database | MySQL |
| ORM | Hibernate |
| Repository | Spring Data JPA |
| Migration Tool | Flyway |
| Password Encryption | BCrypt |
| Primary Key | UUID |
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register |
Register User |
| POST | /auth/login |
Login User |
| 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 |
POST /auth/register{
"name": "John Doe",
"email": "john@example.com",
"age": 24,
"password": "password123"
}POST /auth/login{
"email": "john@example.com",
"password": "password123"
}{
"token": "eyJhbGciOiJIUzI1NiJ9..."
}GET /api/usersHeader:
Authorization: Bearer <JWT_TOKEN>
git clone https://github.com/uddishasinghh31/YOUR_REPOSITORY_NAME.gitCREATE DATABASE prodigy_task3_db;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=86400000mvn spring-boot:runOr run:
BasicRestApiApplication.java
The application will start on:
http://localhost:8080
- 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
- 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)
Udisha Singh
Backend Developer | Java | Spring Boot | MySQL
Linkedin: https://www.linkedin.com/in/udisha-singh-47170b338
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