### Question:
X509AuthenticationFilter extends AbstractAuthenticationProcessingFilter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (!requiresAuthentication(request, response)) { chain.doFilter(request, response); return; } Authentication authResult = attemptAuthentication(request, response); if (authResult == null) { chain.doFilter(request, response); return; } successfulAuthentication(request, response, chain, authResult); } X509AuthenticationFilter(String endpoint,
                                    AuthenticationSuccessHandler successHandler,
                                    AuthenticationProvider authenticationProvider); @Override void doFilter(ServletRequest req, ServletResponse res, FilterChain chain); @Override Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response);  }### Answer:
@Test void shouldAuthenticateWithCertificate() throws ServletException, IOException { httpServletRequest = new MockHttpServletRequest(); httpServletRequest.setMethod(HttpMethod.POST.name()); httpServletRequest.setAttribute("client.auth.X509Certificate", x509Certificate); httpServletRequest.setServletPath("/api/v1/gateway/auth/login"); httpServletResponse = new MockHttpServletResponse(); when(authenticationProvider.authenticate(new X509AuthenticationToken(x509Certificate))) .thenReturn(new TokenAuthentication("user", "jwt")); x509AuthenticationFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); verify(authenticationProvider).authenticate(new X509AuthenticationToken(x509Certificate)); }