Spring Security MCQ - Multiple Choice Questions and Answers

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. If you're stepping into the world of Spring Security, this MCQ guide is an ideal starting point to test your foundational understanding and help you climb the ladder of expertise.

1. What does Spring Security primarily offer?

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

Answer:

c) Authentication and Authorization

Explanation:

Spring Security primarily provides comprehensive security features for authentication and authorization in applications.

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

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

Answer:

c) FilterChainProxy

Explanation:

FilterChainProxy is the core component that manages the security filter chain in Spring Security.

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

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

Answer:

b) @EnableMethodSecurity

Explanation:

The @EnableMethodSecurity annotation is used to enable method-level security annotations.

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

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

Answer:

a) UserDetailsService

Explanation:

The UserDetailsService interface is designed to load user-specific data by its username.

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

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

Answer:

c) User

Explanation:

The User class is a principal implementation of the UserDetails interface provided by Spring Security.

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

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

Answer:

d) @PreAuthorize

Explanation:

The @PreAuthorize annotation is used to secure methods based on role or other access-control expressions.

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

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

Answer:

a) /login

Explanation:

By default, Spring Security provides a basic login page accessible via the /login URL.

8. Which class is commonly extended to provide custom security configurations?

a) SecurityConfigurer
b) WebSecurityConfigurerAdapter
c) SecurityAdapter
d) WebConfigurer

Answer:

b) WebSecurityConfigurerAdapter

Explanation:

The WebSecurityConfigurerAdapter class is frequently extended to provide custom security configurations.

9. 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

Answer:

c) Cross-Site Request Forgery

Explanation:

CSRF stands for Cross-Site Request Forgery, a type of attack that tricks users into performing unintended actions.

10. Which filter in Spring Security handles logout functionality?

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

Answer:

a) LogoutFilter

Explanation:

The LogoutFilter provides logout capabilities in Spring Security.

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

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

Answer:

b) Spring Security OAuth2

Explanation:

Spring Security provides OAuth2 support through the Spring Security OAuth2 module.

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

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

Answer:

c) Authentication

Explanation:

The Authentication class represents the currently authenticated user in Spring Security.

13. Which annotation can be used to inject the currently authenticated user into a method parameter?

a) @CurrentUser
b) @AuthUser
c) @AuthenticatedUser
d) @AuthenticationPrincipal

Answer:

d) @AuthenticationPrincipal

Explanation:

The @AuthenticationPrincipal annotation allows injection of the currently authenticated user (or principal) into a method parameter.

14. What default role prefix does Spring Security use?

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

Answer:

a) ROLE_

Explanation:

By default, Spring Security uses the ROLE_ prefix for roles.

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

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

Answer:

d) SessionAuthenticationProvider

Explanation:

There's no SessionAuthenticationProvider in Spring Security.



Comments