@Override
  public void doFilter(HttpRequest request, HttpResponse response, FilterChain chain) throws IOException {
    boolean forceRedirect = config
      .getBoolean(SONAR_FORCE_REDIRECT_DEFAULT_ADMIN_CREDENTIALS)
      .orElse(true);

    if (forceRedirect && userSession.hasSession() && userSession.isLoggedIn()
      && userSession.isSystemAdministrator() && !"admin".equals(userSession.getLogin())
      && defaultAdminCredentialsVerifier.hasDefaultCredentialUser()) {
      redirectTo(response, request.getContextPath() + CHANGE_ADMIN_PASSWORD_PATH);
    }

    chain.doFilter(request, response);
  }
@Test
  public void do_not_redirect_if_config_says_so() throws Exception {
    when(config.getBoolean("sonar.forceRedirectOnDefaultAdminCredentials")).thenReturn(Optional.of(false));

    underTest.doFilter(request, response, chain);

    verify(response, never()).sendRedirect(any());
  }