title: Loop on login page no matter what the credentials are
body: <p>I'm trying to use Spring Security on my Spring Boot Web project but it's looping on the login page no matter what the credentials are. It is not throwing exceptions, not saying anything is bad, it's just endlessly looping.</p>
  <p>Here's my code:</p>
  <p><em><strong>SecurityConfig Class</strong></em></p>
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private MyUserDetailsService uDs;
  
      @Bean
      public AuthenticationProvider authProvider() {
          DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
          provider.setUserDetailsService(uDs);
          provider.setPasswordEncoder(NoOpPasswordEncoder.getInstance());//no encoding for now
          System.out.println(uDs.toString());
          return provider;
      }
  }
  </code></pre>
  <p><em><strong>MyuserDetailsService Class</strong></em></p>
  <pre><code>@Service
  public class MyUserDetailsService implements UserDetailsService {
  
      @Autowired
      private UserRepository userRepo;
  
      @Override
      public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
          System.out.println(&quot;Searching User ...&quot;);
          User user = userRepo.findByPseudo(username);
          if (user == null) {
              System.out.println(&quot;No User Found : 404.&quot;);
              throw new UsernameNotFoundException(&quot;User 404.&quot;);
          } else
              System.out.println(&quot;User Found !&quot;);
  
          return new PrincipalUser(user);
      }
  
      @Override
      public String toString() {
          return &quot;Custom Service&quot;;
      }
  
  }
  </code></pre>
  <p><em><strong>PrincipalUser Class</strong></em></p>
  <pre><code>
  public class PrincipalUser implements UserDetails {
  
      private static final long serialVersionUID = 1L;
  
      private User user;
  
      public PrincipalUser(User user) {
          super();
          this.user = user;
      }
  
      @Override
      public Collection&lt;? extends GrantedAuthority&gt; getAuthorities() {
          return Collections.singleton(new SimpleGrantedAuthority(&quot;USER&quot;));
      }
  
      @Override
      public String getPassword() {
          return user.getPassword();
      }
  
      @Override
      public String getUsername() {
          return user.getPseudo();
      }
  
      @Override
      public boolean isAccountNonExpired() {
          return true;
      }
  
      @Override
      public boolean isAccountNonLocked() {
          return true;
      }
  
      @Override
      public boolean isCredentialsNonExpired() {
          return true;
      }
  
      @Override
      public boolean isEnabled() {
          return true;
      }
  
  }
  </code></pre>
  <p>application.properties File</p>
  <pre><code>spring.mvc.view.suffix=.jsp
  spring.mvc.view.prefix=WEB-INF/pages/
  
  server.servlet.session.cookie.http-only=true
  server.servlet.session.tracking-modes=cookie
  
  spring.jpa.hibernate.ddl-auto=update
  spring.jpa.open-in-view=true
  spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/mytunes?useTimezone=true&amp;serverTimezone=Europe/Paris
  spring.datasource.username=username
  spring.datasource.password=password
  </code></pre>
  <p>I'm sure that my custom UserDetailsService class is instantiated but it seems like it's not used ...
  Here's Spring's log :</p>
  <pre><code> :: Spring Boot ::        (v2.2.6.RELEASE)
  
  2020-05-12 14:26:50.078  INFO 17808 --- [           main] o.T.projects.mytunes.MyTunesApplication  : Starting MyTunesApplication on ALEXIS with PID 17808 (E:\SpringTools_WS\MyTunes\target\classes started by Alexis in E:\SpringTools_WS\MyTunes)
  2020-05-12 14:26:50.081  INFO 17808 --- [           main] o.T.projects.mytunes.MyTunesApplication  : No active profile set, falling back to default profiles: default
  2020-05-12 14:26:50.620  INFO 17808 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
  2020-05-12 14:26:50.674  INFO 17808 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 48ms. Found 6 JPA repository interfaces.
  2020-05-12 14:26:51.186  INFO 17808 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
  2020-05-12 14:26:51.193  INFO 17808 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
  2020-05-12 14:26:51.193  INFO 17808 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.33]
  2020-05-12 14:26:51.386  INFO 17808 --- [           main] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
  2020-05-12 14:26:51.390  INFO 17808 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2020-05-12 14:26:51.390  INFO 17808 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1275 ms
  2020-05-12 14:26:51.684  INFO 17808 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
  2020-05-12 14:26:51.730  INFO 17808 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.12.Final
  2020-05-12 14:26:51.810  INFO 17808 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
  2020-05-12 14:26:51.879  INFO 17808 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
  2020-05-12 14:26:52.190  INFO 17808 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
  2020-05-12 14:26:52.203  INFO 17808 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
  2020-05-12 14:26:52.278  WARN 17808 --- [           main] org.hibernate.cfg.AnnotationBinder       : HHH000457: Joined inheritance hierarchy [org.ThePouil.projects.mytunes.model.music.TrackList] defined explicit @DiscriminatorColumn.  Legacy Hibernate behavior was to ignore the @DiscriminatorColumn.  However, as part of issue HHH-6911 we now apply the explicit @DiscriminatorColumn.  If you would prefer the legacy behavior, enable the `hibernate.discriminator.ignore_explicit_for_joined` setting (hibernate.discriminator.ignore_explicit_for_joined=true)
  2020-05-12 14:26:52.979  INFO 17808 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
  2020-05-12 14:26:52.985  INFO 17808 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  Custom Service
  2020-05-12 14:26:53.966  INFO 17808 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@1aa59698, org.springframework.security.web.context.SecurityContextPersistenceFilter@3dd750ba, org.springframework.security.web.header.HeaderWriterFilter@7b2d58e6, org.springframework.security.web.csrf.CsrfFilter@2b1d1a5, org.springframework.security.web.authentication.logout.LogoutFilter@3dfc59c5, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@5c25daad, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@160546b1, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@2cacb445, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@4641f66c, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@7d5ef1c3, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@395eb363, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@1e7cfd49, org.springframework.security.web.session.SessionManagementFilter@377e90b0, org.springframework.security.web.access.ExceptionTranslationFilter@2a6dbb7c, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@2419fe6f]
  2020-05-12 14:26:54.095  INFO 17808 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
  2020-05-12 14:26:54.162  INFO 17808 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
  2020-05-12 14:26:54.568  INFO 17808 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
  2020-05-12 14:26:54.569  INFO 17808 --- [           main] o.T.projects.mytunes.MyTunesApplication  : Started MyTunesApplication in 4.725 seconds (JVM running for 5.243)
  2020-05-12 14:27:06.197  INFO 17808 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
  2020-05-12 14:27:06.197  INFO 17808 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
  2020-05-12 14:27:06.210  INFO 17808 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 13 ms
  </code></pre>
  <p>As you can see, &quot;Custom Service&quot; is printed so the object is correctly instantiated. I tried to log in and nothing got printed. So it seems like it's not used, but why?</p>
  <p>I'm getting looped using</p>
  <pre><code>@Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().httpBasic();
      }
  </code></pre>
  <p>If using</p>
  <pre><code>@Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
      }
  </code></pre>
  <p>It works, but the log in is done in a pop up, and I want a page with a form.</p>
  <p>It seems like the loop bug while using a &quot;form page&quot; was due to my navigator (opera GX). Used chrome and the problem vanished.</p>
  <p>Well ... The problem was truly due to user not accepting cookies, not from the navigator itself. But still, Opera GX seems to manage cookies in a strange way.</p>