PasswordChangeUiRequiredFilter extends OncePerRequestFilter { @Override protected void doFilterInternal( final @NonNull HttpServletRequest request, final @NonNull HttpServletResponse response, final @NonNull FilterChain filterChain) throws ServletException, IOException { if (isIgnored(request)) { filterChain.doFilter(request, response); } else if (isCompleted(request)) { logger.debug("Forced password change has been completed."); SavedRequest savedRequest = cache.getRequest(request, response); if (savedRequest != null) { sendRedirect(savedRequest.getRedirectUrl(), request, response); } else { sendRedirect("/", request, response); } } else if (needsPasswordReset(request) && !matchPath.matches(request)) { logger.debug("Password change is required for user."); cache.saveRequest(request, response); sendRedirect(MATCH_PATH, request, response); } else if (matchPath.matches(request) && isAuthenticated() && !needsPasswordReset(request)) { sendRedirect("/", request, response); } else { filterChain.doFilter(request, response); } } PasswordChangeUiRequiredFilter(final UaaSavedRequestCache cache);   }
@Test void requestToMfa() throws Exception { SecurityContextHolder.getContext().setAuthentication(mockUaaAuthentication); mockHttpServletRequest.setPathInfo("/login/mfa/register"); passwordChangeUiRequiredFilter.doFilterInternal(mockHttpServletRequest, mockHttpServletResponse, mockFilterChain); verify(mockFilterChain, times(1)).doFilter(same(mockHttpServletRequest), same(mockHttpServletResponse)); verifyZeroInteractions(mockHttpServletResponse); verifyZeroInteractions(mockRequestCache); }
@Test void notAuthenticated() throws Exception { passwordChangeUiRequiredFilter.doFilterInternal(mockHttpServletRequest, mockHttpServletResponse, mockFilterChain); verify(mockFilterChain, times(1)).doFilter(same(mockHttpServletRequest), same(mockHttpServletResponse)); }
@Test void tryingAccessForcePasswordPageNotAuthenticated() throws Exception { mockHttpServletRequest.setPathInfo("/force_password_change"); passwordChangeUiRequiredFilter.doFilterInternal(mockHttpServletRequest, mockHttpServletResponse, mockFilterChain); verify(mockFilterChain, times(1)).doFilter(same(mockHttpServletRequest), same(mockHttpServletResponse)); }