A robust and scalable microservice for user authentication, authorization, and token validation, built using Spring Boot, JWT, Kafka, and Spring Security. Designed to serve as a core authentication module in a distributed e-commerce platform.
- Spring Boot 3.4.3
- Spring Security
- JWT (jjwt)
- MySQL & JPA (Hibernate)
- Kafka (for async email notifications)
- Eureka Client (for service discovery)
- Lombok (boilerplate reduction)
- ✅ User Signup (with default + custom roles)
- ✅ Secure Login with hashed password & JWT token generation
- ✅ Stateless session management using JWT
- ✅ Token validation with expiry handling
- ✅ Kafka-based email notifications on signup/login
- ✅ Spring Security integration (for authentication/authorization)
- ✅ Exception handling with
@ControllerAdvice
- ✅ Eureka registration for microservice communication
Method | Endpoint | Description |
---|---|---|
POST | /auth/signup |
Register a new user |
POST | /auth/login |
Login user and receive JWT token |
POST | /auth/validate |
Validate JWT for a given user ID |
GET | /users/{id} |
Get user details by ID |
- Java 17
- MySQL running & DB created
- Kafka broker running locally
- Eureka server running at
http://localhost:8761/
spring.datasource.url=jdbc:mysql://localhost:3306/YOUR_DB_NAME
spring.datasource.username=YOUR_DB_USERNAME
spring.datasource.password=YOUR_DB_PASSWORD
email.id=your-email@example.com
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
mvn spring-boot:run
Run unit and integration tests with:
mvn test
- Topics used:
signup
login
Make sure a Kafka broker is running, and configure a consumer for the signup
& login
topics to listen for EmailDto
messages.
src/
├── clients/ # Kafka producer
├── configuration/ # Spring security config
├── controllers/ # REST endpoints
├── dtos/ # Data Transfer Objects
├── exceptions/ # Custom exception classes
├── models/ # Entity classes (User, Role, Session)
├── repositories/ # Spring Data JPA interfaces
├── security/ # JWT and UserDetails config
├── services/ # Business logic
{
"to": "user@example.com",
"from": "your-email@example.com",
"subject": "Welcome to Chitraveda",
"body": "Enjoy shopping!"
}
- Role-based access control (RBAC) using Spring Security
- Refresh tokens & logout API
- OTP-based login support
- Add Swagger documentation
Harshal Kalewar
🔗 LinkedIn
This project is licensed under the MIT License.