Complete the code to declare the filter class that extends the correct Spring Security filter.
public class JwtValidationFilter extends [1] { }
The JwtValidationFilter should extend OncePerRequestFilter to ensure it runs once per request in Spring Security.
Complete the method signature to override the filter logic.
@Override
protected void [1](HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { }The method to override in OncePerRequestFilter is doFilterInternal.
Fix the error in extracting the JWT token from the Authorization header.
String authHeader = request.getHeader("Authorization"); if (authHeader != null && authHeader.startsWith([1])) { String token = authHeader.substring(7); }
The standard prefix for JWT tokens in the Authorization header is "Bearer ".
Fill both blanks to validate the token and set authentication in the security context.
if (jwtUtil.validateToken([1])) { UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken( userDetails, null, userDetails.[2]()); SecurityContextHolder.getContext().setAuthentication(authToken); }
The token variable holds the JWT string to validate. The getAuthorities() method provides user roles for authentication.
Fill all three blanks to complete the filter chain call and handle exceptions properly.
try { [1].doFilter([2], [3]); } catch (JwtException e) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); }
The filter chain's doFilter method is called with the request and response objects to continue processing.