Switched from the manual implemented authentication-layer to Spring Security
[examples/facebook-app] / src / main / java / de / juplo / yourshouter / SocialAuthenticationEntryPoint.java
diff --git a/src/main/java/de/juplo/yourshouter/SocialAuthenticationEntryPoint.java b/src/main/java/de/juplo/yourshouter/SocialAuthenticationEntryPoint.java
new file mode 100644 (file)
index 0000000..4c3671c
--- /dev/null
@@ -0,0 +1,50 @@
+package de.juplo.yourshouter;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * Specialized implementation of {@link AuthenticationEntryPoint}, that
+ * redirects to the social sign-in-page, to let the user decide to sign in or
+ * not.
+ *
+ * @author Kai Moritz
+ */
+@Service
+public class SocialAuthenticationEntryPoint implements AuthenticationEntryPoint
+{
+  private static final Logger LOG =
+      LoggerFactory.getLogger(SocialAuthenticationEntryPoint.class);
+
+
+  /**
+   * {@inheritDoc}
+   *
+   * To commence the sign-in through the Graph-API, we only have to redirect
+   * to our already implemented sign-in-page.
+   */
+  @Override
+  public void commence(
+      HttpServletRequest request,
+      HttpServletResponse response,
+      AuthenticationException exception
+      )
+      throws
+        IOException,
+        ServletException
+  {
+    LOG.info(
+        "redirecting unauthenticated request {} to /signin.html",
+        request.getRequestURI()
+        );
+    response.sendRedirect("/signin.html");
+  }
+}