bug4312 Replaced boolean auth nav param with enum for more flexibility

This commit is contained in:
Benjamin Barth committed 2017-10-27 16:58:58 +02:00
1 parent cd87c1981a
commit 0b80381d2b
17 files changed
+96 -60

No files matched your search

@@ -35,7 +35,6 @@ import com.sap.sse.security.ui.authentication.AuthenticationClientFactoryImpl;
import com.sap.sse.security.ui.authentication.AuthenticationManager;
import com.sap.sse.security.ui.authentication.AuthenticationManagerImpl;
import com.sap.sse.security.ui.authentication.AuthenticationPlaceManagementController;
import com.sap.sse.security.ui.authentication.WrappedPlaceManagementController;
import com.sap.sse.security.ui.authentication.info.LoggedInUserInfoPlace;
import com.sap.sse.security.ui.authentication.view.FlyoutAuthenticationPresenter;
import com.sap.sse.security.ui.client.i18n.StringMessages;
@@ -43,7 +42,7 @@ import com.sap.sse.security.ui.client.i18n.StringMessages;
public class TabletAndDesktopApplicationClientFactory extends AbstractApplicationClientFactory<DesktopApplicationTopLevelView> implements DesktopClientFactory {
private final SailingDispatchSystem dispatch = new SailingDispatchSystemImpl();
private final WrappedPlaceManagementController userManagementWizardController;
private final AuthenticationPlaceManagementController userManagementWizardController;
private final AuthenticationManager authenticationManager;
public TabletAndDesktopApplicationClientFactory(boolean isStandaloneServer) {
@@ -3,13 +3,14 @@ package com.sap.sailing.gwt.home.desktop.places.morelogininformation;
import com.google.gwt.place.shared.Place;
import com.sap.sailing.gwt.home.desktop.app.DesktopClientFactory;
import com.sap.sailing.gwt.home.shared.places.morelogininformation.AbstractMoreLoginInformationActivity;
import com.sap.sse.security.ui.authentication.AuthenticationPlaces;
import com.sap.sse.security.ui.authentication.AuthenticationRequestEvent;
public class MoreLoginInformationActivity extends AbstractMoreLoginInformationActivity {
public MoreLoginInformationActivity(Place place, DesktopClientFactory clientFactory) {
super(clientFactory, new MoreLoginInformationDesktop(
() -> clientFactory.getEventBus().fireEvent(new AuthenticationRequestEvent(true))));
super(clientFactory, new MoreLoginInformationDesktop(() -> clientFactory.getEventBus()
.fireEvent(new AuthenticationRequestEvent(AuthenticationPlaces.CREATE_ACCOUNT))));
}
}
@@ -17,6 +17,7 @@ import com.sap.sailing.gwt.home.shared.places.fakeseries.AbstractSeriesPlace;
import com.sap.sailing.gwt.home.shared.places.start.StartPlace;
import com.sap.sailing.gwt.home.shared.places.user.profile.AbstractUserProfilePlace;
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.client.i18n.StringMessages;
@@ -91,7 +92,7 @@ public class UserProfileActivity extends AbstractActivity implements UserProfile
@Override
public void doTriggerLoginForm() {
clientFactory.getEventBus().fireEvent(new AuthenticationRequestEvent(false));
clientFactory.getEventBus().fireEvent(new AuthenticationRequestEvent(AuthenticationPlaces.SIGN_IN));
}
@Override
@@ -80,7 +80,7 @@ public class MobileApplicationClientFactory extends
dismissCallback.run();
navigator.goToPlace(navigator.getMoreLoginInfo());
},() -> {
navigator.goToPlace(navigator.getSignInNavigation(false));
navigator.goToPlace(navigator.getSignInNavigation());
});
root.setSubHeaderContent(content);
});
@@ -9,6 +9,7 @@ import com.sap.sailing.gwt.home.mobile.places.user.authentication.Authentication
import com.sap.sailing.gwt.home.shared.app.HomePlacesNavigator;
import com.sap.sailing.gwt.home.shared.app.PlaceNavigation;
import com.sap.sailing.gwt.home.shared.places.event.EventContext;
import com.sap.sse.security.ui.authentication.AuthenticationPlaces;
public class MobilePlacesNavigator extends HomePlacesNavigator {
@@ -22,8 +23,12 @@ public class MobilePlacesNavigator extends HomePlacesNavigator {
return createPlaceNavigation(baseUrl, isOnRemoteServer, place);
}
public PlaceNavigation<AuthenticationPlace> getSignInNavigation(boolean registerView) {
return createLocalPlaceNavigation(new AuthenticationPlace(registerView));
public PlaceNavigation<AuthenticationPlace> getSignInNavigation() {
return createLocalPlaceNavigation(new AuthenticationPlace(AuthenticationPlaces.SIGN_IN));
}
public PlaceNavigation<AuthenticationPlace> getCreateAccountNavigation() {
return createLocalPlaceNavigation(new AuthenticationPlace(AuthenticationPlaces.CREATE_ACCOUNT));
}
}
@@ -68,7 +68,7 @@ public class Header extends Composite {
signInNavigationItem = addNavigation(com.sap.sse.security.ui.client.i18n.StringMessages.INSTANCE.signIn(), new Runnable() {
@Override
public void run() {
placeNavigator.getSignInNavigation(false).goToPlace();
placeNavigator.getSignInNavigation().goToPlace();
}
});
userDetailsNavigationItem = addNavigation(placeNavigator.getUserProfileNavigation(), com.sap.sse.security.ui.client.i18n.StringMessages.INSTANCE.userDetails());
@@ -8,7 +8,7 @@ public class MoreLoginInformationActivity extends AbstractMoreLoginInformationAc
public MoreLoginInformationActivity(Place place, MobileApplicationClientFactory clientFactory) {
super(clientFactory, new MoreLoginInformationMobile(
() -> clientFactory.getNavigator().getSignInNavigation(true).goToPlace()));
() -> clientFactory.getNavigator().getCreateAccountNavigation().goToPlace()));
}
}
@@ -10,39 +10,27 @@ import com.sap.sailing.gwt.home.shared.usermanagement.AuthenticationCallbackImpl
import com.sap.sailing.gwt.home.shared.usermanagement.view.AuthenticationViewMobile;
import com.sap.sse.security.ui.authentication.AuthenticationClientFactoryImpl;
import com.sap.sse.security.ui.authentication.AuthenticationPlaceManagementController;
import com.sap.sse.security.ui.authentication.WrappedPlaceManagementController;
import com.sap.sse.security.ui.authentication.create.CreateAccountPlace;
import com.sap.sse.security.ui.authentication.view.AuthenticationView;
public class AuthenticationActivity extends AbstractActivity {
private final MobileApplicationClientFactory clientFactory;
private final AuthenticationView userManagementView = new AuthenticationViewMobile();
private boolean register;
private final AuthenticationPlace place;
public AuthenticationActivity(AuthenticationPlace place, MobileApplicationClientFactory clientFactory) {
register = place.isRegisterView();
this.clientFactory = clientFactory;
this.place = place;
}
@Override
public void start(final AcceptsOneWidget panel, EventBus eventBus) {
panel.setWidget(userManagementView);
WrappedPlaceManagementController userManagementController = new AuthenticationPlaceManagementController(
final AuthenticationPlaceManagementController userManagementController = new AuthenticationPlaceManagementController(
new AuthenticationClientFactoryImpl(clientFactory.getAuthenticationManager(), SharedResources.INSTANCE),
new AuthenticationCallbackImpl(clientFactory.getNavigator().getUserProfileNavigation(),
new SignInSuccessfulNavigationMobile()),
() -> History.back()),
userManagementView, eventBus);
userManagementController.start();
if(register){
userManagementController.goTo(new CreateAccountPlace());
}
userManagementController.goTo(place.getRequestedPlace());
}
private class SignInSuccessfulNavigationMobile implements Runnable {
@Override
public void run() {
History.back();
}
}
}
@@ -6,14 +6,15 @@ import com.google.gwt.place.shared.Prefix;
import com.sap.sailing.gwt.home.shared.app.HasLocationTitle;
import com.sap.sailing.gwt.home.shared.app.HasMobileVersion;
import com.sap.sailing.gwt.home.shared.places.PlaceTokenPrefixes;
import com.sap.sse.security.ui.authentication.AuthenticationPlaces;
import com.sap.sse.security.ui.client.i18n.StringMessages;
public class AuthenticationPlace extends Place implements HasMobileVersion, HasLocationTitle {
private boolean registerView;
private final AuthenticationPlaces requestedPlace;
public AuthenticationPlace(boolean registerView) {
this.registerView = registerView;
public AuthenticationPlace(AuthenticationPlaces requestedPlace) {
this.requestedPlace = requestedPlace;
}
@Override
@@ -21,8 +22,8 @@ public class AuthenticationPlace extends Place implements HasMobileVersion, HasL
return StringMessages.INSTANCE.user();
}
public boolean isRegisterView() {
return registerView;
public AuthenticationPlaces getRequestedPlace() {
return requestedPlace;
}
@Prefix(PlaceTokenPrefixes.UserAuthentication)
@@ -34,7 +35,7 @@ public class AuthenticationPlace extends Place implements HasMobileVersion, HasL
@Override
public AuthenticationPlace getPlace(String token) {
return new AuthenticationPlace(false);
return new AuthenticationPlace(AuthenticationPlaces.SIGN_IN);
}
}
@@ -15,7 +15,7 @@ public abstract class AbstractUserProfileActivity extends AbstractActivity imple
@Override
public void doTriggerLoginForm() {
clientFactory.getNavigator().getSignInNavigation(false).goToPlace();
clientFactory.getNavigator().getSignInNavigation().goToPlace();
}
@Override
@@ -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
@@ -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;
@@ -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();
}
}
@@ -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
@@ -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));
}
}
@@ -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();
}
@@ -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() {