A Spring Boot REST API for user registration and authentication with JWT tokens.
- User registration and login
- JWT authentication
- Role-based access control (USER, ADMIN, MODERATOR)
- MySQL database integration
- Docker support
- Swagger API documentation
- Health check endpoints
- Java 17
- Spring Boot 3.2.0
- Spring Security
- Spring Data JPA
- MySQL 8.0
- JWT (jsonwebtoken)
- Docker
- Maven
- Java 17
- Maven 3.6+
- MySQL 8.0 (or use Docker)
-
Clone the repository
-
Build the project:
mvn clean package
-
Run with H2 database (for testing):
java -jar target/user-registration-service-1.0.0.jar --spring.profiles.active=test
-
Or run with Docker:
docker-compose up -d
Once the application is running, access Swagger UI at:
http://localhost:8989/swagger-ui.html
The application comes with pre-configured users:
- Admin: username=
admin
, password=admin123
- User: username=
user
, password=user123
POST /api/v1/auth/register
- Register new userPOST /api/v1/auth/login
- User loginPOST /api/v1/auth/refresh
- Refresh JWT token
GET /api/v1/users/profile
- Get user profileGET /api/v1/users
- List all users (Admin only)PUT /api/v1/users/{id}
- Update user (Admin only)
GET /api/v1/health
- Health check
Variable | Description | Default |
---|---|---|
SPRING_PROFILES_ACTIVE |
Active profile (dev/test/prod) | - |
DATABASE_URL |
Database URL | jdbc:mysql://localhost:3306/user_registration_db |
DATABASE_USERNAME |
Database username | root |
DATABASE_PASSWORD |
Database password | root123 |
JWT_SECRET |
JWT secret key | - |
test
- H2 in-memory databasedev
- MySQL with development settingsprod
- MySQL with production settings
# Start application with MySQL
docker-compose up -d
# View logs
docker-compose logs -f app
# Stop services
docker-compose down
docker build -t user-registration-service .
Run tests:
mvn test
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.