A modern and secure user management system REST API built with Spring Boot 3, Spring Security, JWT authentication, and PostgreSQL.
API Documentation - All endpoints can be tested interactively
User registration with access token and refresh token
Token refresh with rotation - old token revoked, new tokens issued
Password reset token generation
Authenticated user changing password
User deactivating their own account
- Java 17 - LTS version
- Spring Boot 3.3.7 - Latest stable version
- Spring Security - Authentication & Authorization
- JWT (JSON Web Token) - Token-based authentication
- Spring Data JPA - Database operations
- PostgreSQL 16 - Relational database
- Redis 7 - In-memory caching
- Docker & Docker Compose - Containerization
- Swagger/OpenAPI - API Documentation
- JUnit 5 & Mockito - Testing
- BCrypt - Password encryption
- Bucket4j - Rate limiting
- JavaMailSender - Email (Gmail SMTP)
- Spring AOP - Audit logging
- TOTP (dev.samstevens.totp) - Two-Factor Authentication
- β JWT-based authentication
- β BCrypt password encryption
- β Role-based access control (USER, ADMIN)
- β RESTful API endpoints
- β Global exception handling
- β Input validation
- β Swagger UI documentation
- β Unit & Integration tests
- β Docker support
- β Change password functionality
- β Account deactivation (soft delete)
- β Password reset with token
- β Refresh token mechanism with rotation
- β Email verification (Gmail SMTP)
- β Rate limiting (Bucket4j - IP based)
- β Redis caching (5-minute TTL)
- β Audit logging with Spring AOP
- β Login success/failure tracking with IP address
- β Admin audit log endpoints
- β Two-Factor Authentication (TOTP/Google Authenticator)
- β QR code generation for authenticator apps
- β 2FA enable/disable/validate endpoints
- User Profile Management (GET/PUT /api/users/me)
- firstName, lastName, bio, phoneNumber fields
- Full profile response with 2FA and email verification status
- β
Pagination for user listing (
GET /api/users/paged) - β Filtering by active status, email, role
- β Sorting by any field (asc/desc)
- β Page metadata (totalPages, totalElements, currentPage)
src/
βββ main/
β βββ java/com/backend/usermanagement/
β β βββ config/ # Configuration classes
β β βββ controller/ # REST Controllers
β β βββ domain/entity/ # JPA Entities
β β βββ dto/ # Data Transfer Objects
β β βββ exception/ # Exception handling
β β βββ repository/ # JPA Repositories
β β βββ security/ # Security, JWT & AOP
β β βββ service/ # Business logic
β βββ resources/
β βββ application.properties
βββ test/ # Test classes
- Java 17+
- Maven 3.6+
- Docker & Docker Compose
git clone https://github.com/EagleSoft461/user-management-api.git
cd user-management-api# Create .env file or set system variables
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-passworddocker-compose up -d./mvnw spring-boot:runThe application will start at http://localhost:8081
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /auth/register |
Register new user | β |
| POST | /auth/login |
User login | β |
| POST | /auth/refresh |
Refresh access token | β |
| POST | /auth/forgot-password |
Request password reset | β |
| POST | /auth/reset-password |
Reset password with token | β |
| GET | /auth/verify-email |
Verify email with token | β |
| POST | /auth/resend-verification |
Resend verification email | β |
| POST | /auth/2fa/setup |
Setup 2FA - get QR code | β USER |
| POST | /auth/2fa/verify |
Enable 2FA with code | β USER |
| POST | /auth/2fa/validate |
Login with 2FA code | β |
| POST | /auth/2fa/disable |
Disable 2FA | β USER |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/users |
List all users | β ADMIN |
| GET | /api/users/paged |
List users with pagination & filtering | β ADMIN |
| GET | /api/users/{id} |
Get user details | β ADMIN |
| DELETE | /api/users/{id} |
Deactivate user | β ADMIN |
| PUT | /api/users/{id}/roles/{roleName} |
Add role to user | β ADMIN |
| POST | /api/users/change-password |
Change password | β USER |
| POST | /api/users/deactivate |
Deactivate own account | β USER |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/admin/audit-logs |
All audit logs | β ADMIN |
| GET | /api/admin/audit-logs/failed |
Failed operations only | β ADMIN |
| GET | /api/admin/audit-logs/user/{email} |
Logs by user | β ADMIN |
Swagger UI: http://localhost:8081/swagger-ui.html
OpenAPI Docs: http://localhost:8081/v3/api-docs
- Register: Send email and password to
/auth/register - Login: Send credentials to
/auth/login - Token: Receive JWT token in response
- Authorization: Add token to header for protected endpoints:
Authorization: Bearer <your-jwt-token>
curl -X POST http://localhost:8081/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'curl -X POST http://localhost:8081/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'curl -X GET "http://localhost:8081/api/users/paged?page=0&size=10&sortBy=createdAt&sortDir=desc&active=true" \
-H "Authorization: Bearer <your-jwt-token>"curl -X POST http://localhost:8081/api/users/change-password \
-H "Authorization: Bearer <your-jwt-token>" \
-H "Content-Type: application/json" \
-d '{
"currentPassword": "password123",
"newPassword": "newPassword456",
"confirmPassword": "newPassword456"
}'curl -X POST http://localhost:8081/api/users/deactivate \
-H "Authorization: Bearer <your-jwt-token>" \
-H "Content-Type: application/json" \
-d '{
"password": "password123"
}'curl -X POST http://localhost:8081/auth/forgot-password \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com"
}'curl -X POST http://localhost:8081/auth/reset-password \
-H "Content-Type: application/json" \
-d '{
"token": "reset-token-from-email",
"newPassword": "newPassword456",
"confirmPassword": "newPassword456"
}'curl -X POST http://localhost:8081/auth/refresh \
-H "Content-Type: application/json" \
-d '{
"refreshToken": "your-refresh-token"
}'# Run all tests
./mvnw test
# Run specific test class
./mvnw test -Dtest=UserServiceTest- id (PK)
- email (unique)
- password (encrypted)
- is_active
- email_verified
- two_factor_enabled
- two_factor_secret
- created_at
- id (PK)
- name (unique)
- user_id (FK)
- role_id (FK)
- id (PK)
- user_email
- action
- success
- ip_address
- details
- timestamp
- Passwords are hashed with BCrypt
- JWT tokens are valid for 24 hours
- Role-based authorization
- Rate limiting: 5 req/min (login), 3 req/min (register/forgot-password), 30 req/min (general)
- Email verification required after registration
- All sensitive operations are audit logged
- Optional Two-Factor Authentication (TOTP)
User data is cached in Redis with a 5-minute TTL:
GET /api/usersβ full list cachedGET /api/users/{id}β per-user cache with keyusers::{id}- Cache is automatically evicted on any write operation
# Start PostgreSQL + Redis
docker-compose up -d
# Stop services
docker-compose down
# Remove data volumes
docker-compose down -v# Create JAR file
./mvnw clean package
# Run JAR
java -jar target/usermanagement-0.0.1-SNAPSHOT.jar# Database
SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/userdb
SPRING_DATASOURCE_USERNAME=admin
SPRING_DATASOURCE_PASSWORD=admin
# JWT
JWT_SECRET=your-secret-key
JWT_EXPIRATION=86400000
# Email (Gmail SMTP)
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
# Redis
SPRING_DATA_REDIS_HOST=localhost
SPRING_DATA_REDIS_PORT=6379- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- JWT authentication
- Role-based access control
- Change password & account deactivation
- Password reset & refresh token
- Email verification
- Rate limiting
- Redis caching
- Audit logging
- Two-Factor Authentication (2FA)
- Pagination & Filtering
- User profile management
- API versioning
See our detailed ROADMAP.md for planned features and timeline.
This project is licensed under the MIT License - see the LICENSE file for details.
EagleSoft461
- GitHub: @EagleSoft461
- LinkedIn: ALΔ° ORHAN OK
- Email: aliorhanok78@gmail.com
- Spring Boot Team
- Spring Security Team
- JWT.io
- PostgreSQL Community
For support, email aliorhanok78@gmail.com or open an issue in the repository.
β If you find this project useful, please consider giving it a star!

