A secure, token-based file sharing system built with Spring Boot, JWT authentication, AES encryption, and role-based access control. Users can upload, download, and share files using one-time access tokens.
- ✅ Secure file upload & download
- 🔑 JWT-based authentication
- 🔐 AES encryption for file storage
- 🧑 Role-based access control (USER / ADMIN)
- 🔗 One-time share token generation
- 🧪 JUnit + Mockito unit tests
- 🐳 Dockerized for easy deployment
- Java 17 + Spring Boot 3
- Spring Security 6
- JWT (JSON Web Tokens)
- AES (Advanced Encryption Standard)
- JPA PostgreSQL
- Maven
- Docker & Docker Compose
- Java 17+
- Maven
- Docker (optional)
- Git
git clone "your-repo"
cd "your-repo"
./mvnw spring-boot:run# Start the app
docker compose -f docker-compose.yml up -d
# Stop it
docker compose -f docker-compose.yml down📝 Ensure .env is present with your SECRET_KEY and other configs.
All secured endpoints require a JWT in the Authorization header.
🔐 Endpoints
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/auth/register | Public | Register new user |
| POST | /api/auth/login | Public | Login and receive JWT |
| GET | /api/users/protected | Admin only | Admin-protected sample endpoint |
📁 File Management
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/files/upload | Authenticated | Upload a file |
| GET | /api/files/my | Authenticated | List user's uploaded files |
| GET | /api/files/download/{id} | Authenticated | Download user's own file |
🔗 Share Token System
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/token/generate | Authenticated | Generate one-time token for own file |
| GET | /api/token/download/{token} | Public | Download shared file using token |
Run all unit tests with:
./mvnw test-
Tested using JUnit 5, Mockito, and MockMvc
-
Includes controller and service tests
-
Mocked JWT and Authentication behavior
Create a .env file in your project root with:
SECRET_KEY=your-super-secret-keyLoaded with dotenv-java
MIT – Feel free to use, modify, and share.