User Management refactoring - Moved email validation and password reset

url references into AuthenticationManager
This commit is contained in:
Benjamin Barth committed 2016-01-27 16:13:16 +01:00
1 parent 21f80d231b
commit 00a8b1fd92
14 files changed
+56 -89

No files matched your search

@@ -60,7 +60,6 @@ public class TabletAndDesktopApplicationClientFactory extends AbstractApplicatio
private TabletAndDesktopApplicationClientFactory(EventBus eventBus, PlaceController placeController, DesktopPlacesNavigator placesNavigator) {
super(new TabletAndDesktopApplicationView(placesNavigator, eventBus), eventBus, placeController, placesNavigator);
authenticationManager = new AuthenticationManagerImpl(this, eventBus);
final AuthenticationViewDesktop userManagementDisplay = new AuthenticationViewDesktop();
final Runnable signInSuccesfullNavigation = new Runnable() {
@@ -69,11 +68,13 @@ public class TabletAndDesktopApplicationClientFactory extends AbstractApplicatio
userManagementWizardController.goTo(new LoggedInUserInfoPlace());
}
};
this.authenticationManager = new AuthenticationManagerImpl(this, eventBus, getHomePlacesNavigator()
.getMailVerifiedConfirmationNavigation().getFullQualifiedUrl(), getHomePlacesNavigator()
.getPasswordResetNavigation().getFullQualifiedUrl());
this.userManagementWizardController = new AuthenticationPlaceManagementController(
new AuthenticationClientFactoryImpl(authenticationManager, SharedResources.INSTANCE),
new AuthenticationCallbackImpl(getHomePlacesNavigator().getMailVerifiedConfirmationNavigation(),
getHomePlacesNavigator().getPasswordResetNavigation(), getHomePlacesNavigator().
getUserProfileNavigation(), signInSuccesfullNavigation), userManagementDisplay, getEventBus());
new AuthenticationCallbackImpl(getHomePlacesNavigator().getUserProfileNavigation(),
signInSuccesfullNavigation), userManagementDisplay, getEventBus());
new FlyoutAuthenticationPresenter(userManagementDisplay, getTopLevelView().getAuthenticationMenuView(),
userManagementWizardController, eventBus);
@@ -63,7 +63,9 @@ public class MobileApplicationClientFactory extends
PlaceController placeController, final MobilePlacesNavigator navigator) {
super(root, eventBus, placeController);
this.navigator = navigator;
authenticationManager = new AuthenticationManagerImpl(this, eventBus);
this.authenticationManager = new AuthenticationManagerImpl(this, eventBus, getNavigator()
.getMailVerifiedConfirmationNavigation().getFullQualifiedUrl(), getNavigator()
.getPasswordResetNavigation().getFullQualifiedUrl());
}
public MobilePlacesNavigator getNavigator() {
@@ -26,9 +26,8 @@ public class AuthenticationActivity extends AbstractActivity {
panel.setWidget(userManagementView);
WrappedPlaceManagementController userManagementController = new AuthenticationPlaceManagementController(
new AuthenticationClientFactoryImpl(clientFactory.getAuthenticationManager(), SharedResources.INSTANCE),
new AuthenticationCallbackImpl(clientFactory.getNavigator().getMailVerifiedConfirmationNavigation(),
clientFactory.getNavigator().getPasswordResetNavigation(), clientFactory.getNavigator()
.getUserProfileNavigation(), new SignInSuccessfulNavigationMobile()),
new AuthenticationCallbackImpl(clientFactory.getNavigator().getUserProfileNavigation(),
new SignInSuccessfulNavigationMobile()),
userManagementView, eventBus);
userManagementController.start();
}
@@ -1,43 +1,20 @@
package com.sap.sailing.gwt.home.shared.usermanagement;
import com.google.gwt.user.client.Window;
import com.sap.sailing.gwt.home.shared.app.PlaceNavigation;
import com.sap.sailing.gwt.home.shared.places.user.confirmation.ConfirmationPlace;
import com.sap.sailing.gwt.home.shared.places.user.passwordreset.PasswordResetPlace;
import com.sap.sailing.gwt.home.shared.places.user.profile.AbstractUserProfilePlace;
import com.sap.sse.security.ui.authentication.AuthenticationCallback;
public class AuthenticationCallbackImpl implements AuthenticationCallback {
private final String createConfirmationUrl;
private final String passwordResetUrl;
private final PlaceNavigation<? extends AbstractUserProfilePlace> userProfileNavigation;
private final Runnable signInSuccessfulNavigation;
public AuthenticationCallbackImpl(PlaceNavigation<ConfirmationPlace> createConfirmationNavigation,
PlaceNavigation<PasswordResetPlace> passwordResetPlaceNavigation,
PlaceNavigation<? extends AbstractUserProfilePlace> userProfileNavigation,
public AuthenticationCallbackImpl(PlaceNavigation<? extends AbstractUserProfilePlace> userProfileNavigation,
Runnable signInSuccessfulNavigation) {
this.signInSuccessfulNavigation = signInSuccessfulNavigation;
this.createConfirmationUrl = createUrl(createConfirmationNavigation);
this.passwordResetUrl = createUrl(passwordResetPlaceNavigation);
this.userProfileNavigation = userProfileNavigation;
}
private String createUrl(PlaceNavigation<?> placeNavigation) {
return Window.Location.createUrlBuilder().setHash(placeNavigation.getTargetUrl()).buildString();
}
@Override
public String getCreateConfirmationUrl() {
return createConfirmationUrl;
}
@Override
public String getPasswordResetUrl() {
return passwordResetUrl;
}
@Override
public void handleUserProfileNavigation() {
userProfileNavigation.goToPlace();
@@ -1,11 +1,9 @@
package com.sap.sse.security.ui.authentication;
import com.sap.sse.security.ui.authentication.create.CreateAccountView;
import com.sap.sse.security.ui.authentication.info.LoggedInUserInfoView;
import com.sap.sse.security.ui.authentication.recover.PasswordRecoveryView;
public interface AuthenticationCallback extends CreateAccountView.Presenter.Callback,
PasswordRecoveryView.Presenter.Callback, LoggedInUserInfoView.Presenter.Callback {
public interface AuthenticationCallback {
void handleSignInSuccess();
void handleUserProfileNavigation();
}
@@ -7,10 +7,10 @@ import com.sap.sse.security.ui.shared.UserDTO;
public interface AuthenticationManager {
void createAccount(String name, String email, String password, String fullName, String company,
String validationBaseURL, AsyncCallback<UserDTO> callback);
void createAccount(String name, String email, String password, String fullName,
String company, AsyncCallback<UserDTO> callback);
void reqeustPasswordReset(String username, String eMailAddress, String baseURL, AsyncCallback<Void> callback);
void reqeustPasswordReset(String username, String eMailAddress, AsyncCallback<Void> callback);
void login(String username, String password, AsyncCallback<SuccessInfo> callback);
@@ -13,10 +13,15 @@ public class AuthenticationManagerImpl implements AuthenticationManager {
private final WithSecurity clientFactory;
private final EventBus eventBus;
private final String emailConfirmationUrl;
private final String passwordResetUrl;
public AuthenticationManagerImpl(final WithSecurity clientFactory, final EventBus eventBus) {
public AuthenticationManagerImpl(WithSecurity clientFactory, final EventBus eventBus,
String emailConfirmationUrl, String passwordResetUrl) {
this.clientFactory = clientFactory;
this.eventBus = eventBus;
this.emailConfirmationUrl = emailConfirmationUrl;
this.passwordResetUrl = passwordResetUrl;
clientFactory.getUserService().addUserStatusEventHandler(new UserStatusEventHandler() {
@Override
public void onUserStatusChange(UserDTO user) {
@@ -34,15 +39,15 @@ public class AuthenticationManagerImpl implements AuthenticationManager {
}
@Override
public void createAccount(String name, String email, String password, String fullName, String company,
String validationBaseURL, AsyncCallback<UserDTO> callback) {
clientFactory.getUserManagementService().createSimpleUser(name, email, password, fullName, company,
validationBaseURL, callback);
public void createAccount(String name, String email, String password, String fullName,
String company, AsyncCallback<UserDTO> callback) {
clientFactory.getUserManagementService().createSimpleUser(name, email, password,
fullName, company, emailConfirmationUrl, callback);
}
@Override
public void reqeustPasswordReset(String username, String eMailAddress, String baseURL, AsyncCallback<Void> callback) {
clientFactory.getUserManagementService().resetPassword(username, eMailAddress, baseURL, callback);
public void reqeustPasswordReset(String username, String eMailAddress, AsyncCallback<Void> callback) {
clientFactory.getUserManagementService().resetPassword(username, eMailAddress, passwordResetUrl, callback);
}
@Override
@@ -69,8 +69,8 @@ public class AuthenticationPlaceManagementController extends WrappedPlaceManagem
return new CreateAccountActivity(clientFactory.createCreateAccountView(), clientFactory, callback,
placeController);
} else if (placeToUse instanceof PasswordRecoveryPlace) {
return new PasswordRecoveryActivity(clientFactory.createPasswordRecoveryView(), clientFactory,
callback, placeController);
return new PasswordRecoveryActivity(clientFactory.createPasswordRecoveryView(),
clientFactory, placeController);
} else if (placeToUse instanceof LoggedInUserInfoPlace) {
return new LoggedInUserInfoActivity(clientFactory.createLoggedInUserInfoView(), clientFactory,
callback, placeController);
@@ -48,8 +48,7 @@ public class CreateAccountActivity extends AbstractActivity implements CreateAcc
public void createAccount() {
if (values.validate()) {
clientFactory.getAuthenticationManager().createAccount(values.username, values.email,
values.password, values.fullName, values.company, callback.getCreateConfirmationUrl(),
new AsyncCallback<UserDTO>() {
values.password, values.fullName, values.company, new AsyncCallback<UserDTO>() {
@Override
public void onSuccess(final UserDTO result) {
clientFactory.getAuthenticationManager().login(result.getName(), values.password,
@@ -28,9 +28,5 @@ public interface CreateAccountView extends ErrorMessageView, IsWidget {
void signIn();
public interface Callback {
String getCreateConfirmationUrl();
}
}
}
@@ -4,6 +4,7 @@ import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceController;
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.AuthenticationRequestEvent;
@@ -14,11 +15,11 @@ public class LoggedInUserInfoActivity extends AbstractActivity implements Logged
private final AuthenticationClientFactory clientFactory;
private final PlaceController placeController;
private final LoggedInUserInfoView view;
private final Callback callback;
private final AuthenticationCallback callback;
private EventBus eventBus;
public LoggedInUserInfoActivity(LoggedInUserInfoView view, AuthenticationClientFactory clientFactory,
LoggedInUserInfoView.Presenter.Callback callback, PlaceController placeController) {
AuthenticationCallback callback, PlaceController placeController) {
this.view = view;
this.clientFactory = clientFactory;
this.placeController = placeController;
@@ -11,9 +11,5 @@ public interface LoggedInUserInfoView extends IsWidget {
public interface Presenter {
void gotoProfileUi();
void signOut();
public interface Callback {
void handleUserProfileNavigation();
}
}
}
@@ -18,14 +18,12 @@ public class PasswordRecoveryActivity extends AbstractActivity implements Passwo
private final AuthenticationClientFactory clientFactory;
private final PlaceController placeController;
private final PasswordRecoveryView view;
private final Callback callback;
public PasswordRecoveryActivity(PasswordRecoveryView view, AuthenticationClientFactory clientFactory,
PasswordRecoveryView.Presenter.Callback callback, PlaceController placeController) {
PlaceController placeController) {
this.view = view;
this.clientFactory = clientFactory;
this.placeController = placeController;
this.callback = callback;
}
@Override
@@ -36,27 +34,26 @@ public class PasswordRecoveryActivity extends AbstractActivity implements Passwo
@Override
public void resetPassword(final String email, final String username) {
clientFactory.getAuthenticationManager().reqeustPasswordReset(username, email, callback.getPasswordResetUrl(),
new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
String name = (username == null || username.isEmpty()) ? email : username;
placeController.goTo(new ConfirmationInfoPlace(Action.RESET_REQUESTED, name));
clientFactory.getAuthenticationManager().reqeustPasswordReset(username, email, new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
String name = (username == null || username.isEmpty()) ? email : username;
placeController.goTo(new ConfirmationInfoPlace(Action.RESET_REQUESTED, name));
}
@Override
public void onFailure(Throwable caught) {
StringMessages i18n = StringMessages.INSTANCE;
if (caught instanceof UserManagementException) {
if (CANNOT_RESET_PASSWORD_WITHOUT_VALIDATED_EMAIL.equals(caught.getMessage())) {
view.setErrorMessage(i18n.cannotResetPasswordWithoutValidatedEmail(username));
} else {
view.setErrorMessage(i18n.errorResettingPassword(username, caught.getMessage()));
}
@Override
public void onFailure(Throwable caught) {
StringMessages i18n = StringMessages.INSTANCE;
if (caught instanceof UserManagementException) {
if (CANNOT_RESET_PASSWORD_WITHOUT_VALIDATED_EMAIL.equals(caught.getMessage())) {
view.setErrorMessage(i18n.cannotResetPasswordWithoutValidatedEmail(username));
} else {
view.setErrorMessage(i18n.errorResettingPassword(username, caught.getMessage()));
}
} else {
view.setErrorMessage(i18n.errorDuringPasswordReset(caught.getMessage()));
}
}
});
} else {
view.setErrorMessage(i18n.errorDuringPasswordReset(caught.getMessage()));
}
}
});
}
}
@@ -11,9 +11,5 @@ public interface PasswordRecoveryView extends ErrorMessageView, IsWidget {
void resetPassword(String email, String username);
public interface Callback {
String getPasswordResetUrl();
}
}
}