Spring Security is one of the most powerful modules in the Spring ecosystem, designed to provide comprehensive security features for Java applications. From authentication to authorization, CSRF protection to OAuth2, Spring Security handles it all. This MCQ guide will help you gauge your understanding and enhance your knowledge of Spring Security.
Note that each MCQ question is followed by the correct answer and an explanation to help reinforce your knowledge.
1. What does Spring Security primarily offer?
Answer:
Explanation:
Spring Security primarily provides comprehensive security features for authentication and authorization in applications.
2. What is the primary responsibility of Spring Security's Authentication mechanism?
Answer:
Explanation:
Authentication is the process of confirming the user's identity. It ensures that the user is who they claim to be.
3. Which component in Spring Security holds the information about a user's granted authorities?
Answer:
Explanation:
The Authentication object holds the principal (user) details and its granted authorities.
4. In Spring Security, what is the main difference between authentication and authorization?
Answer:
Explanation:
Authentication confirms user identity, while authorization defines the actions or resources an authenticated user can access.
5. Which filter is central to Spring Security's filter chain?
Answer:
Explanation:
FilterChainProxy is the core component that manages the security filter chain in Spring Security.
6. Which annotation is used to enable method-level security?
Answer:
Explanation:
The @EnableMethodSecurity annotation is used to enable method-level security annotations.
7. Which interface is primarily responsible for loading UserDetails by its username in Spring Security?
Answer:
Explanation:
The UserDetailsService interface is designed to load user-specific data by its username.
8. In Spring Security, which class is a principal UserDetails implementation?
Answer:
Explanation:
The User class is a principal implementation of the UserDetails interface provided by Spring Security.
9. Which annotation secures a method and restricts it to specific roles?
Answer:
Explanation:
The @PreAuthorize annotation is used to secure methods based on role or other access-control expressions.
10. By default, which URL is used for the Spring Security login page?
Answer:
Explanation:
By default, Spring Security provides a basic login page accessible via the /login URL.
11. What does CSRF stand for in Spring Security?
Answer:
Explanation:
CSRF stands for Cross-Site Request Forgery, a type of attack that tricks users into performing unintended actions.
12. Which filter in Spring Security handles logout functionality?
Answer:
Explanation:
The LogoutFilter provides logout capabilities in Spring Security.
13. In which module is the OAuth2 support provided in Spring Security?
Answer:
Explanation:
Spring Security provides OAuth2 support through the Spring Security OAuth2 module.
14. Which class represents the currently authenticated user in Spring Security?
Answer:
Explanation:
The Authentication class represents the currently authenticated user in Spring Security.
15. What default role prefix does Spring Security use?
Answer:
Explanation:
By default, Spring Security uses the ROLE_ prefix for roles.
16. Which of the following is NOT an authentication provider in Spring Security?
Answer:
Explanation:
There's no SessionAuthenticationProvider in Spring Security.
17. Which Spring Security filter is responsible for processing user authentication?
Answer:
Explanation:
The UsernamePasswordAuthenticationFilter processes authentication requests based on username and password.
18. How does Spring Security handle authorization aspects for web requests?
Answer:
Explanation:
Spring Security uses a chain of filters to handle the authorization aspects for web requests.
19. Which annotation checks if a user is authenticated before accessing a method?
Answer:
Explanation:
The @Secured annotation ensures that a user is authenticated before accessing the annotated method.
20. Which class in Spring Security is used to hash passwords?
Answer:
Explanation:
The PasswordEncoder interface in Spring Security provides mechanisms to hash passwords.
21. Which of the following is a default filter used for form-based authentication in Spring Security?
Answer:
Explanation:
The UsernamePasswordAuthenticationFilter is used for form-based authentication to process the submission of the login form.
22. In Spring Security, which authentication method sends credentials with every HTTP request?
Answer:
Explanation:
Basic authentication sends the username and password with every HTTP request, encoded in the header.
23. What does the ROLE_ANONYMOUS in Spring Security represent?
Answer:
Explanation:
ROLE_ANONYMOUS represents users that have not authenticated but are accessing public or permitted resources.
24. What mechanism does form-based authentication in Spring Security typically use to remember the authenticated user across multiple requests?
Answer:
Explanation:
Form-based authentication usually relies on HTTP sessions to remember the authenticated user across requests.
25. Which Spring Security filter is responsible for processing authentication for HTTP Basic Authentication?
Answer:
Explanation:
The BasicAuthenticationFilter processes the authentication request for HTTP Basic Authentication.
Related Spring MCQ Posts
- Spring IOC Container MCQ - Multiple Choice Questions and Answers
- Spring Dependency Injection MCQ - Multiple Choice Questions and Answers
- Spring Beans MCQ - Multiple Choice Questions and Answers
- Spring Configuration MCQ - Multiple Choice Questions and Answers
- Spring AOP MCQ - Multiple Choice Questions and Answers
- Spring JDBC MCQ - Multiple Choice Questions and Answers
- Spring Data MCQ - Multiple Choice Questions and Answers
- Spring Messaging MCQ - Multiple Choice Questions and Answers
- Spring Batch MCQ - Multiple Choice Questions and Answers
- Spring WebFlux MCQ - Multiple Choice Questions and Answers
- Spring Testing Quiz - MCQ - Multiple Choice Questions
- Spring Security Quiz - MCQ - Multiple Choice Questions
Comments
Post a Comment
Leave Comment