@Test @WithMockUser(username = "user") void testDoFilterInternalIsNotConfigured() throws IOException, ServletException { request.setRequestURI("/login"); when(authenticationSettings.getTwoFactorAuthentication()).thenReturn(ENFORCED); when(twoFactorAuthenticationService.isConfiguredForUser()).thenReturn(false); filter.doFilterInternal(request, response, chain); String configuredRedirectUrl = TwoFactorAuthenticationController.URI + TwoFactorAuthenticationController.TWO_FACTOR_ACTIVATION_URI; assertEquals(configuredRedirectUrl, response.getRedirectedUrl()); }
@Override protected void doFilterInternal( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { if (currentUserIsAuthenticated() && isUserShouldTwoFactorAuthenticate() && isNotProtected(httpServletRequest.getRequestURI()) && isInsufficientlyAuthenticated()) { redirectToTwoFactorAuthenticationController(httpServletRequest, httpServletResponse); } else { filterChain.doFilter(httpServletRequest, httpServletResponse); } }
TwoFactorAuthenticationFilter extends OncePerRequestFilter { @Override protected void doFilterInternal( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { if (currentUserIsAuthenticated() && isUserShouldTwoFactorAuthenticate() && isNotProtected(httpServletRequest.getRequestURI()) && isInsufficientlyAuthenticated()) { redirectToTwoFactorAuthenticationController(httpServletRequest, httpServletResponse); } else { filterChain.doFilter(httpServletRequest, httpServletResponse); } } }
TwoFactorAuthenticationFilter extends OncePerRequestFilter { @Override protected void doFilterInternal( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { if (currentUserIsAuthenticated() && isUserShouldTwoFactorAuthenticate() && isNotProtected(httpServletRequest.getRequestURI()) && isInsufficientlyAuthenticated()) { redirectToTwoFactorAuthenticationController(httpServletRequest, httpServletResponse); } else { filterChain.doFilter(httpServletRequest, httpServletResponse); } } TwoFactorAuthenticationFilter(
      AuthenticationSettings authenticationSettings,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      RedirectStrategy redirectStrategy,
      UserAccountService userAccountService); }
TwoFactorAuthenticationFilter extends OncePerRequestFilter { @Override protected void doFilterInternal( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { if (currentUserIsAuthenticated() && isUserShouldTwoFactorAuthenticate() && isNotProtected(httpServletRequest.getRequestURI()) && isInsufficientlyAuthenticated()) { redirectToTwoFactorAuthenticationController(httpServletRequest, httpServletResponse); } else { filterChain.doFilter(httpServletRequest, httpServletResponse); } } TwoFactorAuthenticationFilter(
      AuthenticationSettings authenticationSettings,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      RedirectStrategy redirectStrategy,
      UserAccountService userAccountService);  }
TwoFactorAuthenticationFilter extends OncePerRequestFilter { @Override protected void doFilterInternal( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { if (currentUserIsAuthenticated() && isUserShouldTwoFactorAuthenticate() && isNotProtected(httpServletRequest.getRequestURI()) && isInsufficientlyAuthenticated()) { redirectToTwoFactorAuthenticationController(httpServletRequest, httpServletResponse); } else { filterChain.doFilter(httpServletRequest, httpServletResponse); } } TwoFactorAuthenticationFilter(
      AuthenticationSettings authenticationSettings,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      RedirectStrategy redirectStrategy,
      UserAccountService userAccountService);   }