mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-20 19:20:04 +00:00
bug4312 Replaced boolean auth nav param with enum for more flexibility
This commit is contained in:
1 parent
cd87c1981a
commit
0b80381d2b
17 files changed
+96
-60
No files matched your search
+1
-1
@@ -159,7 +159,7 @@ public class AuthenticationManagerImpl implements AuthenticationManager {
|
||||
@Override
|
||||
public void logout() {
|
||||
userService.logout();
|
||||
eventBus.fireEvent(new AuthenticationRequestEvent(false));
|
||||
eventBus.fireEvent(new AuthenticationRequestEvent(AuthenticationPlaces.SIGN_IN));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+20
-7
@@ -24,6 +24,8 @@ import com.sap.sse.security.ui.authentication.view.AuthenticationView;
|
||||
*/
|
||||
public class AuthenticationPlaceManagementController extends WrappedPlaceManagementController {
|
||||
|
||||
private final AuthenticationClientFactory clientFactory;
|
||||
|
||||
/**
|
||||
* Creates a new {@link AuthenticationPlaceManagementController} instance with the given parameters.
|
||||
*
|
||||
@@ -35,14 +37,25 @@ public class AuthenticationPlaceManagementController extends WrappedPlaceManagem
|
||||
public AuthenticationPlaceManagementController(AuthenticationClientFactory clientFactory,
|
||||
AuthenticationCallback callback, AuthenticationView authenticationView, EventBus globalEventBus) {
|
||||
super(new Configuration(clientFactory, callback, authenticationView));
|
||||
globalEventBus.addHandler(AuthenticationContextEvent.TYPE, new AuthenticationContextEvent.Handler() {
|
||||
@Override
|
||||
public void onUserChangeEvent(AuthenticationContextEvent event) {
|
||||
AuthenticationPlaceManagementController.this.fireEvent(event);
|
||||
}
|
||||
});
|
||||
this.clientFactory = clientFactory;
|
||||
globalEventBus.addHandler(AuthenticationContextEvent.TYPE, this::fireEvent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tells the wrapped framework to go to the {@link Place} represented by the given {@link AuthenticationPlaces}
|
||||
* instance is no user is logged in. Otherwise the wrapped framework will go to the {@link LoggedInUserInfoPlace
|
||||
* user info} page.
|
||||
*
|
||||
* @param authPlace
|
||||
* {@link AuthenticationPlaces} instance representing a {@link Place} instance to go to
|
||||
*
|
||||
* @see #goTo(Place)
|
||||
*/
|
||||
public void goTo(AuthenticationPlaces authPlace) {
|
||||
final boolean isLoggedIn = clientFactory.getAuthenticationManager().getAuthenticationContext().isLoggedIn();
|
||||
super.goTo(isLoggedIn ? new LoggedInUserInfoPlace() : authPlace.getPlace());
|
||||
}
|
||||
|
||||
private static class Configuration implements PlaceManagementConfiguration {
|
||||
private final AuthenticationClientFactory clientFactory;
|
||||
private final AuthenticationCallback callback;
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.sap.sse.security.ui.authentication;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.sap.sse.security.ui.authentication.create.CreateAccountPlace;
|
||||
import com.sap.sse.security.ui.authentication.signin.SignInPlace;
|
||||
|
||||
/**
|
||||
* Enumeration to specify a requested {@link AbstractAuthenticationPlace authentication places}.
|
||||
*/
|
||||
public enum AuthenticationPlaces {
|
||||
|
||||
/** {@link AuthenticationPlaces} representation for {@link SignInPlace} */
|
||||
SIGN_IN(SignInPlace::new),
|
||||
/** {@link AuthenticationPlaces} representation for {@link CreateAccountPlace} */
|
||||
CREATE_ACCOUNT(CreateAccountPlace::new);
|
||||
|
||||
private final Supplier<? extends AbstractAuthenticationPlace> placeSupplier;
|
||||
|
||||
private AuthenticationPlaces(Supplier<? extends AbstractAuthenticationPlace> placeSupplier) {
|
||||
this.placeSupplier = placeSupplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return new instance of the {@link AbstractAuthenticationPlace} represented by this {@link AuthenticationPlaces}
|
||||
*/
|
||||
public AbstractAuthenticationPlace getPlace() {
|
||||
return this.placeSupplier.get();
|
||||
}
|
||||
|
||||
}
|
||||
+5
-5
@@ -9,18 +9,18 @@ import com.google.gwt.event.shared.GwtEvent;
|
||||
public class AuthenticationRequestEvent extends GwtEvent<AuthenticationRequestEvent.Handler> {
|
||||
public static final Type<Handler> TYPE = new Type<AuthenticationRequestEvent.Handler>();
|
||||
|
||||
private final boolean register;
|
||||
private final AuthenticationPlaces requestedPlace;
|
||||
|
||||
public AuthenticationRequestEvent(boolean register) {
|
||||
this.register = register;
|
||||
public AuthenticationRequestEvent(AuthenticationPlaces requestedPlace) {
|
||||
this.requestedPlace = requestedPlace;
|
||||
}
|
||||
|
||||
public interface Handler extends EventHandler {
|
||||
void onUserManagementRequestEvent(AuthenticationRequestEvent event);
|
||||
}
|
||||
|
||||
public boolean isRegister() {
|
||||
return register;
|
||||
public AuthenticationPlaces getRequestedPlace() {
|
||||
return requestedPlace;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.sap.sse.security.ui.authentication.decorator;
|
||||
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationPlaces;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationRequestEvent;
|
||||
|
||||
/**
|
||||
@@ -19,6 +20,6 @@ public class FlyoutNotLoggedInPresenter implements NotLoggedInPresenter {
|
||||
|
||||
@Override
|
||||
public void doTriggerLoginForm() {
|
||||
eventBus.fireEvent(new AuthenticationRequestEvent(false));
|
||||
eventBus.fireEvent(new AuthenticationRequestEvent(AuthenticationPlaces.SIGN_IN));
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -7,6 +7,7 @@ import com.google.gwt.user.client.ui.AcceptsOneWidget;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationCallback;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationClientFactory;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationContextEvent;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationPlaces;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationRequestEvent;
|
||||
import com.sap.sse.security.ui.authentication.signin.SignInPlace;
|
||||
|
||||
@@ -45,7 +46,7 @@ public class LoggedInUserInfoActivity extends AbstractActivity implements Logged
|
||||
|
||||
@Override
|
||||
public void gotoProfileUi() {
|
||||
eventBus.fireEvent(new AuthenticationRequestEvent(false));
|
||||
eventBus.fireEvent(new AuthenticationRequestEvent(AuthenticationPlaces.SIGN_IN));
|
||||
callback.handleUserProfileNavigation();
|
||||
}
|
||||
|
||||
|
||||
+5
-10
@@ -2,6 +2,7 @@ package com.sap.sse.security.ui.authentication.view;
|
||||
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationContextEvent;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationPlaceManagementController;
|
||||
import com.sap.sse.security.ui.authentication.AuthenticationRequestEvent;
|
||||
import com.sap.sse.security.ui.authentication.WrappedPlaceManagementController;
|
||||
import com.sap.sse.security.ui.authentication.app.AuthenticationContext;
|
||||
@@ -34,7 +35,7 @@ public class FlyoutAuthenticationPresenter implements AuthenticationMenuView.Pre
|
||||
*/
|
||||
public FlyoutAuthenticationPresenter(final FlyoutAuthenticationView flyoutAuthenticationView,
|
||||
final AuthenticationMenuView authenticationMenuView,
|
||||
WrappedPlaceManagementController authenticationPlaceManagementController,
|
||||
AuthenticationPlaceManagementController authenticationPlaceManagementController,
|
||||
EventBus eventBus, AuthenticationContext initialAuthentication) {
|
||||
this.flyoutAuthenticationView = flyoutAuthenticationView;
|
||||
this.authenticationMenuView = authenticationMenuView;
|
||||
@@ -45,15 +46,9 @@ public class FlyoutAuthenticationPresenter implements AuthenticationMenuView.Pre
|
||||
authenticationMenuView.setPresenter(this);
|
||||
flyoutAuthenticationView.setAutoHidePartner(authenticationMenuView);
|
||||
|
||||
eventBus.addHandler(AuthenticationRequestEvent.TYPE, new AuthenticationRequestEvent.Handler() {
|
||||
@Override
|
||||
public void onUserManagementRequestEvent(AuthenticationRequestEvent event) {
|
||||
if(event.isRegister()){
|
||||
showRegister();
|
||||
}else{
|
||||
toggleFlyout();
|
||||
}
|
||||
}
|
||||
eventBus.addHandler(AuthenticationRequestEvent.TYPE, event -> {
|
||||
flyoutAuthenticationView.show();
|
||||
authenticationPlaceManagementController.goTo(event.getRequestedPlace());
|
||||
});
|
||||
|
||||
eventBus.addHandler(AuthenticationContextEvent.TYPE, new AuthenticationContextEvent.Handler() {
|
||||
|
||||
Reference in new issue
Block a user