Gatekeepers are used to protect places from unauthorized access. For example, a Gatekeeper could be set to protect a Presenter for which a user needs to log in.
Example of use:
import javax.inject.Inject;
import com.gwtplatform.mvp.client.proxy.Gatekeeper;
import com.project.shared.CurrentSession;
public class LoggedInGatekeeper implements Gatekeeper {
private final CurrentSession currentSession;
@Inject
LoggedInGatekeeper(CurrentSession currentSession) {
this.currentSession = currentSession;
}
@Override
public boolean canReveal() {
return currentSession.isLoggedIn();
}
}
By using canReveal() when a certain condition is met, in this case if a user is logged in, GWTP will automatically use the Gatekeeper to ensure access to the Presenter is authorized.
Gatekeeper Annotations
@DefaultGatekeeper
Used to set a class as the default Gatekeeper for ProxyPlaces that are not annotated with @UseGatekeeper. This is done simply by annotating your Gatekeeper class with @DefaultGatekeeper.
import javax.inject.Inject;
import com.gwtplatform.mvp.client.annotations.DefaultGatekeeper;
import com.gwtplatform.mvp.client.proxy.Gatekeeper;
import com.project.shared.CurrentSession;
@DefaultGatekeeper
public class LoggedInGatekeeper implements Gatekeeper {
private final CurrentSession currentSession;
@Inject
LoggedInGatekeeper(CurrentSession currentSession) {
this.currentSession = currentSession;
}
@Override
public boolean canReveal() {
return currentSession.isLoggedIn();
}
}
@UseGatekeeper
This annotation lets you define a Gatekeeper to use for the ProxyPlace associated with your Presenter.