title: Howto integrate spring-social authentication with spring-security?
body: <p>I've got a little webapp secured by spring-security using a username/password combo on a sql-db as credentials.</p>
  
  <p>I now want to add facebook/twitter authentication with spring-social. Using the examples I am  able to store the users credentials in my db. I'm now working on authenticating the user against his current session on my app using the following piece of code:</p>
  
  <p><code></p>
  
  <pre><code>public String signIn(String userId, Connection&lt;?&gt; connection, NativeWebRequest request) {
  
      User user = userService.getUserById(Long.parseLong(userId));
      user.setPassword(this.passwordEncoder.encodePassword(user.getAccessToken(), this.salt));
      this.userService.store(user);
  
      UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getDisplayName(), user.getAccessToken());
  
      HttpServletRequest req = request.getNativeRequest(HttpServletRequest.class); // generate session if one doesn't exist
      token.setDetails(new WebAuthenticationDetails(req));
      Authentication authenticatedUser = this.authenticationManager.authenticate(token);
      SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
  
      return "/user/dashboard";
  }
  </code></pre>
  
  <p></code></p>
  
  <p>The authentication works, I am not getting any BadCredential-exceptions. But after being redirected to /user/dashboard I am thrown back to the login.</p>
  
  <p>I am out of ideas, a similar piece of code for authenticating the session is working after a classical signup.</p>
  
  <p>Does anyone have any ideas why this happens or how to debug this?</p>
  
  <p>Thanks very much in advance!
  Hendrik</p>