A Spring Boot REST API project demonstrating authentication and authorization using Spring Security, JWT, Spring Data JPA, and MySQL.
This repository is intended as a learning and reference project for understanding how security is implemented in modern Spring Boot applications.
- RESTful APIs built with Spring Boot
- Authentication using Spring Security
- Stateless authentication using JWT (JSON Web Tokens)
- Role-based authorization
- Database integration using Spring Data JPA
- MySQL as the relational database
- Maven-based dependency management
- Clean and beginner-friendly project structure
- Java 21
- Spring Boot
- Spring Security
- Spring Data JPA
- JWT (JSON Web Token)
- MySQL
- Maven
- Lombok
src/main/java
└── com.security.demo
├── config
├── controller
├── model
├── repo
├── service
└── DemoApplication.java
- Spring Security is configured using SecurityFilterChain
- JWT is used for stateless authentication
- Tokens are generated after successful authentication
- Each request is validated using a JWT filter
- Secured endpoints require a valid token
MySQL is used as the database and configured using Spring Data JPA.
Example application.properties configuration:
spring.datasource.url=jdbc:MySQL://localhost:5432/your_db
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
- Java 21 or higher
- Maven
- MySQL running locally
- Clone the repository
git clone https://github.com/a6hijeet/spring-security-demo.git
- Navigate to the project directory
cd spring-security-demo
- Build the project
mvn clean install
- Run the application
mvn spring-boot:run
The application will start on:
You can test the APIs using:
- Postman
- curl
- Any REST client
Typical request flow:
- Authenticate user and receive JWT token
- Send token in request header
Authorization: Bearer YOUR_JWT_TOKEN
- Access secured endpoints
- Understand Spring Security fundamentals
- Learn JWT-based authentication
- Secure REST APIs
- Work with Spring Data JPA and MySQL
- Build real-world backend security patterns
- This is a demo and learning project
- Not intended for production use
- Focuses on clarity and fundamentals