Refactored authorization from HomeController to UserCookieInterceptor
[examples/facebook-app] / src / main / java / de / juplo / yourshouter / UserCookieInterceptor.java
index 6a6cba6..c72ef41 100644 (file)
@@ -1,6 +1,7 @@
 package de.juplo.yourshouter;
 
 
+import java.io.IOException;
 import java.util.Collections;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -52,6 +53,9 @@ public final class UserCookieInterceptor extends HandlerInterceptorAdapter
    * @return
    *     Always <code>true</code>, to indicate, that the intercepted request
    *     should be handled normally.
+   * @throws java.io.IOException
+   *     if something wents wrong, while sending the redirect to the
+   *     sign-in-page.
    */
   @Override
   public boolean preHandle(
@@ -59,7 +63,12 @@ public final class UserCookieInterceptor extends HandlerInterceptorAdapter
       HttpServletResponse response,
       Object handler
       )
+      throws
+        IOException
   {
+    if (request.getServletPath().startsWith("/signin"))
+      return true;
+
     String user = UserCookieGenerator.INSTANCE.readCookieValue(request);
     if (user != null)
     {
@@ -78,7 +87,9 @@ public final class UserCookieInterceptor extends HandlerInterceptorAdapter
         UserCookieGenerator.INSTANCE.removeCookie(response);
       }
     }
-    return true;
+
+    response.sendRedirect("/signin.html");
+    return false;
   }
 
   /**