Revision: 8481
Author: [email protected]
Date: Wed Aug  4 14:25:37 2010
Log: Fix authentication redirection

Review at http://gwt-code-reviews.appspot.com/740801

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8481

Modified:
 /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/Scaffold.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/server/domain/GaeUserInformation.java /trunk/user/src/com/google/gwt/requestfactory/client/AuthenticationFailureHandler.java
 /trunk/user/src/com/google/gwt/requestfactory/client/LoginWidget.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java /trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
 /trunk/user/src/com/google/gwt/requestfactory/server/UserInformation.java
/trunk/user/src/com/google/gwt/requestfactory/shared/UserInformationRequest.java

=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/Scaffold.java Mon Aug 2 15:57:18 2010 +++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/Scaffold.java Wed Aug 4 14:25:37 2010
@@ -37,6 +37,7 @@
 import com.google.gwt.sample.expenses.gwt.request.ExpensesRequestFactory;
 import com.google.gwt.sample.expenses.gwt.ui.ListActivitiesMapper;
 import com.google.gwt.sample.expenses.gwt.ui.ScaffoldListPlaceRenderer;
+import com.google.gwt.user.client.Window.Location;
 import com.google.gwt.user.client.ui.RootLayoutPanel;
 import com.google.gwt.valuestore.shared.Record;
 import com.google.gwt.valuestore.shared.SyncResult;
@@ -91,7 +92,8 @@
         login.setUserInformation(userInformationRecord);
       }
      };
- requestFactory.userInformationRequest().getCurrentUserInformation().fire(receiver);
+     requestFactory.userInformationRequest().getCurrentUserInformation(
+         Location.getHref()).fire(receiver);

     /* Left side lets us pick from all the types of entities */

=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/server/domain/GaeUserInformation.java Mon Aug 2 15:57:18 2010 +++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/server/domain/GaeUserInformation.java Wed Aug 4 14:25:37 2010
@@ -28,8 +28,12 @@
 public class GaeUserInformation extends UserInformation {
private static UserService userService = UserServiceFactory.getUserService();

-  public static GaeUserInformation getCurrentUserInformation() {
-    return new GaeUserInformation();
+ public static GaeUserInformation getCurrentUserInformation(String redirectUrl) {
+    return new GaeUserInformation(redirectUrl);
+  }
+
+  public GaeUserInformation(String redirectUrl) {
+    super(redirectUrl);
   }

   public String getEmail() {
@@ -49,11 +53,11 @@
   }

   public String getLoginUrl() {
-    return userService.createLoginURL("RETURN_URL");
+    return userService.createLoginURL(redirectUrl);
   }

   public String getLogoutUrl() {
-    return userService.createLogoutURL("RETURN_URL");
+    return userService.createLogoutURL(redirectUrl);
   }

   public String getName() {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/AuthenticationFailureHandler.java Fri Jul 23 15:42:40 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/AuthenticationFailureHandler.java Wed Aug 4 14:25:37 2010
@@ -43,7 +43,6 @@
       }
       if (Response.SC_UNAUTHORIZED == response.getStatusCode()) {
         String loginUrl = response.getHeader("login");
-        loginUrl = loginUrl.replace("RETURN_URL", Location.getHref());
         Location.replace(loginUrl);
       }
       String newUser = response.getHeader("userId");
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/LoginWidget.java Mon Aug 2 15:57:18 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/LoginWidget.java Wed Aug 4 14:25:37 2010
@@ -44,7 +44,6 @@
   public void setUserInformation(UserInformationRecord info) {
     name.setInnerText(info.getName());
     logoutUrl = info.getLogoutUrl();
-    logoutUrl = logoutUrl.replace("RETURN_URL", Location.getHref());
   }

   @UiHandler("logoutLink")
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java Mon Aug 2 20:55:43 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java Wed Aug 4 14:25:37 2010
@@ -27,6 +27,7 @@
 import com.google.gwt.requestfactory.shared.RequestObject;
 import com.google.gwt.requestfactory.shared.RequestEvent.State;
 import com.google.gwt.requestfactory.shared.impl.JsonRequestDataUtil;
+import com.google.gwt.user.client.Window.Location;
 import com.google.gwt.valuestore.shared.Record;
 import com.google.gwt.valuestore.shared.impl.RecordJsoImpl;
 import com.google.gwt.valuestore.shared.impl.RecordSchema;
@@ -101,6 +102,7 @@
     } else {
       builder.setRequestData(requestObject.getRequestData());
     }
+    builder.setHeader("pageurl", Location.getHref());
     builder.setCallback(new RequestCallback() {

       public void onError(Request request, Throwable exception) {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java Mon Aug 2 20:55:43 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java Wed Aug 4 14:25:37 2010
@@ -35,7 +35,9 @@
* Handles GWT RequestFactory JSON requests. Does user authentication on every
  * request, returning SC_UNAUTHORIZED if authentication fails, as well as a
* header named "login" which contains the URL the user should be sent in to - * login. If authentication fails, a header named "userId" is returned, which
+ * login. Note that the servlet expects a "pageurl" header in the request,
+ * indicating the page to redirect to after authentication.
+ * If authentication succeeds, a header named "userId" is returned, which
* will be unique to the user (so the app can react if the signed in user has
  * changed).
  *
@@ -68,7 +70,8 @@

     try {
       // Check that user is logged in before proceeding
- UserInformation userInfo = UserInformation.getCurrentUserInformation();
+      UserInformation userInfo =
+ UserInformation.getCurrentUserInformation(request.getHeader("pageurl"));
       if (!userInfo.isUserLoggedIn()) {
         response.setHeader("login", userInfo.getLoginUrl());
         response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/UserInformation.java Mon Aug 2 15:57:18 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/server/UserInformation.java Wed Aug 4 14:25:37 2010
@@ -27,7 +27,12 @@
    * without any information.
    */
   private static class UserInformationSimpleImpl extends UserInformation {
+
     private Long id = 0L;
+
+    public UserInformationSimpleImpl(String redirectUrl) {
+      super(redirectUrl);
+    }

     public String getEmail() {
       return "";
@@ -60,18 +65,19 @@

   private static String userInformationImplClass = "";

-  public static UserInformation getCurrentUserInformation() {
+ public static UserInformation getCurrentUserInformation(String redirectUrl) {
     UserInformation userInfo = null;
     if (!userInformationImplClass.isEmpty()) {
       try {
-        userInfo =
- (UserInformation) Class.forName(userInformationImplClass).newInstance();
+        userInfo = (UserInformation) Class.forName(
+            userInformationImplClass).getConstructor(
+                String.class).newInstance(redirectUrl);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
     if (userInfo == null) {
-      userInfo = new UserInformationSimpleImpl();
+      userInfo = new UserInformationSimpleImpl(redirectUrl);
     }
     return userInfo;
   }
@@ -80,7 +86,14 @@
     userInformationImplClass = clazz;
   }

+  protected String redirectUrl = "";
   private Integer version = 0;
+
+  public UserInformation(String redirectUrl) {
+    if (redirectUrl != null) {
+      this.redirectUrl = redirectUrl;
+    }
+  }

   public abstract String getEmail();
   public abstract Long getId();
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/UserInformationRequest.java Mon Aug 2 15:57:18 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/shared/UserInformationRequest.java Wed Aug 4 14:25:37 2010
@@ -25,6 +25,6 @@
 @Service(UserInformation.class)
 public interface UserInformationRequest {

-  RecordRequest<UserInformationRecord> getCurrentUserInformation();
+ RecordRequest<UserInformationRecord> getCurrentUserInformation(String redirectUrl);

 }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to