A. Method name should be httpBasic() with capital B.
B. authorizeHttpRequests() should be authorizeRequests().
C. authenticated() should be permitAll().
D. No error, configuration is correct.
Solution
Step 1: Check method names carefully
The method to enable HTTP Basic is httpBasic() with a capital B, not httpbasic().
Step 2: Verify other methods
authorizeHttpRequests() is correct in Spring Security 6+, and authenticated() is appropriate to require login.
Final Answer:
Method name should be httpBasic() with capital B. -> Option A
Quick Check:
Method names are case-sensitive = httpBasic() [OK]
Hint: Check method capitalization carefully [OK]
Common Mistakes:
Using wrong method case like httpbasic()
Confusing authorizeHttpRequests with older authorizeRequests
Changing authenticated() to permitAll() incorrectly
5. You want to secure your Spring Boot REST API with HTTP Basic authentication but only for the endpoints under /admin/**. Which configuration snippet correctly applies HTTP Basic only to those endpoints?
hard
A. http.httpBasic().authorizeHttpRequests(auth -> auth.anyRequest().authenticated());
B. http.authorizeHttpRequests(auth -> auth.requestMatchers("/admin/**").authenticated().anyRequest().permitAll()).httpBasic();
C. http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll()).httpBasic();
D. http.authorizeHttpRequests(auth -> auth.requestMatchers("/admin/**").permitAll()).httpBasic();
Solution
Step 1: Understand the requirement
Only endpoints matching /admin/** should require authentication; others should be open.
Step 2: Analyze each option
http.authorizeHttpRequests(auth -> auth.requestMatchers("/admin/**").authenticated().anyRequest().permitAll()).httpBasic(); correctly requires authentication for /admin/** and permits all other requests. Other options either require authentication for all requests, permit all requests, or incorrectly permit the /admin/** paths.
Final Answer:
http.authorizeHttpRequests(auth -> auth.requestMatchers("/admin/**").authenticated().anyRequest().permitAll()).httpBasic(); -> Option B
Quick Check:
Secure only /admin/** = authenticated() on matcher + permitAll() others [OK]
Hint: Use requestMatchers for specific paths, then set auth [OK]
Common Mistakes:
Applying authentication to all endpoints instead of specific ones
Permitting admin endpoints by mistake
Misordering authorizeHttpRequests and httpBasic calls
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.