Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is form-based login in Spring Boot?
Form-based login is a way to authenticate users by showing a login form where they enter their username and password. Spring Security handles the form submission and checks credentials.
Click to reveal answer
intermediate
Which Spring Security class is commonly extended or configured to set up form-based login?
You usually configure form-based login by customizing the SecurityFilterChain bean or extending WebSecurityConfigurerAdapter (older versions). In Spring Boot 3+, use SecurityFilterChain with HttpSecurity.
Click to reveal answer
beginner
What method in HttpSecurity enables form-based login configuration?
The method is formLogin(). It allows you to customize the login page, success handler, failure handler, and more.
Click to reveal answer
intermediate
How do you specify a custom login page URL in form-based login?
Use formLogin().loginPage("/custom-login") in your HttpSecurity configuration to tell Spring Security to use your own login page.
Click to reveal answer
beginner
What happens if you do not configure a custom login page in Spring Boot form-based login?
Spring Security provides a default login page automatically. It is a simple form that asks for username and password.
Click to reveal answer
Which method starts form-based login configuration in Spring Security?
AauthorizeRequests()
BformLogin()
Ccsrf()
DhttpBasic()
✗ Incorrect
The formLogin() method enables form-based login configuration.
How do you set a custom login page URL in Spring Boot form login?
AformLogin().loginPage("/my-login")
BhttpBasic().loginPage("/my-login")
CformLogin().defaultSuccessUrl("/my-login")
Dcsrf().loginPage("/my-login")
✗ Incorrect
Use formLogin().loginPage("/my-login") to specify a custom login page.
What does Spring Boot provide if no custom login page is configured?
ARedirect to home page
BNo login page, access denied
CA default login form page
DAn error page
✗ Incorrect
Spring Security automatically provides a default login form page.
In Spring Boot 3+, which bean is recommended to configure security including form login?
ASecurityFilterChain
BWebSecurityConfigurerAdapter
CAuthenticationManager
DUserDetailsService
✗ Incorrect
SecurityFilterChain bean with HttpSecurity is the modern way to configure security.
Which of these is NOT a feature you can customize in formLogin()?
AloginPage URL
BsuccessHandler
CfailureHandler
Ddatabase connection
✗ Incorrect
Database connection is unrelated to formLogin() customization.
Explain how to configure a custom form-based login page in Spring Boot.
Think about how you tell Spring Security to use your own login page URL.
You got /5 concepts.
Describe what happens when a user accesses a secured page without being logged in using form-based login.
Consider the user flow from accessing a protected resource to successful login.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of formLogin() in Spring Security?
easy
A. To enable form-based login for user authentication
B. To disable all login methods
C. To configure database connections
D. To set up REST API endpoints
Solution
Step 1: Understand formLogin() role
The formLogin() method in Spring Security enables users to log in using a web form.
Step 2: Compare with other options
Other options like disabling login or configuring database are unrelated to formLogin().
Final Answer:
To enable form-based login for user authentication -> Option A
Quick Check:
formLogin() enables form login [OK]
Hint: Remember formLogin() means login via web form [OK]
Common Mistakes:
Confusing formLogin() with database setup
Thinking formLogin() disables login
Mixing formLogin() with API configuration
2. Which of the following is the correct way to customize the login page URL in Spring Security?
easy
A. http.formLogin().loginPath("/custom-login")
B. http.formLogin().loginPage("/custom-login")
C. http.formLogin().pageUrl("/custom-login")
D. http.formLogin().setLoginUrl("/custom-login")
Solution
Step 1: Identify correct method for login page URL
The method to set a custom login page URL is loginPage() used after formLogin().
Step 2: Verify syntax correctness
Only http.formLogin().loginPage("/custom-login") uses the correct method name and syntax: loginPage("/custom-login").
Final Answer:
http.formLogin().loginPage("/custom-login") -> Option B
Quick Check:
loginPage() sets custom login URL [OK]
Hint: Use loginPage() to set custom login URL [OK]
Common Mistakes:
Using incorrect method names like setLoginUrl()
Confusing loginPage() with other methods
Missing parentheses or quotes
3. Given the following Spring Security configuration snippet, what will be the behavior when a user accesses /login?
A. permitAll() should be called on authorizeHttpRequests, not formLogin
B. loginPage() must be called before formLogin()
C. permitAll() is not a valid method in Spring Security
D. The code is correct and will work as expected
Solution
Step 1: Check method chaining correctness
In Spring Security, permitAll() is used on authorization rules, not directly on formLogin().
Step 2: Understand correct usage
To allow public access to the login page, permitAll() should be called on the authorization configuration for the login page URL.
Final Answer:
permitAll() should be called on authorizeHttpRequests, not formLogin -> Option A
Quick Check:
permitAll() belongs to authorization, not formLogin [OK]
Hint: permitAll() controls access, use it in authorizeHttpRequests [OK]
Common Mistakes:
Calling permitAll() on formLogin()
Misplacing loginPage() call
Assuming permitAll() is invalid
5. You want to create a Spring Security setup where:
- The login page is at /user-login
- The login page is accessible without authentication
- All other pages require login
Which configuration snippet correctly achieves this?
hard
A. http.authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
.formLogin(form -> form.loginPage("/user-login").permitAll());
B. http.formLogin().loginPage("/user-login").permitAll()
.authorizeHttpRequests(auth -> auth.anyRequest().authenticated());
C. http.authorizeHttpRequests(auth -> auth.requestMatchers("/user-login").permitAll().anyRequest().authenticated())
.formLogin(form -> form.loginPage("/user-login"));
D. http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.formLogin(form -> form.loginPage("/user-login"));
Solution
Step 1: Permit access to the login page
Use requestMatchers("/user-login").permitAll() to allow unauthenticated access to the login page.
Step 2: Require authentication for all other requests
Use anyRequest().authenticated() to protect all other endpoints.
Step 3: Configure form login with custom login page
formLogin(form -> form.loginPage("/user-login")) sets the custom login page.
Final Answer:
http.authorizeHttpRequests(auth -> auth.requestMatchers("/user-login").permitAll().anyRequest().authenticated())
.formLogin(form -> form.loginPage("/user-login")); -> Option C
Quick Check:
Properly permits login page and protects others [OK]
Hint: Explicitly permit login page URL in authorizeHttpRequests [OK]
Common Mistakes:
Not permitting the login page URL (option A)
Invalid chaining after formLogin.permitAll() (option B)