title: Spring Security: SecurityContextHolder.getContext().getAuthentication() returns null after user registering user and redirecting to after login page
body: <p>After user is registered successfully, i am trying to redirect user to after login page and trying to get the Active user from SecurityContextHolder.getContext().getAuthentication(); which is returning null.</p>
  
  <p>Here is how i am setting context when user is successfully registered</p>
  
  <pre><code> UsernamePasswordAuthenticationToken authenticatedUser = new UsernamePasswordAuthenticationToken(userDetails.getUsername(), userDetails.getPassword(), userDetails.getAuthorities());
   authenticatedUser.setDetails(userDetails);
  
   if(authenticatedUser.isAuthenticated()) {
          SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
   }
  </code></pre>
  
  <p>Then i am redirecting user to x page using response.sendRedirect(url);</p>
  
  <p>In the controller method i am trying to the current user as </p>
  
  <pre><code>@RequestMapping("/&lt;pattern&gt;")
  public @ResponseBody &lt;method_name&gt;(HttpServletRequest req,HttpServletResponse resp){
       Authentication auth = SecurityContextHolder.getContext().getAuthentication();
          if(auth==null){
              System.out.println("this is null");
          }
          else{
            // do something
          }
  }
  </code></pre>
  
  <p>I am seeing the text in console as "this is null".</p>
  
  <p>How to get retain the currentuser/Principal from SecurityContext() through out the user period till user logs out.</p>