From: Roland Häder Date: Fri, 5 Aug 2016 13:10:32 +0000 (+0200) Subject: Cleanup: (please cherry-pick) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=95db66e8b9045128b3ec3e5659a6a65d1efc3b42;p=pizzaservice-war.git Cleanup: (please cherry-pick) - removed general contact bean as this is really not needed in an administrative user bean Signed-off-by: Roland Häder Signed-off-by: Roland Häder --- diff --git a/src/java/de/chotime/landingpage/beans/user/password/LandingUserPasswordWebRequestBean.java b/src/java/de/chotime/landingpage/beans/user/password/LandingUserPasswordWebRequestBean.java deleted file mode 100644 index fe4c5a91..00000000 --- a/src/java/de/chotime/landingpage/beans/user/password/LandingUserPasswordWebRequestBean.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (C) 2016 Cho-Time GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package de.chotime.landingpage.beans.user.password; - -import de.chotime.landingpage.beans.BaseLandingController; -import de.chotime.landingpage.beans.features.LandingFeaturesWebApplicationController; -import de.chotime.landingpage.beans.login.LandingUserLoginWebSessionController; -import java.util.Objects; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Event; -import javax.enterprise.inject.Any; -import javax.faces.view.facelets.FaceletException; -import javax.inject.Inject; -import javax.inject.Named; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent; -import org.mxchange.jusercore.events.user.password_change.UserUpdatedPasswordEvent; -import org.mxchange.jusercore.exceptions.UserNotFoundException; -import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; -import org.mxchange.jusercore.exceptions.UserStatusLockedException; -import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.model.user.UserSessionBeanRemote; -import org.mxchange.jusercore.model.user.UserUtils; -import org.mxchange.jusercore.model.user.password_history.PasswordHistory; - -/** - * A user password (change) bean (controller) - *

- * @author Roland Haeder - */ -@Named ("userPasswordController") -@RequestScoped -public class LandingUserPasswordWebRequestBean extends BaseLandingController implements LandingUserPasswordWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_267_867_367_501L; - - /** - * Features controller - */ - @Inject - private LandingFeaturesWebApplicationController featureController; - - /** - * Remote user bean - */ - private final UserSessionBeanRemote userBean; - - /** - * Current password (for confirmation of password change) - */ - private String userCurrentPassword; - - /** - * Login bean (controller) - */ - @Inject - private LandingUserLoginWebSessionController userLoginController; - - /** - * User password (unencrypted from web form) - */ - private String userPassword; - - /** - * User password repeated (unencrypted from web form) - */ - private String userPasswordRepeat; - - /** - * Event being fired when user's password has been updated - */ - @Any - @Inject - private Event userUpdatedPasswordEvent; - - /** - * Default constructor - */ - public LandingUserPasswordWebRequestBean () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - } - - @Override - public String doChangePassword () { - // This method shall only be called if the user is logged-in - if (!this.userLoginController.isUserLoggedIn()) { - // Not logged-in - throw new IllegalStateException("User is not logged-in"); //NOI18N - } else if (!this.isRequiredChangePasswordSet()) { - // Not all required fields are set - throw new FaceletException("Not all required fields are set."); //NOI18N - } else if (!this.userLoginController.ifCurrentPasswordMatches()) { - // Password not matching - throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); - } else if (!this.featureController.isFeatureEnabled("change_user_password")) { //NOI18N - // Editing is not allowed - throw new IllegalStateException("User tried to change password."); //NOI18N - } else if (!UserUtils.ifPasswordMatches(this.getUserCurrentPassword(), this.userLoginController.getLoggedInUser())) { - // Password mismatches - this.showFacesMessage("form_user_change_password:userCurrentPassword", "Entered current password does not matched stored password."); //NOI18N - - // Clear bean - this.clear(); - - // No redirect - return ""; //NOI18N - } else if (!Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())) { - // Both entered passwords don't match - this.showFacesMessage("form_user_change_password:userPasswordRepeat", "Entered new passwords mismatch."); //NOI18N - - // Clear bean - this.clear(); - - // No redirect - return ""; //NOI18N - } else if (Objects.equals(this.getUserCurrentPassword(), this.getUserPassword())) { - // New password matches current - this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is same as current password."); //NOI18N - - // Clear bean - this.clear(); - - // No redirect - return ""; //NOI18N - } else if (this.userLoginController.isPasswordInHistory(this.getUserPassword())) { - // Is already in list (to old passwords are ignored) - this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is has already been used some time ago."); //NOI18N - - // Clear bean - this.clear(); - - // No redirect - return ""; //NOI18N - } - - // Get user instance - User user = this.userLoginController.getLoggedInUser(); - - // Encrypt password - String encryptedPassword = UserUtils.encryptPassword(this.getUserPassword()); - - // Set it in user - user.setUserEncryptedPassword(encryptedPassword); - - try { - // All is set, then update password - PasswordHistory passwordHistory = this.userBean.updateUserPassword(user); - - // Fire event - this.userUpdatedPasswordEvent.fire(new UserUpdatedPasswordEvent(passwordHistory)); - } catch (final UserNotFoundException | UserStatusUnconfirmedException | UserStatusLockedException ex) { - // Clear bean - this.clear(); - - // Throw again - throw new FaceletException(ex); - } - - // Clear bean - this.clear(); - - // Return outcome - return "login_data_saved"; //NOI18N - } - - @Override - public String getUserCurrentPassword () { - return this.userCurrentPassword; - } - - @Override - public void setUserCurrentPassword (final String userCurrentPassword) { - this.userCurrentPassword = userCurrentPassword; - } - - @Override - public String getUserPassword () { - return this.userPassword; - } - - @Override - public void setUserPassword (final String userPassword) { - this.userPassword = userPassword; - } - - @Override - public String getUserPasswordRepeat () { - return this.userPasswordRepeat; - } - - @Override - public void setUserPasswordRepeat (final String userPasswordRepeat) { - this.userPasswordRepeat = userPasswordRepeat; - } - - public boolean isRequiredChangePasswordSet () { - // Is all data set? - return ((this.getUserCurrentPassword() != null) && - (!this.getUserCurrentPassword().isEmpty()) && - (this.getUserPassword() != null) && - (!this.getUserPassword().isEmpty()) && - (this.getUserPasswordRepeat() != null) && - (!this.getUserPasswordRepeat().isEmpty())); - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all data - this.setUserPassword(null); - this.setUserPasswordRepeat(null); - } - -} diff --git a/src/java/de/chotime/landingpage/beans/user/password/LandingUserPasswordWebRequestController.java b/src/java/de/chotime/landingpage/beans/user/password/LandingUserPasswordWebRequestController.java deleted file mode 100644 index a876eab7..00000000 --- a/src/java/de/chotime/landingpage/beans/user/password/LandingUserPasswordWebRequestController.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2016 Cho-Time GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package de.chotime.landingpage.beans.user.password; - -import java.io.Serializable; -import javax.ejb.Local; - -/** - * An interface for user beans - *

- * @author Roland Haeder - */ -@Local -public interface LandingUserPasswordWebRequestController extends Serializable { - - /** - * Getter for unencrypted user password - *

- * @return Unencrypted user password - */ - String getUserPassword (); - - /** - * Setter for unencrypted user password - *

- * @param userPassword Unencrypted user password - */ - void setUserPassword (final String userPassword); - - /** - * Getter for current unencrypted user password - *

- * @return Current unencrypted user password - */ - String getUserCurrentPassword (); - - /** - * Setter for current unencrypted user password - *

- * @param userCurrentPassword Current unencrypted user password - */ - void setUserCurrentPassword (final String userCurrentPassword); - - /** - * Getter for unencrypted user password repeated - *

- * @return Unencrypted user password repeated - */ - String getUserPasswordRepeat (); - - /** - * Setter for unencrypted user password repeated - *

- * @param userPasswordRepeat Unencrypted user password repeated - */ - void setUserPasswordRepeat (final String userPasswordRepeat); - - /** - * Changes logged-in user's password. It must not match with current password and should not appear in password history list for X (configurable) entries. - *

- * @return Redirect outcome - */ - String doChangePassword (); - -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java new file mode 100644 index 00000000..36aee966 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java @@ -0,0 +1,245 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.user.password; + +import java.util.Objects; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent; +import org.mxchange.jusercore.events.user.password_change.UserUpdatedPasswordEvent; +import org.mxchange.jusercore.exceptions.UserNotFoundException; +import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; +import org.mxchange.jusercore.exceptions.UserStatusLockedException; +import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; +import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.UserSessionBeanRemote; +import org.mxchange.jusercore.model.user.UserUtils; +import org.mxchange.jusercore.model.user.password_history.PasswordHistory; +import org.mxchange.pizzaapplication.beans.BasePizzaController; +import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController; +import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; + +/** + * A user password (change) bean (controller) + *

+ * @author Roland Haeder + */ +@Named ("userPasswordController") +@RequestScoped +public class PizzaUserPasswordWebRequestBean extends BasePizzaController implements PizzaUserPasswordWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 15_267_867_367_501L; + + /** + * Features controller + */ + @Inject + private PizzaFeaturesWebApplicationController featureController; + + /** + * Remote user bean + */ + private final UserSessionBeanRemote userBean; + + /** + * Current password (for confirmation of password change) + */ + private String userCurrentPassword; + + /** + * Login bean (controller) + */ + @Inject + private PizzaUserLoginWebSessionController userLoginController; + + /** + * User password (unencrypted from web form) + */ + private String userPassword; + + /** + * User password repeated (unencrypted from web form) + */ + private String userPasswordRepeat; + + /** + * Event being fired when user's password has been updated + */ + @Any + @Inject + private Event userUpdatedPasswordEvent; + + /** + * Default constructor + */ + public PizzaUserPasswordWebRequestBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public String doChangePassword () { + // This method shall only be called if the user is logged-in + if (!this.userLoginController.isUserLoggedIn()) { + // Not logged-in + throw new IllegalStateException("User is not logged-in"); //NOI18N + } else if (!this.isRequiredChangePasswordSet()) { + // Not all required fields are set + throw new FaceletException("Not all required fields are set."); //NOI18N + } else if (!this.userLoginController.ifCurrentPasswordMatches()) { + // Password not matching + throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); + } else if (!this.featureController.isFeatureEnabled("change_user_password")) { //NOI18N + // Editing is not allowed + throw new IllegalStateException("User tried to change password."); //NOI18N + } else if (!UserUtils.ifPasswordMatches(this.getUserCurrentPassword(), this.userLoginController.getLoggedInUser())) { + // Password mismatches + this.showFacesMessage("form_user_change_password:userCurrentPassword", "Entered current password does not matched stored password."); //NOI18N + + // Clear bean + this.clear(); + + // No redirect + return ""; //NOI18N + } else if (!Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())) { + // Both entered passwords don't match + this.showFacesMessage("form_user_change_password:userPasswordRepeat", "Entered new passwords mismatch."); //NOI18N + + // Clear bean + this.clear(); + + // No redirect + return ""; //NOI18N + } else if (Objects.equals(this.getUserCurrentPassword(), this.getUserPassword())) { + // New password matches current + this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is same as current password."); //NOI18N + + // Clear bean + this.clear(); + + // No redirect + return ""; //NOI18N + } else if (this.userLoginController.isPasswordInHistory(this.getUserPassword())) { + // Is already in list (to old passwords are ignored) + this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is has already been used some time ago."); //NOI18N + + // Clear bean + this.clear(); + + // No redirect + return ""; //NOI18N + } + + // Get user instance + User user = this.userLoginController.getLoggedInUser(); + + // Encrypt password + String encryptedPassword = UserUtils.encryptPassword(this.getUserPassword()); + + // Set it in user + user.setUserEncryptedPassword(encryptedPassword); + + try { + // All is set, then update password + PasswordHistory passwordHistory = this.userBean.updateUserPassword(user); + + // Fire event + this.userUpdatedPasswordEvent.fire(new UserUpdatedPasswordEvent(passwordHistory)); + } catch (final UserNotFoundException | UserStatusUnconfirmedException | UserStatusLockedException ex) { + // Clear bean + this.clear(); + + // Throw again + throw new FaceletException(ex); + } + + // Clear bean + this.clear(); + + // Return outcome + return "login_data_saved"; //NOI18N + } + + @Override + public String getUserCurrentPassword () { + return this.userCurrentPassword; + } + + @Override + public void setUserCurrentPassword (final String userCurrentPassword) { + this.userCurrentPassword = userCurrentPassword; + } + + @Override + public String getUserPassword () { + return this.userPassword; + } + + @Override + public void setUserPassword (final String userPassword) { + this.userPassword = userPassword; + } + + @Override + public String getUserPasswordRepeat () { + return this.userPasswordRepeat; + } + + @Override + public void setUserPasswordRepeat (final String userPasswordRepeat) { + this.userPasswordRepeat = userPasswordRepeat; + } + + public boolean isRequiredChangePasswordSet () { + // Is all data set? + return ((this.getUserCurrentPassword() != null) && + (!this.getUserCurrentPassword().isEmpty()) && + (this.getUserPassword() != null) && + (!this.getUserPassword().isEmpty()) && + (this.getUserPasswordRepeat() != null) && + (!this.getUserPasswordRepeat().isEmpty())); + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data + this.setUserPassword(null); + this.setUserPasswordRepeat(null); + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestController.java new file mode 100644 index 00000000..6a053874 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestController.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.user.password; + +import java.io.Serializable; +import javax.ejb.Local; + +/** + * An interface for user beans + *

+ * @author Roland Haeder + */ +@Local +public interface PizzaUserPasswordWebRequestController extends Serializable { + + /** + * Getter for unencrypted user password + *

+ * @return Unencrypted user password + */ + String getUserPassword (); + + /** + * Setter for unencrypted user password + *

+ * @param userPassword Unencrypted user password + */ + void setUserPassword (final String userPassword); + + /** + * Getter for current unencrypted user password + *

+ * @return Current unencrypted user password + */ + String getUserCurrentPassword (); + + /** + * Setter for current unencrypted user password + *

+ * @param userCurrentPassword Current unencrypted user password + */ + void setUserCurrentPassword (final String userCurrentPassword); + + /** + * Getter for unencrypted user password repeated + *

+ * @return Unencrypted user password repeated + */ + String getUserPasswordRepeat (); + + /** + * Setter for unencrypted user password repeated + *

+ * @param userPasswordRepeat Unencrypted user password repeated + */ + void setUserPasswordRepeat (final String userPasswordRepeat); + + /** + * Changes logged-in user's password. It must not match with current password and should not appear in password history list for X (configurable) entries. + *

+ * @return Redirect outcome + */ + String doChangePassword (); + +}