Spring Boot

Spring Security Basics

Spring Security, authentication, authorization, SecurityFilterChain, UserDetailsService, PasswordEncoder

25 câu hỏi phỏng vấn·
Mid-Level
1

What is Spring Security?

Câu trả lời

Spring Security is a security framework for Spring applications that provides authentication and authorization features. It protects applications against common attacks (CSRF, XSS, session fixation) and offers integration with various authentication mechanisms (form login, HTTP Basic, OAuth2, JWT). The framework uses a filter chain (Security Filter Chain) to intercept and process HTTP requests before they reach controllers.

2

What is the difference between authentication and authorization in Spring Security?

Câu trả lời

Authentication verifies user identity (who are you?), typically via username/password, while authorization verifies permissions (what can you do?). Authentication happens first and creates a SecurityContext with user information. Authorization then uses this information to decide if the user can access a specific resource. For example, a user can be successfully authenticated but not authorized to access /admin if their role is USER and not ADMIN.

3

What is the SecurityContext in Spring Security?

Câu trả lời

The SecurityContext is an object that contains the security information of the currently authenticated user, primarily the Authentication object. It is stored in the SecurityContextHolder and accessible throughout request processing. After successful authentication, Spring Security creates a SecurityContext containing an Authentication with user details (username, authorities, credentials). This context allows the application to check who the current user is and what their permissions are.

4

How does SecurityContextHolder store the SecurityContext by default?

5

What is the role of the UserDetails interface in Spring Security?

+22 câu hỏi phỏng vấn

Nắm vững Spring Boot cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí