A secure Spring Boot REST API for managing tasks with authentication and role-based access control.
This project demonstrates how to build a secure backend system with:
• Spring Boot
• Spring Security
• PostgreSQL
• Layered Architecture
Think of it as the backend engine of a productivity app where users manage tasks while admins control task operations.
🔐 Secure authentication with Spring Security
👤 User registration with encrypted passwords
📋 Task creation, update, deletion and retrieval
📊 Pagination support for task listing
🔎 Task filtering by status and priority
🛡 Role-based authorization (ADMIN / USER)
⚠ Centralized exception handling
🗄 PostgreSQL database persistence
| Technology | Purpose |
|---|---|
| ☕ Java | Programming language |
| 🌱 Spring Boot | Backend framework |
| 🔐 Spring Security | Authentication & authorization |
| 🗃 Spring Data JPA | Database access |
| 🐘 PostgreSQL | Database |
| 📦 Maven | Dependency management |
The backend follows a layered architecture to maintain separation of concerns.
flowchart LR
Client --> Controller
Controller --> Service
Service --> Validator
Service --> Repository
Repository --> Database
Handles incoming HTTP requests and returns responses.
Example:
TaskManagerController
Contains the core business logic.
Example:
TaskManagerService
Handles input validation and business rules.
Example:
TaskManagerValidator
Handles database operations using Spring Data JPA.
Example:
TaskRepository
Stores users and tasks in PostgreSQL.
task-manager
│
├── controller
│ └── TaskManagerController.java
│
├── service
│ └── TaskManagerService.java
│
├── validator
│ └── TaskManagerValidator.java
│
├── repository
│ ├── TaskRepository.java
│ └── UserRepository.java
│
├── security
│ ├── SecurityConfig.java
│ └── CustomUserDetailsService.java
│
├── exception
│ └── GlobalExceptionHandler.java
│
├── model
│ ├── Task.java
│ ├── User.java
│ └── Status.java
│
└── TaskManagerApplication.java
Each task can have one of the following statuses:
RUNNING
SUSPENDED
TERMINATED
| Method | Endpoint | Description |
|---|---|---|
| POST | /register | Register a new user |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /tasks | ADMIN | Create a task |
| GET | /tasks?page=&size= | ADMIN, USER | View paginated tasks |
| GET | /tasks/{pid} | ADMIN, USER | View task by PID |
| PATCH | /tasks/{pid} | ADMIN | Update task |
| DELETE | /tasks/{pid} | ADMIN | Delete task |
| Method | Endpoint |
|---|---|
| GET | /tasks/filter?status=&priority= |
Allows filtering tasks by:
• status
• priority
| Method | Endpoint |
|---|---|
| GET | /admin/test |
| GET | /deleteTest |
Used to test role-based access control.
POST /register
Content-Type: application/json
{
"username": "cos",
"password": "12345"
}
POST /tasks
Authorization: Basic Auth
Content-Type: application/json
{
"name": "Complete backend project",
"priority": 1,
"status": "RUNNING"
}
GET /tasks?page=0&size=5
GET /tasks/filter?status=RUNNING
or
GET /tasks/filter?priority=2
git clone https://github.com/yourusername/task-manager-backend.git
cd task-manager-backend
Update application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/taskdb
spring.datasource.username=youruser
spring.datasource.password=yourpassword
mvn spring-boot:run
Server will start at
http://localhost:8080
Use Postman or any REST client.
Typical workflow:
1️⃣ Register a user
2️⃣ Login using form authentication
3️⃣ Use APIs to create and manage tasks
🚀 JWT authentication
📄 Swagger API documentation
🐳 Docker containerization
📊 Task analytics dashboard
📧 Email notifications
✔ Secure REST API development with Spring Boot
✔ Authentication and authorization with Spring Security
✔ Database design using JPA
✔ Pagination and filtering in REST APIs
✔ Layered backend architecture
⭐ If you like this project, consider giving it a star.