title: How to handle login success in Spring Security
body: <p>Apologies if my question seems like something a novice would ask. I am new to the Spring world. I am using Spring Security to authenticate users. Authentication is working properly, but after authentication success I want Spring to call the Controller method .`</p>
  
  <pre><code>    @RequestMapping(value = "/login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
      public JwtAuthenticationResponse userLogin() {
  System.out.println("Login Success");
          JwtUser user = (JwtUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
          String token = userService.generateToken(authenticationService.loadUserByUsername(user.getUsername()));
          JwtAuthenticationResponse response = new JwtAuthenticationResponse(token, user.getAuthorities().toArray(),user.getUsername());
          return response;
      }
  }
  </code></pre>
  
  <p>In Spring Security Configuration I added the following</p>
  
  <pre><code>    http.authorizeRequests().anyRequest().permitAll().and().formLogin().loginProcessingUrl("/login").defaultSuccessUrl("/login");
  
  http.addFilterBefore(filter,UsernamePasswordAuthenticationFilter.class);
  </code></pre>
  
  <p>In this case, it is returning a default Spring Login form. It is not calling my controller method.</p>
  
  <p>I made the request using</p>
  
  <pre><code>http://localhost:8080/myapp/login
  </code></pre>
  
  <p>Can someone suggest what I have to do to invoke the Controller after login is successful, in order to send the Authentication token after login.</p>
  
  <p>Appreciate any help!</p>
  
  <p>Thank you </p>