Consider a Spring Boot application with HTTP Basic authentication enabled on a REST endpoint. What is the response when a client tries to access the endpoint without sending any credentials?
spring.security.user.name=user spring.security.user.password=pass @RestController public class MyController { @GetMapping("/data") public String getData() { return "secret data"; } }
Think about how HTTP Basic authentication challenges clients when no credentials are provided.
When HTTP Basic authentication is enabled, accessing a protected endpoint without credentials causes the server to respond with 401 Unauthorized and a WWW-Authenticate header. This header tells the client to provide credentials.
Choose the correct Java configuration snippet to enable HTTP Basic authentication in a Spring Boot application.
Look for the method that enables HTTP Basic authentication and requires authentication for all requests.
Option B uses the modern Spring Security DSL to require authentication for all requests and enables HTTP Basic authentication with default settings.
When a client sends credentials using HTTP Basic authentication with username 'admin' and password '1234', what is the exact value of the 'Authorization' header?
Remember HTTP Basic authentication encodes 'username:password' in Base64 and prefixes with 'Basic '.
The string 'admin:1234' encoded in Base64 is 'YWRtaW46MTIzNA=='. The header value is 'Basic ' plus this encoded string.
Given the following Spring Security configuration, why does the endpoint '/api/data' remain accessible without authentication?
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/public/**").permitAll()
.anyRequest().permitAll())
.httpBasic(withDefaults());Check the order and effect of authorization rules in the configuration.
The '.anyRequest().permitAll()' rule allows all requests without authentication, so HTTP Basic authentication is effectively disabled for all endpoints.
Consider the security model of HTTP Basic authentication in Spring Boot. Which statement correctly identifies a key limitation?
Think about how HTTP Basic authentication transmits credentials over the network.
HTTP Basic authentication encodes credentials in Base64, which is not encryption. Without HTTPS, credentials can be intercepted easily.