title: Spring boot - return user object after log in
body: <p>I have a spring boot application with WebSecurityConfigurerAdapter configured like this - </p>
  
  <pre><code>http.csrf().disable()
                      .exceptionHandling()
                      .authenticationEntryPoint(restAuthenticationEntryPoint)
                      .and()
                  .authorizeRequests()
                      .antMatchers("/user/*", "/habbit/*").authenticated()
                      .and()
                  .formLogin()
                      .loginProcessingUrl("/login")
                      .permitAll()
                      .usernameParameter("email")
                      .passwordParameter("pass")
                      .successHandler(authenticationSuccessHandler)
                      .failureHandler(new SimpleUrlAuthenticationFailureHandler())
                      .and()
                  .logout()
                      .logoutUrl("/logout")
                      .invalidateHttpSession(true);
  </code></pre>
  
  <p>Can I add something like my own controller that would, after successful authentication, return back a custom object with some details about the authenticated user?</p>
  
  <p><strong>Update:</strong>
  To clarity, i'm using an angular application as the client.
  Currently I need to make 2 requests form my client to the server:
  1. POST request to /login URL for authentication.
  2. GET request to retrieve authenticated user data.</p>
  
  <p>My aim is to have the 1st request return to me user information so I don't have to make the 2dn request. 
  Currently the 1st request only authenticates the user, creates a session on the server and send back a '200 OK' status response with <strong>no data</strong>. I want it to return a success response <strong>with data</strong> about the logged in user.</p>
  
  <p><strong>Answered:</strong></p>
  
  <p>The correct answer is in comments so i will write it here:
  I needed to redirect from my successHandler to my controller which in turn returns the currently logged in user info ( in my case controller is in url '/user/me': </p>
  
  <pre><code> @Override
      public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
                                          Authentication authentication) throws ServletException, IOException {
          clearAuthenticationAttributes(request);
          getRedirectStrategy().sendRedirect(request, response, "/user/me");
      }
  </code></pre>