Authentication (xác thực): "Bạn là ai?" — verify identity (login mật khẩu, JWT, OAuth). Authorization (phân quyền): "Bạn được phép làm gì?" — check permission (role, scope). Authentication luôn xảy ra trước Authorization.
Trong Spring Security:
- Authentication: implement UserDetailsService.loadUserByUsername() trả về UserDetails (username, password hash, danh sách authority) — Spring so credential và dựng Authentication object.
- Authorization: rule theo URL qua authorizeHttpRequests — hasRole("ADMIN"), authenticated(), permitAll() cho từng pattern; hoặc theo method qua @PreAuthorize (xem câu method-level security).
- Sau khi xác thực thành công, SecurityContextHolder giữ Authentication (user info, roles) cho thread hiện tại — mọi check phân quyền phía sau đọc từ đây.