title: Spring Security Disable Login Page / Redirect
body: <p>Is there a way to disable the redirect for Spring Security and the login page. My requirements specify the login should be part of the navigation menu.</p>
  
  <p>Example:</p>
  
  <p><a href="https://i.stack.imgur.com/Ei3OF.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ei3OF.png" alt="enter image description here"></a></p>
  
  <p>Therefore there is no dedicated login page. The login information needs to be submitted via Ajax. If an error occurs it should return JSON specifying the error and use the proper HTTP Status code. If authentication checks out it should return a 200 and then javascript can handle it from there.</p>
  
  <p>I hope that makes sense unless there is any easier way to accomplish this with Spring Security. I don't have much experience with Spring Security. I assume this has to be a common practice, but I didn't find much.</p>
  
  <p>Current spring security configuration</p>
  
  <pre><code>@Configuration
  @EnableGlobalMethodSecurity(prePostEnabled = true)
  @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
      @Autowired
      private UserDetailsService userDetailsService;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests()
                  .antMatchers("/", "/public/**").permitAll()
                  .antMatchers("/about").permitAll()
                  .anyRequest().fullyAuthenticated()
                  .and()
                  .formLogin()
                  .loginPage("/login")
                  .failureUrl("/login?error")
                  .usernameParameter("email")
                  .permitAll()
                  .and()
                  .logout()
                  .logoutUrl("/logout")
                  .deleteCookies("remember-me")
                  .logoutSuccessUrl("/")
                  .permitAll()
                  .and()
                  .rememberMe();
      }
  
      @Override
      public void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth
                  .userDetailsService(userDetailsService)
                  .passwordEncoder(new BCryptPasswordEncoder());
      }
  </code></pre>
  
  <p>Update:</p>
  
  <p>I tried using HttpBasic() but then it asks for login creds not matter what and its the ugly browser popup which is not acceptable to the end user. It looks like I may have to extend AuthenticationEntryPoint.</p>
  
  <p>At the end of the day I need Spring security to send back JSON saying the authentication succeeded or failed.</p>