Implemented a simple UserIdSource, that stores the user in a cookie
[examples/facebook-app] / src / main / java / de / juplo / yourshouter / ProviderUserIdConnectionSignUp.java
diff --git a/src/main/java/de/juplo/yourshouter/ProviderUserIdConnectionSignUp.java b/src/main/java/de/juplo/yourshouter/ProviderUserIdConnectionSignUp.java
new file mode 100644 (file)
index 0000000..fa4613d
--- /dev/null
@@ -0,0 +1,42 @@
+package de.juplo.yourshouter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.social.connect.Connection;
+import org.springframework.social.connect.ConnectionKey;
+import org.springframework.social.connect.ConnectionSignUp;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * Extracts the local user-ID from the data given by the provider.
+ *
+ * @author Kai Moritz
+ */
+@Service
+public class ProviderUserIdConnectionSignUp implements ConnectionSignUp
+{
+  private final Logger LOG =
+      LoggerFactory.getLogger(ProviderUserIdConnectionSignUp.class);
+
+
+  /**
+   * This implementation simply reuse the ID, that was provided by the provider.
+   *
+   * @param connection
+   *     The {@link Connection} for the unknown user.
+   * @return
+   *     The user-ID, that was provided by the provider.
+   */
+  @Override
+  public String execute(Connection<?> connection)
+  {
+    ConnectionKey key = connection.getKey();
+    LOG.info(
+        "signing up user {} from provider {}",
+        key.getProviderUserId(),
+        key.getProviderId()
+        );
+    return key.getProviderUserId();
+  }
+}