A Spring Boot microservice responsible for stakeholder registration, authentication, authorization, profile management, and user administration in the SalonSphere platform.
The Stakeholder Service is the first core microservice of the SalonSphere application.
- User registration
- User login
- JWT-based authentication
- JWT request filtering
- Role-based authorization
@PreAuthorizemethod-level security- Secure password handling using Spring Security
- Get user by email
- Get currently authenticated user
- Update user profile
- Change password
- Delete user
- Search users by firstname
- RESTful API architecture
- DTO-based request and response handling
- Standardized
ApiResponse<T>structure - HTTP status codes using
ResponseEntity - Bean Validation using
@Valid - Global exception handling
- Pagination
- Sorting
- Search functionality
- Controller-level logging
- Swagger / OpenAPI documentation
- Interactive API testing through Swagger UI
| Technology | Usage |
|---|---|
| Java | Programming Language |
| Spring Boot | Application Framework |
| Spring MVC | REST API Development |
| Spring Security | Authentication & Authorization |
| JWT | Token-Based Authentication |
| Spring Data JPA | Database Access |
| Hibernate | ORM |
| MySQL | Database |
| Maven | Build & Dependency Management |
| Swagger / OpenAPI | API Documentation |
| SLF4J | Application Logging |
| Jakarta Validation | Request Validation |
src/main/java/com/project/stakeholders
โ
โโโ controller
โ โโโ StakeholderController.java
โ
โโโ dto
โ โโโ ApiResponse.java
โ โโโ ChangePasswordDTO.java
โ โโโ LoginDTO.java
โ โโโ LoginResponseDTO.java
โ โโโ RegisterDTO.java
โ โโโ ResponseDTO.java
โ โโโ UpdateDTO.java
โ
โโโ entity
โ โโโ Stakeholders.java
โ
โโโ exception
โ โโโ GlobalExceptionHandler.java
โ โโโ UserNotFoundException.java
โ
โโโ jwt
โ โโโ JwtAuthenticationFilter.java
โ โโโ JwtUtil.java
โ
โโโ repository
โ โโโ StakeholderRepository.java
โ
โโโ security
โ โโโ StakeholderUserDetailsService.java
โ
โโโ service
โโโ StakeholderService.java
โโโ StakeholderServiceImpl.java
Client
โ
โ POST /stakeholders/login
โผ
Stakeholder Controller
โ
โผ
Stakeholder Service
โ
โผ
Spring Security Authentication
โ
โผ
JWT Token Generated
โ
โผ
Client
For protected APIs:
Client
โ
โ Authorization: Bearer <JWT>
โผ
JwtAuthenticationFilter
โ
โโโ Extract JWT
โ
โโโ Validate JWT
โ
โโโ Extract User Email
โ
โโโ Load UserDetails
โ
โโโ Set Authentication
โ
โผ
Spring Security
โ
โผ
Controller
| Method | Endpoint | Description |
|---|---|---|
| POST | /stakeholders/register |
Register a new user |
| POST | /stakeholders/login |
Authenticate user and generate JWT |
| Method | Endpoint | Description |
|---|---|---|
| GET | /stakeholders/email/{email} |
Get user by email |
| PUT | /stakeholders/update/{email} |
Update user |
| DELETE | /stakeholders/{email} |
Delete user |
| PUT | /stakeholders/change-password |
Change password |
| Method | Endpoint | Description |
|---|---|---|
| GET | /stakeholders/me |
Get authenticated user's profile |
| PUT | /stakeholders/me |
Update authenticated user's profile |
| Method | Endpoint | Description |
|---|---|---|
| GET | /stakeholders/all |
Get users with pagination and sorting |
| GET | /stakeholders/search |
Search users by firstname |
Successful responses use a common ApiResponse<T> structure.
{
"success": true,
"message": "User retrieved successfully.",
"data": {
"id": 1,
"firstname": "Kunal",
"lastname": "Patil",
"email": "kunal@example.com"
}
}{
"success": false,
"message": "User not found.",
"data": null
}This keeps the API response format consistent for frontend and service consumers.
The service uses a centralized GlobalExceptionHandler.
Currently handled:
| Exception | HTTP Status |
|---|---|
UserNotFoundException |
404 NOT FOUND |
MethodArgumentNotValidException |
400 BAD REQUEST |
Generic Exception |
500 INTERNAL SERVER ERROR |
Validation errors are returned in a structured format:
{
"success": false,
"message": "Validation Failed",
"data": {
"email": "Invalid email format",
"password": "Password must be at least 8 characters"
}
}Administrative operations are protected using Spring Security method-level authorization.
Example:
@PreAuthorize("hasRole('ADMIN')")Therefore, only users with the ADMIN role can access administrative operations such as deleting users.
The /all endpoint supports pagination and sorting.
Example:
GET /stakeholders/all?page=0&size=5&sortBy=firstnameDefault values:
page = 0
size = 5
sortBy = firstname
Users can be searched by firstname.
Example:
GET /stakeholders/search?firstname=KunalThe search uses case-insensitive partial matching.
Example:
Kunal
kunal
KUNAL
can all match the appropriate records.
Swagger UI is available during local development at:
http://localhost:8080/swagger-ui/index.html
Swagger provides an interactive interface for:
- Viewing available APIs
- Viewing request parameters
- Sending API requests
- Testing authentication
- Inspecting responses
- Testing HTTP status codes
The application currently uses MySQL.
Example configuration:
spring.application.name=SalonSphere
spring.datasource.url=jdbc:mysql://localhost:3306/stakeholders_database spring.datasource.username=root spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true
> For deployment, database credentials should be supplied through environment variables rather than committed directly to the repository.
(Currently using Embedded Database - H2 Database)
## โถ๏ธ How to Run
### 1. Clone the repository
```bash
git clone <YOUR_REPOSITORY_URL>
Open the project in:
- IntelliJ IDEA
- Eclipse
- VS Code
- Spring Tool Suite
Create the database:
CREATE DATABASE stakeholders_database;Update the database credentials in:
application.properties
mvn clean install
mvn spring-boot:run
Or run the main Spring Boot application class from your IDE.
http://localhost:8080/swagger-ui/index.html
The APIs can be tested using:
- Swagger UI
- Postman
- IntelliJ HTTP Client
For protected endpoints, first authenticate using:
POST /stakeholders/login
Then use the returned JWT token:
Authorization: Bearer <JWT_TOKEN>
Status: โ Completed
Implemented:
- User registration
- User login
- JWT authentication
- Role-based authorization
- User profile management
- Password change
- User deletion
- Current user API
- Pagination
- Sorting
- Search
- DTOs
- Validation
- Global exception handling
- Standardized API responses
- Controller logging
- Swagger/OpenAPI
Module 1 โ Stakeholder Service โ Module 2 โ Salon Service ๐ Module 3 โ Staff Service Module 4 โ Booking Service Module 5 โ Payment Service Module 6 โ Review Service Module 7 โ Notification Service Module 8 โ API Gateway Module 9 โ Service Discovery Module 10 โ Distributed Tracing Module 11 โ Docker & Deployment
Planned improvements include:
- Refresh token authentication
- Advanced security exception handling
- Unit and integration testing
- Service-to-service communication
- API Gateway
- Eureka Service Discovery
- Redis caching
- Circuit Breaker
- Distributed tracing
- Docker containerization
- CI/CD
- Cloud deployment
Technologies: Java | Spring Boot | Spring Security | JWT REST APIs | JPA | Hibernate | MySQL React | Angular | Microservices
This project is developed for learning, portfolio development, and demonstrating practical Spring Boot and microservices development.