Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 43

    Role-Based Access Control

    RBAC = permissions tied to roles, roles tied to users.

    Course progress0%
    Focus
    3 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    RBAC = permissions tied to roles, roles tied to users. USER reads their data; ADMIN manages everyone; AUDITOR reads but never writes.

    Informative example

    bash
    # users
    id email ...
    1 ana@acme.com
    2 bob@acme.com
    # roles
    id name
    1 USER
    2 ADMIN
    # user_roles (many-to-many)
    user_id role_id
    1 1
    2 1
    2 2
    // Endpoint
    @PreAuthorize("hasRole('ADMIN')")
    @DeleteMapping("/{id}") public void delete(@PathVariable Long id) { ... }

    Best practices

    • Store roles in their own table — never as a CSV column.
    • Prefix authorities with ROLE_; Spring strips it for hasRole(...).
    • For fine-grained needs (per-resource), graduate to ABAC / policies.
    Ready to mark this lesson complete?Track your journey across the entire course.