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.stereotype.Service;
9 import org.springframework.web.context.request.NativeWebRequest;
13 * Simple implementation of {@link SignInAdapter}.
15 * We configured Spring-Social to call this implementation, to sign in the
16 * user, after he was authenticated by Facebook.
21 public class UserCookieSignInAdapter implements SignInAdapter
23 private final static Logger LOG =
24 LoggerFactory.getLogger(UserCookieSignInAdapter.class);
28 * Stores the user in the security-context to sign him in.
29 * Also remembers the user for subsequent calls by storing the ID in the
33 * The user-ID. We configured Spring-Social to call
34 * {@link UserCookieSignInAdapter} to extract a user-ID from the
37 * The connection. In our case a connection to Facebook.
39 * The actual request. We need it, to store the cookie.
41 * We return <code>null</code>, to indicate, that the user should be
42 * redirected to the default-post-sign-in-URL (configured in
43 * {@link ProviderSinInController}) after a successfull authentication.
45 * @see {@link UserCookieSignInAdapter}
46 * @see {@link ProviderSignInController#postSignInUrl}
51 Connection<?> connection,
52 NativeWebRequest request
56 "signing in user {} (connected via {})",
58 connection.getKey().getProviderId()
60 SecurityContext.setCurrentUser(user);
63 .addCookie(user, request.getNativeResponse(HttpServletResponse.class));
65 // We return null to trigger a redirect to "/".