sequenceDiagram
autonumber
participant Browser as Web Browser Client
participant Tomcat as Servlet Container (Tomcat)
participant SecChain as Spring Security Filter Chain
participant DS as DispatcherServlet
participant Controller as StaffAdministrationController
participant Service as EmployeeServiceImpl
participant Repo as EmployeeRepository
participant DB as MySQL Database
participant View as Thymeleaf Engine
Note over Browser,DB: Phase 1: Mutating Submission (POST)
Browser->>Tomcat: POST /staff/save (Employee Form Data + _csrf)
Tomcat->>SecChain: Execute Filter Chain
SecChain->>SecChain: CsrfFilter validates _csrf token (OK)
SecChain->>SecChain: AuthorizationFilter verifies ROLE_MANAGER (OK)
SecChain->>DS: Delegate to DispatcherServlet
DS->>Controller: saveEmployee(theEmployee)
Controller->>Service: save(theEmployee)
Service->>Repo: save(theEmployee)
Repo->>DB: Executes SQL INSERT or UPDATE
DB-->>Repo: Saved Entity with ID
Repo-->>Service: Employee Entity
Service-->>Controller: Return Employee
Controller-->>DS: Return redirect to /staff/list
DS-->>Tomcat: Issue HTTP 302 Redirect (Location: /staff/list)
Tomcat-->>Browser: HTTP 302 Found
Note over Browser,DB: Phase 2: Idempotent Fetch (GET)
Browser->>Tomcat: GET /staff/list (Follows Redirect)
Tomcat->>SecChain: Execute Filter Chain
SecChain->>SecChain: AuthorizationFilter verifies ROLE_EMPLOYEE (OK)
SecChain->>DS: Delegate to DispatcherServlet
DS->>Controller: listEmployees(theModel)
Controller->>Service: findAll()
Service->>Repo: findAllByOrderByLastNameAsc()
Repo->>DB: Executes SELECT * FROM employee ORDER BY lastName ASC
DB-->>Repo: List of Employees
Repo-->>Service: List of Employees
Service-->>Controller: Return List
Controller->>Controller: theModel.addAttribute("employees", list)
Controller-->>DS: Return logical view name staff/staff-list
DS->>View: Render "staff/staff-list" with Model
View->>View: Evaluate sec:authorize and inject data
View-->>Tomcat: Rendered HTML Response Stream
Tomcat-->>Browser: HTTP 200 OK (Content-Type: text/html)
3. Form Login Authentication Filter Execution Flow¶
sequenceDiagram
autonumber
participant Browser as Web Browser Client
participant Tomcat as Tomcat Container
participant UPAF as UsernamePasswordAuthenticationFilter
participant AM as ProviderManager (AuthenticationManager)
participant DaoProvider as DaoAuthenticationProvider
participant UserStore as JdbcUserDetailsManager
participant Encoder as BCryptPasswordEncoder
participant SessionStrategy as SessionAuthenticationStrategy
Browser->>Tomcat: POST /authenticate (username='mary', password='fun123', _csrf)
Tomcat->>UPAF: Intercepts POST to loginProcessingUrl
UPAF->>UPAF: Extracts username & password parameters
UPAF->>AM: authenticate(UsernamePasswordAuthenticationToken)
AM->>DaoProvider: authenticate(authentication)
DaoProvider->>UserStore: loadUserByUsername("mary")
UserStore-->>DaoProvider: UserDetails (username='mary', passwordHash='{bcrypt}$2a$...', roles)
DaoProvider->>Encoder: matches("fun123", passwordHash)
Encoder->>Encoder: Computes BCrypt hash with stored salt
Encoder-->>DaoProvider: Matches (true)
DaoProvider-->>AM: Fully Populated Authentication Token
AM-->>UPAF: Authentication Success
UPAF->>SessionStrategy: onAuthentication (Prevent Session Fixation)
UPAF->>UPAF: Store SecurityContext in HttpSession
UPAF-->>Tomcat: HTTP 302 Redirect to defaultSuccessUrl (/staff/list)
Tomcat-->>Browser: HTTP 302 Found (Set-Cookie: JSESSIONID=...)
4. Architectural Comparison: HTTP Basic vs Form-Based Authentication¶
Dimension
HTTP Basic Authentication
Form-Based Authentication
Primary Architecture
Stateless REST APIs / Microservices
Stateful Server-Side Rendered Web Portals
User Interface
Unstyled, browser-native pop-up modal
Custom branded HTML / CSS (Bootstrap 5)
Session Model
Stateless (STATELESS session creation)
Stateful (IF_REQUIRED or ALWAYS session creation)
Credential Lifetime
Transmitted on every single HTTP request
Transmitted once during login; session cookie thereafter
@BeanpublicUserDetailsManageruserDetailsManager(DataSourcedataSource){JdbcUserDetailsManagerjdbcUserDetailsManager=newJdbcUserDetailsManager(dataSource);// Exact 3-column projection contractjdbcUserDetailsManager.setUsersByUsernameQuery("select user_id, pw, active from members where user_id=?");// Exact 2-column projection contractjdbcUserDetailsManager.setAuthoritiesByUsernameQuery("select user_id, role from roles where user_id=?");returnjdbcUserDetailsManager;}