SPRING SECURITY / 05

Sequence and class diagrams

The actual flow illustrated. No Mermaid loading or Internet connection is required.

How to read a sequence

Each column represents a participant; time flows downwards. Numbered arrows show calls and responses on the success path. Internal library steps are grouped for readability. Errors stop the flow before the success response.

1. Login

Login sequence
Credential authentication with DaoAuthenticationProvider, BCrypt and HS256 issuance. Click to enlarge the SVG.

If the account does not exist, is disabled or its password does not match, 401 is returned and no JWT is issued. Notice that the controller reloads AppUser after authenticate to issue the response.

2. Registration

Public registration sequence
The DTO has no role and the controller builds AppUser with USER. Click to enlarge the SVG.

Input validation may return 400. Duplicate detection or the database unique constraint may result in 409. saveAndFlush obtains the id before constructing sub.

3. Protected request

Protected request sequence
The signature is checked before querying the role; /me obtains the profile through the service. Click to enlarge the SVG.

Missing or invalid JWT: 401. Disabled or deleted account: 401. Valid USER identity on an ADMIN route: 403, without running the controller. The diagram shows /me, which accepts both roles.

4. Administrative editing

ADMIN editing sequence
Filters check the role; UserService checks rules concerning the acting account. Click to enlarge the SVG.

Editing occurs within the service transaction. The edited account's JWT does not change: its next request reads the new role from the database. Input validation occurs when the controller resolves @Valid.

5. Class diagram

Backend class diagram
Arrow = dependency or use; secondary methods and getters are omitted for readability. Click to enlarge the SVG.

AuthController also depends on AuthenticationManager, UserRepository and PasswordEncoder; UserService uses PasswordEncoder for account creation and password changes. SecurityConfig declares those beans and the JWT converter, which also uses the repository. Spring Data implements UserRepository at runtime; the project has no handwritten repository class.

AppUser is transformed into UserResponse; AuthResponse contains a UserResponse. Requests and responses are DTOs, not database entities. GlobalExceptionHandler translates exceptions into ApiError. The diagram groups infrastructure and DTOs to show key relationships without inventorying the entire Spring library.

CV & portfolio · ES / EN
EspañolEnglish