On Sunday, June 5, 2011 2:31:13 PM UTC+2, Adam T wrote:
>
> Hi, 
>
> I think you can do this relatively simply, but it's not directly noted 
> in the documentation. 
>
> (warning, a little plug ahead...) We're looking at how to do this for 
> the 2nd edition of the GWT in Action book, and the approach below is 
> where we are at the moment, though we have not thought through all 
> implementations yet.  The final solution will be described in detail 
> in the book, but the following is the essence of the current solution: 
>
> *  GWT has a FilteredActivityMapper that you can use to run another 
> activity rather than the one associated with the requested Place; for 
> example if you go to a PhotoEditPlace when not logged in, you might 
> want to run the LoginActivity rather than PhotoEditActivity.
>

This is basically what's causing the issue to all three of you. You'd rather 
either treat authentication as an orthogonal concern to navigation (that 
each activity then takes account of; possibly wrapping the "real" activity 
in a "guard" activity if you want to also decouple authentication from your 
activities: the "guard" activity would show a landing screen or whatever 
until it receives a LoginEvent and then starts the wrapped "real" activity) 
or treat it as a distinct place (similar to what you'd have with HTTP 
redirects).
 

> *  To do that, we created a Filter, such as: 
>
>         Filter filter = new Filter(){ 
> public Place filter(Place place) { 
>                                 // Always allow the WelcomePlace 
> if(place instanceof WelcomePlace) return place; 
>
>                                 // If user is not logged in, redirect 
> the activity for requested place to the login activity 
> if(!isLoggedIn()) return loginPlace; 
>
>                                 // If user is logged in, then allow 
> the requested place/activity 
> else return place; 
> }}; 
>
> * To use the filter, we created the ActivityMapper using a 
> FilteredActivityMapper instead of the standard ActivityMapper, i.e.: 
>
>         // Difference to normal here 
>         ActivityMapper activityMapper = new 
> FilteredActivityMapper(filter, new AppActivityMapper(clientFactory)); 
>         // Carry on as normal from here 
>         ActivityManager activityManager = new 
> ActivityManager(activityMapper, eventBus);
>

With the exception that you're splitting things into a 
FilteredActivityMapper, you're basically doing the same as Stevko already 
proposed.
 

> * In the login activity, there is code to refresh the browser page if 
> the user logs in successfully (a simple Window.Location.reload() has 
> worked so far)
>

If you can leave with a browser refresh, you'd better authenticate outside 
your app: redirect to a login page that redirects back to the app, so that 
when the app initializes you know whether the user is authenticated or not, 
and you could even load a distinct GWT app: one for unauthenticated users, a 
different one for authenticated ones.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/cVpzTzRHUkJlVjRK.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to