A Spring Boot Authentication & Authorization System built using JWT (JSON Web Token) and Spring Security. This project demonstrates user registration, login, role-based access control, and secure REST APIs following clean layered architecture.
- User Registration & Login
- JWT-based Authentication
- Role-based Authorization (USER / ADMIN)
- Password Encryption (BCrypt)
- Secured REST APIs
- Global Exception Handling
- Clean Architecture (Controller, Service, Repository)
- MySQL / H2 compatible
- Java 17
- Spring Boot
- Spring Security
- JWT (JSON Web Token)
- Spring Data JPA (Hibernate)
- MySQL / H2
- Maven
- Postman (API Testing)
auth-system/
│
├── controller/
│ ├── AuthController.java
│ └── UserController.java
│
├── dto/
│ ├── LoginRequest.java
│ ├── RegisterRequest.java
│ └── AuthResponse.java
│
├── entity/
│ ├── User.java
│ └── Role.java
│
├── repository/
│ ├── UserRepository.java
│ └── RoleRepository.java
│
├── security/
│ ├── JwtUtil.java
│ ├── JwtFilter.java
│ └── SecurityConfig.java
│
├── service/
│ ├── AuthService.java
│ └── UserService.java
│
├── exception/
│ ├── GlobalExceptionHandler.java
│ └── CustomException.java
│
├── AuthSystemApplication.java
└── application.properties
POST /api/auth/register
Request Body
{
"username": "priyanka",
"password": "1234",
"email": "priyanka@gmail.com"
}POST /api/auth/login
Request Body
{
"username": "priyanka",
"password": "1234"
}Response
{
"token": "eyJhbGciOiJIUzI1NiJ9..."
}GET /api/users/profile
Header
Authorization: Bearer <JWT_TOKEN>
- User logs in with username & password
- Server validates credentials
- JWT token is generated
- Client sends token in Authorization header
- JwtFilter validates token for every request
- Access granted to secured endpoints
Create application.properties file:
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/auth_db
spring.datasource.username=root
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
jwt.secret=your_jwt_secret
jwt.expiration=86400000
---
## 🧪 Testing
* Use **Postman**
* Register → Login → Copy JWT
* Pass JWT in `Authorization` header to access protected APIs
---
## 🎯 Interview Explanation (One-Liner)
> “I built a Spring Boot authentication system using JWT and Spring Security, implementing secure login, registration, role-based authorization, and clean layered architecture.”
---
## 📌 Future Enhancements
* Refresh Token
* OAuth2 / Google Login
* Email Verification
* Forgot Password Feature
* Docker Deployment
---
## 👩💻 Author
**Priyanka Rode**
Java | Spring Boot | Backend Developer
---