Spring Security Quiz - MCQ - Multiple Choice Questions


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?

a) Web Design Templates
b) Database Connectivity
c) Authentication and Authorization
d) RESTful Services

2. What is the primary responsibility of Spring Security's Authentication mechanism?

a) Enforcing HTTPS
b) Confirming user identity
c) Managing database connections
d) Logging application events

3. Which component in Spring Security holds the information about a user's granted authorities?

a) UserDetails
b) GrantedAuthorities
c) UserRoles
d) Authentication

4. In Spring Security, what is the main difference between authentication and authorization?

a) They both refer to the same process.
b) Authentication is for verifying identity, while authorization determines what an authenticated user can access.
c) Authentication grants access, while authorization verifies identity.
d) Both are filters used to block unauthorized requests.

5. Which filter is central to Spring Security's filter chain?

a) HttpFilter
b) WebSecurityFilter
c) FilterChainProxy
d) SecurityChainFilter

6. Which annotation is used to enable method-level security?

a) @EnableSecurity
b) @EnableMethodSecurity
c) @MethodSecure
d) @SecureMethod

7. Which interface is primarily responsible for loading UserDetails by its username in Spring Security?

a) UserDetailsService
b) UserDetailsLoader
c) UserManager
d) UserProvider

8. In Spring Security, which class is a principal UserDetails implementation?

a) UserDetail
b) UserPrincipal
c) User
d) AppUser

9. Which annotation secures a method and restricts it to specific roles?

a) @RoleSecure
b) @PermitRole
c) @HasRole
d) @PreAuthorize

10. By default, which URL is used for the Spring Security login page?

a) /login
b) /signin
c) /auth
d) /enter

11. What does CSRF stand for in Spring Security?

a) Cross-Site Request Framework
b) Cross-Security Request Forgery
c) Cross-Site Request Forgery
d) Cross-Server Request Form

12. Which filter in Spring Security handles logout functionality?

a) LogoutFilter
b) SessionFilter
c) SignoutFilter
d) ExitFilter

13. In which module is the OAuth2 support provided in Spring Security?

a) Spring OAuth
b) Spring Security OAuth2
c) Spring Auth2
d) Spring OpenAuth

14. Which class represents the currently authenticated user in Spring Security?

a) CurrentUser
b) SecurityUser
c) Authentication
d) AuthenticatedUser

15. What default role prefix does Spring Security use?

a) ROLE_
b) AUTH_
c) USER_
d) SPRING_

16. Which of the following is NOT an authentication provider in Spring Security?

a) DaoAuthenticationProvider
b) JwtAuthenticationProvider
c) RememberMeAuthenticationProvider
d) SessionAuthenticationProvider

17. Which Spring Security filter is responsible for processing user authentication?

a) AuthenticationFilter
b) UserAuthenticationFilter
c) UsernamePasswordAuthenticationFilter
d) UserCredentialsFilter

18. How does Spring Security handle authorization aspects for web requests?

a) Through Filters
b) Using AOP (Aspect-Oriented Programming)
c) By directly modifying application logic
d) Through JDBC

19. Which annotation checks if a user is authenticated before accessing a method?

a) @IsAuthenticated
b) @AuthCheck
c) @Secured
d) @UserCheck

20. Which class in Spring Security is used to hash passwords?

a) PasswordEncoder
b) PasswordHasher
c) HashEncoder
d) SecureEncoder

21. Which of the following is a default filter used for form-based authentication in Spring Security?

a) HttpBasicFilter
b) FormAuthenticationFilter
c) UsernamePasswordAuthenticationFilter
d) FormLoginFilter

22. In Spring Security, which authentication method sends credentials with every HTTP request?

a) Form-based authentication
b) OAuth2 authentication
c) JWT authentication
d) Basic authentication

23. What does the ROLE_ANONYMOUS in Spring Security represent?

a) Authenticated users
b) Users with elevated privileges
c) Non-authenticated users accessing public resources
d) Admin users

24. What mechanism does form-based authentication in Spring Security typically use to remember the authenticated user across multiple requests?

a) JWT tokens
b) Session
c) Basic Auth header
d) API keys

25. Which Spring Security filter is responsible for processing authentication for HTTP Basic Authentication?

a) HttpBasicAuthFilter
b) BasicAuthenticationFilter
c) BasicAuthProcessingFilter
d) HttpBasicProcessingFilter

Related Spring MCQ Posts


Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare