Skip to content

feat: add RBAC with role-based endpoint protection and controller refactor - #42

Open
exeaman wants to merge 3 commits into
hoangsonww:masterfrom
exeaman:feat/rbac-basic
Open

feat: add RBAC with role-based endpoint protection and controller refactor#42
exeaman wants to merge 3 commits into
hoangsonww:masterfrom
exeaman:feat/rbac-basic

Conversation

@exeaman

@exeaman exeaman commented Apr 20, 2026

Copy link
Copy Markdown

Overview

This pull request introduces Role-Based Access Control (RBAC) using Spring Security and refactors controllers by moving business logic to the service layer.

The goal is to improve security, maintainability, and align the codebase with standard backend design practices without breaking existing API contracts.


Related Issue/Ticket

N/A (feature enhancement)


Files Changed

Security

  • SecurityConfig.java
  • CustomUserDetailsService.java
  • JwtRequestFilter.java

Controllers

  • AuthController.java
  • DepartmentController.java
  • EmployeeController.java

Services

  • AuthService.java
  • DepartmentService.java
  • EmployeeService.java

DTOs

  • AssignRoleRequestDto.java
  • UserResponseDto.java

Documentation

  • README.md (updated with RBAC usage and authentication flow)

Testing

  • Verified endpoints using Swagger and Postman
  • Tested JWT authentication flow:
    • Register → Authenticate → Access protected endpoints
  • Tested RBAC behavior:
    • ADMIN → full access (create/update/delete)
    • MANAGER → limited update access
    • EMPLOYEE → read-only access
  • Verified error handling:
    • 401 Unauthorized (invalid credentials)
    • 403 Forbidden (insufficient permissions)
    • 404 Not Found
    • 409 Conflict (duplicate user, invalid operations)

Screenshots (if applicable)

N/A (Backend changes only)


Notes to Reviewers

  • RBAC is implemented using @PreAuthorize with role-based authorities
  • Role is stored in the users table and enforced at the controller level
  • Added endpoint for ADMIN to assign roles to users
  • Business logic has been moved from controllers to service layer
  • Existing API endpoints, request/response structure, and status codes are preserved to avoid breaking changes
  • Addressed review feedback:
    • Added duplicate user check during registration
    • Improved authentication error handling
    • Removed redundant controller logic

Deployment Notes

  • No additional deployment steps required
  • Ensure JWT secret and database configuration are properly set

@vercel

vercel Bot commented Apr 20, 2026

Copy link
Copy Markdown

@exeaman is attempting to deploy a commit to the dav nguyen's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify

netlify Bot commented Apr 20, 2026

Copy link
Copy Markdown

Deploy Preview for employee-management-fullstack-system canceled.

Name Link
🔨 Latest commit 33fa44d
🔍 Latest deploy log https://app.netlify.com/projects/employee-management-fullstack-system/deploys/69e68adf86f0eb00082b77a3

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements Role-Based Access Control (RBAC) and refactors the backend architecture by delegating business logic from controllers to service components. Key changes include the integration of JWT-based security, role-based endpoint authorization, and new administrative user management features. Review feedback highlights several improvement opportunities, such as aligning exception types in the authentication service with the global handler, further simplifying controllers by delegating logic, eliminating redundant entity lookups, and adding necessary validation to request DTOs to ensure robustness.

@exeaman exeaman left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The basic RBAC implementation has been done along with some architectural improvements in MVC layers.

@hoangsonww hoangsonww added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested java Pull requests that update Java code labels Apr 20, 2026
@hoangsonww hoangsonww added this to the v2.x.x - Stable Release milestone Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed java Pull requests that update Java code question Further information is requested

Projects

Development

Successfully merging this pull request may close these issues.

2 participants