1
votes

Im using GWTP in my GWT app and have the following architecture:

LoginPresenter (Presenter)
    DashboardPresenter (TabContainerPresenter)
        TabbedPresenter1 (Presenter)
        TabbedPresenter2 (Presenter)
        TabbedPresenter3 (Presenter)

The first time I start my app, the onBind and addTab methods are called in the DashboardPresenter and when I navigate to a tab, the onbind method is called on that presenter.

If I create a PlaceRequest and navigate back to LoginPresenter via my PlaceManager (by pressing a logout button), I return to the login presenter.

The problem is that if I login again, then all the onBind methods are not called because they are still in memory. onReset and onReveal are called correctly, but I would very much like that each Presenter are reset and that the onBind will be called on each login.

I decide on the login event which tabs should be visible for user and restrict tabs in the addTab method of the DashboardPresenter if the user does not have sufficient rights to see those tabs. But as of now, the tabs are setup the first time a user logs in, but not the next time. This means that if a user with lesser rights logs in after an admin user, he can see the same tabs as the admin. Not good!

How should I deal with this? I would very much like to "reset" all presenters or the session when a user logsout (navigating to the login page). Is it the Ginjector that needs to be "reset", so that it does not return the same binded objects as before?

Just to clarify: we do have server side security which prohibits users with no rights to access sensitive data. But when the user logs in, the gwt app receives a list of features which the user can access. This is used for customizing the UI to fit the rights of the user. (E.g. customize the visible tabs based on users privileges).

2
I should add that Im not currently using the unbind methods on the presenters, since im not sure what happens exactly when these methods are invoked. - Rasmus Nielsen
My solution, at the moment, is to do a complete page reload using Window.Location.reload(). Im not very fond of this, but it does the trick. Still need a good solution on "resetting" my web app on a logout event... - Rasmus Nielsen
FYI the onUnBind() methods should be called manually, thus they're not applicable in your situation (Cf. stackoverflow.com/questions/13396992/…). - Anders R. Bystrup

2 Answers

0
votes

I am not sure if this work:

But you could try to fire a LogoutEvent on the global EventBus , handle it in all Presenters that need to be "unloaded" (TabbedPresenter1, etc) and call onUnbind() on them. Afterwards navigate back to the LoginPresenter

Alternatively you could make us of a custom TabData (subclass TabDataBasic and add a flag hasAccess). Again you fire a LogoutEvent and when you handle it you can do something like that:

TabDataDynamic tabData = (TabDataDynamic)getProxy().getTabData();
tabData.setHasAccess(false);
getProxy().changeTab(tabData);

In yout TabPanel implementation you have to make sure that the Tab is hidden, when the flag is set to false.

0
votes

I think that you should take a look to GateKeeper which can be easily used with presenters like:

@ProxyCodeSplit
@NameToken(NameTokens....)
@UseGatekeeper( Your1GateKeeper.class)
public interface MyProxy extends TabContentProxyPlace<YourPresenter> {
}

And you can inject a Dashboard presenter to GateKeeper to check is this tab available:

@Singleton
public class Your1GateKeeper implements Gatekeeper{

 private DashboardPresenter presenter;

 @Inject
 public ReadOnlyGateKeeper(DashboardPresenter presenter) {
    this.presenter = presenter;
 }

 @Override
 public boolean canReveal() {
    return presenter.isAvailable();
 }

}

So using appropriate GateKeepers will allow you to reach required security.