title: Uncorrect redirect after login - Spring Boot
body: <p>In my <code>Spring Boot</code> application I have a strange problem.</p>
  
  <p>After login, my web app redirect to a JS page (<code>bootstrap-table.js</code>). This page not appears every times, but only at the first login, in the successive login we are redirect to the correct page "home.html".</p>
  
  <p>In my WebApp I use: <code>thymeleaf</code> and <code>bootstrap4</code>.</p>
  
  <p>This is my Security Configuration:</p>
  
  <pre><code>    @Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled=true)
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
          @Autowired
      private UserDetailsService userDetailsService;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
  
          http
          .authorizeRequests()
              .antMatchers("/").permitAll()
              .antMatchers("/resources/**").permitAll()
              .antMatchers("/resetpwd/**").permitAll()
              .anyRequest().authenticated()
          .and()
          .formLogin()
              .loginPage("/login")
              .permitAll()
              .failureUrl("/?login_error")
              .defaultSuccessUrl("/home")
          .and()
          .logout()
              .logoutUrl("/logout")
              .logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET"))
              .permitAll()
              .logoutSuccessUrl("/")
              .invalidateHttpSession(true)
              .deleteCookies("remember-me")
          .and()
              .rememberMe()
          .and()
              .sessionManagement();
  
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web
             .ignoring()
             .antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**", "/webjars/**");
      }
  
  }
  </code></pre>
  
  <p>I have define the <strong>css</strong> and <strong>js</strong> file in <code>default.html</code>, the login form is in the header.html: </p>
  
  <pre><code>        &lt;ul class="nav navbar-nav pull-right  ml-auto " sec:authorize="isAnonymous()"&gt;
  
               &lt;li class="nav-item"&gt;
                  &lt;a class="nav-link dropdown-toggle " href="#" data-toggle="dropdown" th:text="#{login}"&gt; &lt;/a&gt;
  
                  &lt;ul class="dropdown-menu form-wrapper"&gt;                 
                      &lt;li&gt;
  
                    &lt;form th:action="@{/login}"  data-parsley-validate="" method="POST" class="form login" &gt;
                      &lt;div class="col-sm-12 text-center" th:text="#{login}" &gt;&lt;/div&gt;
                      &lt;p th:if="${loginError}" style="color: red;" th:text="#{login_unsuccessful}"&gt;&lt;/p&gt;
  
                      &lt;br /&gt;
                      &lt;div class="form-group"&gt;
                              &lt;div class="input-group mb-2"&gt;
                                  &lt;div class="input-group-prepend"&gt;
                                      &lt;div class="input-group-text"&gt;&lt;i class="fas fa-user text-info"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;input type="text" class="form-control" id="username" name='username' placeholder="Username" required&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;div class="input-group mb-2"&gt;
                                  &lt;div class="input-group-prepend"&gt;
                                      &lt;div class="input-group-text"&gt;&lt;i class="fas fa-key text-info"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;input type="password" class="form-control" id="password" name="password" placeholder="Password" required&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;input type="submit" class="btn btn-primary btn-block text-center" value="Login"&gt;
                      &lt;div class="form-footer"&gt;
                          &lt;a data-target="#modalPwd" data-toggle="modal" href="#modalPwd" id="pwdDmntct" th:text="#{pwdDimenticata}"&gt;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
               &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
          &lt;/ul&gt;
  </code></pre>
  
  <p>In the body of default I have the definition of JS.</p>
  
  <pre><code>&lt;body&gt;
  
      &lt;!-- page content --&gt;
      &lt;div class="container-fluid"&gt;
          &lt;nav th:replace="~{/fragments/header :: header}"&gt;&lt;/nav&gt;
          &lt;div class="container-fluid"&gt;           
  
              &lt;div layout:fragment="content"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;          
      &lt;!-- /page content --&gt;
  
      &lt;script th:src="@{/js/parsley/parsley.js}" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script th:src="@{/js/parsley/it.js}" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script th:src="@{/bootstrap-table/bootstrap-table.min.js}" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script th:src="@{/bootstrap-table/bootstrap-table-it-IT.min.js}" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script th:src="@{/webjars/bootstrap-datepicker/js/bootstrap-datepicker.min.js}" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script th:src="@{/webjars/bootstrap-datepicker/locales/bootstrap-datepicker.it.min.js}" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script th:src="@{/webjars/select2/dist/js/select2.min.js}" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript" th:inline="javascript"&gt;
          $(function () {
              if($('form').length){
                  $('form').parsley().on('form:validated', function(e) {
                      if (e.validationResult) {
                          $('input[type=submit]').attr('disabled', 'disabled');
                      }
                  });
              }
              $('body').on('click', '[data-toggle="modal"]', function(){
                  $($(this).data("target")+' .modal-content').load($(this).attr('href'));
              });
          });
      &lt;/script&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>Can anyone help me to understand this problem?
  Thanks</p>