Complete the code to define a Spring Boot controller method that handles login requests.
public ResponseEntity<String> login(@RequestBody LoginRequest [1]) {
// method body
}The parameter name loginRequest clearly represents the login data object received in the request body.
Complete the code to inject the authentication manager bean into the service class.
@Autowired
private [1] authenticationManager;The correct Spring Security interface to handle authentication is AuthenticationManager.
Fix the error in the code that authenticates a user with username and password.
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken([1], password)
);The first argument to UsernamePasswordAuthenticationToken must be the username, not the password.
Fill both blanks to create a JWT token after successful authentication.
String token = jwtUtil.[1](authentication.getName(), [2]);
Use generateToken to create the token and pass the username and authorities for claims.
Fill all three blanks to configure HTTP security to require authentication for all requests except login.
http.csrf().disable()
.authorizeHttpRequests()
.requestMatchers("/login").[1]()
.anyRequest().[2]()
.and()
.sessionManagement().sessionCreationPolicy([3]);Allow all users to access /login without authentication, require authentication for other requests, and use stateless sessions for JWT.