4. Spring Security Flashcards
(74 cards)
What is Spring Security?
Spring Security is a powerful and customizable authentication and access control framework for Java applications, particularly those built using the Spring framework.
True or False: Spring Security is only used for authentication.
False. Spring Security provides both authentication and authorization features.
What are the core components of Spring Security?
The core components of Spring Security include Authentication, Authorization, Security Context, Filters, and Security Interceptors.
Fill in the blank: Spring Security provides _____ for securing web applications.
authentication and authorization
What is the purpose of the SecurityContextHolder?
The SecurityContextHolder stores the security context, which contains the authentication details of the currently authenticated user.
What is a UserDetailsService?
UserDetailsService is an interface in Spring Security that is used to retrieve user-related data, typically for authentication purposes.
How can you secure a REST API using Spring Security?
You can secure a REST API using Spring Security by configuring HTTP security to require authentication for certain endpoints and using JWT or OAuth2 for token-based authentication.
What is CSRF and how does Spring Security handle it?
CSRF stands for Cross-Site Request Forgery. Spring Security provides built-in protection against CSRF attacks by requiring a CSRF token for state-changing requests.
What is the purpose of the @EnableWebSecurity annotation?
The @EnableWebSecurity annotation is used to enable Spring Security’s web security support and provide the Spring MVC integration.
What role does the AuthenticationManager play in Spring Security?
The AuthenticationManager is responsible for processing authentication requests and returning an Authentication object if the credentials are valid.
Multiple choice: Which of the following is a valid way to configure HTTP security in Spring Security? (A) Using XML configuration (B) Using Java configuration (C) Both A and B
C) Both A and B
What is the difference between Authentication and Authorization?
Authentication is the process of verifying the identity of a user, while Authorization determines what an authenticated user is allowed to do.
True or False: Spring Security supports method-level security.
True. Spring Security provides annotations like @PreAuthorize and @Secured for method-level security.
What is the role of a Filter in Spring Security?
Filters in Spring Security are used to intercept requests and responses, allowing for operations like authentication and authorization to occur.
What is the purpose of the @PreAuthorize annotation?
The @PreAuthorize annotation is used to specify method-level security by allowing access based on the evaluation of an expression.
Fill in the blank: Spring Security uses _____ to generate secure tokens for stateless authentication.
JWT (JSON Web Tokens)
What is a Security Filter Chain?
A Security Filter Chain is a sequence of filters that Spring Security applies to incoming requests, allowing for various security checks.
What is the role of the PasswordEncoder in Spring Security?
PasswordEncoder is an interface that provides methods for encoding and verifying passwords securely.
Multiple choice: Which of the following protocols can Spring Security support for OAuth? (A) OAuth 1.0 (B) OAuth 2.0 (C) Both A and B
B) OAuth 2.0
What is the purpose of the @Secured annotation?
The @Secured annotation is used to specify the roles that are allowed to execute a particular method.
True or False: Spring Security can be integrated with other frameworks like JPA and Hibernate.
True. Spring Security can be integrated with various frameworks to enhance security in applications.
What is the default login page provided by Spring Security?
The default login page provided by Spring Security is a simple HTML form that prompts for a username and password.
What is the use of the SecurityConfigurerAdapter?
SecurityConfigurerAdapter is a base class that allows developers to customize the security configuration by overriding methods.
Fill in the blank: In Spring Security, the _____ interface is used to represent the authentication token.
Authentication