Spring Boot Security MCQ - Multiple Choice Questions and Answers

Spring Boot Security ensures robust and secure applications without a steep learning curve. The library is packed with features that enable authentication, authorization, and protection against common security vulnerabilities. For those ready to dive into the fascinating world of Spring Boot Security, this MCQ guide offers a chance to test your foundational knowledge.

1. Which Spring Boot starter dependency is essential for integrating Spring Security?

a) spring-boot-starter-auth
b) spring-boot-starter-secure
c) spring-boot-starter-oauth2
d) spring-boot-starter-security

Answer:

d) spring-boot-starter-security

Explanation:

To integrate Spring Security in a Spring Boot application, you should include the spring-boot-starter-security dependency.

2. By default, what is the username provided by Spring Boot Security?

a) admin
b) root
c) user
d) guest

Answer:

c) user

Explanation:

Spring Boot Security provides a default username of user when no other configurations are specified.

3. Which of the following is a primary interface for authentication in Spring Security?

a) Authenticator
b) AuthProvider
c) AuthenticationManager
d) AuthenticationProvider

Answer:

c) AuthenticationManager

Explanation:

The AuthenticationManager interface is responsible for authenticating the user in Spring Security.

4. Which annotation ensures that a method can only be accessed by authenticated users?

a) @Secured
b) @Authenticated
c) @Authorize
d) @PermitAll

Answer:

a) @Secured

Explanation:

The @Secured annotation ensures that a method is secured and can only be accessed by authenticated users.

5. Which filter is responsible for processing user authentication in form login?

a) UsernamePasswordAuthenticationFilter
b) BasicAuthenticationFilter
c) OAuth2AuthenticationFilter
d) JwtAuthenticationFilter

Answer:

a) UsernamePasswordAuthenticationFilter

Explanation:

The UsernamePasswordAuthenticationFilter processes authentication for form-based logins.

6. How do you enable method-level security in Spring Boot?

a) @EnableMethodSecurity
b) @SecureMethods
c) @ActivateMethodSecurity
d) @ProtectMethods

Answer:

a) @EnableMethodSecurity

Explanation:

You can enable method-level security using the @EnableMethodSecurity annotation.

7. What does CSRF stand for in the context of web security?

a) Common Security Request Forgery
b) Cross Security Request Firewall
c) Cross-Site Resource Forgery
d) Cross-Site Request Forgery

Answer:

d) Cross-Site Request Forgery

Explanation:

CSRF stands for Cross-Site Request Forgery, a type of attack where unauthorized commands are executed on behalf of an authenticated user.

8. Which method is used to permit all requests on a particular endpoint in the configuration?

a) .allowAll()
b) .permit()
c) .permitAll()
d) .open()

Answer:

c) .permitAll()

Explanation:

The .permitAll() method is used in the configuration to allow unrestricted access to a specific endpoint.

9. How can you enforce role-based access to a URL in Spring Security?

a) .hasRole('ROLE_ADMIN')
b) .role('ADMIN')
c) .withRole('ADMIN')
d) .roleEnforced('ADMIN')

Answer:

a) .hasRole('ROLE_ADMIN')

Explanation:

You can enforce role-based access to a URL using the .hasRole('ROLE_NAME') method.

10. Which of the following provides out-of-the-box OAuth 2.0 login?

a) Spring Boot
b) Spring Data
c) Spring Boot Security
d) Spring Cloud

Answer:

c) Spring Boot Security

Explanation:

Spring Boot Security provides out-of-the-box support for OAuth 2.0 login.


Related Spring Boot MCQ Posts

Comments