1 package de.juplo.yourshouter;
3 import javax.servlet.http.HttpServletResponse;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6 import org.springframework.social.connect.Connection;
7 import org.springframework.social.connect.web.SignInAdapter;
8 import org.springframework.web.context.request.NativeWebRequest;
12 * Simple implementation of {@link SignInAdapter}.
14 * We configured Spring-Social to call this implementation, to sign in the
15 * user, after he was authenticated by Facebook.
19 public class UserCookieSignInAdapter implements SignInAdapter
21 private final static Logger LOG =
22 LoggerFactory.getLogger(UserCookieSignInAdapter.class);
26 * Stores the user in the security-context to sign him in.
27 * Also remembers the user for subsequent calls by storing the ID in the
31 * The user-ID. We configured Spring-Social to call
32 * {@link UserCookieSignInAdapter} to extract a user-ID from the
35 * The connection. In our case a connection to Facebook.
37 * The actual request. We need it, to store the cookie.
39 * We return <code>null</code>, to indicate, that the user should be
40 * redirected to the default-post-sign-in-URL (configured in
41 * {@link ProviderSinInController}) after a successfull authentication.
43 * @see {@link UserCookieSignInAdapter}
44 * @see {@link ProviderSignInController#postSignInUrl}
49 Connection<?> connection,
50 NativeWebRequest request
54 "signing in user {} (connected via {})",
56 connection.getKey().getProviderId()
58 SecurityContext.setCurrentUser(user);
61 .addCookie(user, request.getNativeResponse(HttpServletResponse.class));
63 // We return null to trigger a redirect to "/".