- removed general contact bean as this is really not needed in an administrative user bean
Signed-off-by: Roland Häder <roland@haeder.net>
Signed-off-by: Roland Häder <roland@mxchange.org>
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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)
- * <p>
- * @author Roland Haeder<rhaeder@cho-time.de>
- */
-@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<UpdatedUserPasswordEvent> 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);
- }
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-package de.chotime.landingpage.beans.user.password;
-
-import java.io.Serializable;
-import javax.ejb.Local;
-
-/**
- * An interface for user beans
- * <p>
- * @author Roland Haeder<rhaeder@cho-time.de>
- */
-@Local
-public interface LandingUserPasswordWebRequestController extends Serializable {
-
- /**
- * Getter for unencrypted user password
- * <p>
- * @return Unencrypted user password
- */
- String getUserPassword ();
-
- /**
- * Setter for unencrypted user password
- * <p>
- * @param userPassword Unencrypted user password
- */
- void setUserPassword (final String userPassword);
-
- /**
- * Getter for current unencrypted user password
- * <p>
- * @return Current unencrypted user password
- */
- String getUserCurrentPassword ();
-
- /**
- * Setter for current unencrypted user password
- * <p>
- * @param userCurrentPassword Current unencrypted user password
- */
- void setUserCurrentPassword (final String userCurrentPassword);
-
- /**
- * Getter for unencrypted user password repeated
- * <p>
- * @return Unencrypted user password repeated
- */
- String getUserPasswordRepeat ();
-
- /**
- * Setter for unencrypted user password repeated
- * <p>
- * @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.
- * <p>
- * @return Redirect outcome
- */
- String doChangePassword ();
-
-}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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)
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@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<UpdatedUserPasswordEvent> 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.user.password;
+
+import java.io.Serializable;
+import javax.ejb.Local;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@Local
+public interface PizzaUserPasswordWebRequestController extends Serializable {
+
+ /**
+ * Getter for unencrypted user password
+ * <p>
+ * @return Unencrypted user password
+ */
+ String getUserPassword ();
+
+ /**
+ * Setter for unencrypted user password
+ * <p>
+ * @param userPassword Unencrypted user password
+ */
+ void setUserPassword (final String userPassword);
+
+ /**
+ * Getter for current unencrypted user password
+ * <p>
+ * @return Current unencrypted user password
+ */
+ String getUserCurrentPassword ();
+
+ /**
+ * Setter for current unencrypted user password
+ * <p>
+ * @param userCurrentPassword Current unencrypted user password
+ */
+ void setUserCurrentPassword (final String userCurrentPassword);
+
+ /**
+ * Getter for unencrypted user password repeated
+ * <p>
+ * @return Unencrypted user password repeated
+ */
+ String getUserPasswordRepeat ();
+
+ /**
+ * Setter for unencrypted user password repeated
+ * <p>
+ * @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.
+ * <p>
+ * @return Redirect outcome
+ */
+ String doChangePassword ();
+
+}