From 0288cb8f96277f8aa56abfb9bd2f12c29516f09e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 12 Mar 2016 18:09:31 +0100 Subject: [PATCH] Continued: - added local caching of all enqueued email addresses (this can become big) - updated jar(s) --- lib/juser-core.jar | Bin 37613 -> 38112 bytes lib/juser-lib.jar | Bin 4887 -> 5111 bytes .../EmailChangeWebSessionBean.java | 199 ++++++++++++++++++ .../EmailChangeWebSessionController.java | 70 ++++++ .../beans/login/UserLoginWebSessionBean.java | 21 +- .../login/UserLoginWebSessionController.java | 8 + .../password/UserPasswordValidator.java | 4 +- web/login/login_change_email_address.xhtml | 6 +- 8 files changed, 302 insertions(+), 6 deletions(-) create mode 100644 src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java create mode 100644 src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionController.java diff --git a/lib/juser-core.jar b/lib/juser-core.jar index 8488d71d29bac0c83be02e3c7e5e3129e0b51f47..8ce84feb27b6c1ae7308aae243d964e112f069d6 100644 GIT binary patch delta 3538 zcma)93s98T6+ZvJFLwDsSOFh^tc{r6<>{*lLQkNP;o0R3733 z!E0&aOfv0gs<9@TuBd67R+E^Rsg1FDIB6%f=513uZKgBLG^W$<+<(Ch!I{AP_uTW{ zbI$$#bMHO>-5bxSe|=Wf%8Ly~8&MchTmOLOQXlFcxa+6tP~X7&4sO48p%v4WSuCoQ z92N(Z0v1=5Y!>lq9*e04mpCy#MjTLWto{n>B{i12pQ>4ETR#luv$oMtrjO^c_^+Xu z#eAa&BG6~NuCQ!3H<(#|rWHwjX5>@@>&v1mq&yn4M&j1El`7-ji7SmPUrNZ5@+-$I zDbtcSO8Y0B$E94DdO^yV%z4J>w*H0%jZNF~bL~X@6o}}0hbT8hilkh-I6Qk?<)Dqm z)8kg!N`5QZX`2lVR6BKW^CNDyvq`6gx_GQRoUGJsqaND9YA>t3tnOsfUEJ)p&>jo* ziD;KQFlSD$QCTb$yGxw6*hTYC;93_iZ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l68l^RXjpjr2C3$E A2><{9 diff --git a/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java new file mode 100644 index 00000000..afce8835 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2016 quix0r + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.beans.email_address; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Objects; +import javax.enterprise.context.SessionScoped; +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.addressbook.beans.login.UserLoginWebSessionController; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; +import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; +import org.mxchange.jusercore.model.email_address.EmailAddressChange; +import org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote; +import org.mxchange.jusercore.model.user.User; + +/** + * A web session bean for changing email addresses + *

+ * @author Roland Haeder + */ +@Named ("emailChangeController") +@SessionScoped +public class EmailChangeWebSessionBean implements EmailChangeWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 186_078_724_659_153L; + + /** + * Email address 1 (changing) + */ + private String emailAddress1; + + /** + * Email address 2 (repeat in changing) + */ + private String emailAddress2; + + /** + * Local list of already queued email addresses + */ + private List emailAddresses; + + /** + * Remote email change bean + */ + private final EmailChangeSessionBeanRemote emailBean; + + /** + * Login bean (controller) + */ + @Inject + private UserLoginWebSessionController loginController; + + /** + * Default constructor + */ + public EmailChangeWebSessionBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.emailBean = (EmailChangeSessionBeanRemote) context.lookup("ejb/stateless-jjobs-email-change"); //NOI18N + + // Init list + this.emailAddresses = this.emailBean.allQueuedAddressesAsList(); + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public String doChangeEmailAddress () { + // This method shall only be called if the user is logged-in + if (!this.loginController.isUserLoggedIn()) { + // Not logged-in + throw new IllegalStateException("User is not logged-in"); //NOI18N + } else if (!this.isRequiredChangeEmailAddressSet()) { + // Not all required fields are set + throw new FaceletException("Not all required fields are set."); //NOI18N + } else if (!Objects.equals(this.getEmailAddress1(), this.getEmailAddress2())) { + // Email address 1+2 mismatch + throw new FaceletException("Email address 1/2 are mismatching."); //NOI18N + } else if (!this.loginController.ifCurrentPasswordMatches()) { + // Password not matching + throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser())); + } + + // Get user instance + User user = this.loginController.getLoggedInUser(); + + // It should be there, so run some tests on it + assert (user instanceof User) : "Instance loginController.loggedInUser is null"; //NOI18N + assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null"; //NOI18N + assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N + assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N + assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N + assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N + + // Check if the email address is already enqueued + if (this.isEmailAddressQueued()) { + // Yes, then abort here + return "login_email_already_added"; //NOI18N + } + + // Create change object + ChangeableEmailAddress emailAddress = new EmailAddressChange(user, this.getEmailAddress1(), new GregorianCalendar()); + + // Call EJB + this.emailBean.enqueueEmailAddressForChange(emailAddress); + + // All fine + return "login_email_change_queued"; //NOI18N + } + + @Override + public String getEmailAddress1 () { + return this.emailAddress1; + } + + @Override + public void setEmailAddress1 (final String emailAddress1) { + this.emailAddress1 = emailAddress1; + } + + @Override + public String getEmailAddress2 () { + return this.emailAddress2; + } + + @Override + public void setEmailAddress2 (final String emailAddress2) { + this.emailAddress2 = emailAddress2; + } + + @Override + public boolean isRequiredChangeEmailAddressSet () { + return ((this.getEmailAddress1() != null) && + (this.getEmailAddress2() != null)); + } + + /** + * Checks if current emailAddress1 has already been queued. First a local + * list is being checked, if not found, the EJB is called. Only if found, + * the result is "cached" in the list. + *

+ * @return Whether the email address in field emailAddress1 is already queued + */ + private boolean isEmailAddressQueued () { + // It should be there + assert (this.getEmailAddress1() != null) : "emailAddress1 should not be null"; //NOI18N + assert (!this.getEmailAddress1().trim().isEmpty()) : "emailAddress1 should not be empty"; //NOI18N + + // Check list + if (this.emailAddresses.contains(this.getEmailAddress1())) { + // Okay, found it + return true; + } + + // Check EJB + boolean isQueued = this.emailBean.isEmailAddressEnqueued(this.getEmailAddress1()); + + // Is it there? + if (isQueued) { + // Add to list + this.emailAddresses.add(this.getEmailAddress1()); + } + + // Return status + return isQueued; + } + +} diff --git a/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionController.java b/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionController.java new file mode 100644 index 00000000..92af0927 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionController.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 quix0r + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.beans.email_address; + +import java.io.Serializable; + +/** + * An interface for an email change controller + *

+ * @author Roland Haeder + */ +public interface EmailChangeWebSessionController extends Serializable { + + /** + * Getter for email address 1 (changing) + *

+ * @return Email address + */ + String getEmailAddress1 (); + + /** + * Setter for email address 1 (changing) + *

+ * @param emailAddress1 Email address 1 + */ + void setEmailAddress1 (final String emailAddress1); + + /** + * Getter for email address 2 (repeat changing) + *

+ * @return Email address 2 + */ + String getEmailAddress2 (); + + /** + * Setter for email address 2 (repeat changing) + *

+ * @param emailAddress2 Email address 2 + */ + void setEmailAddress2 (final String emailAddress2); + + /** + * Checks whether all required are set for changing email address + *

+ * @return Whether the required personal data is set + */ + boolean isRequiredChangeEmailAddressSet (); + + /** + * Changes logged-in user's email address if the current password matches. + *

+ * @return New target page + */ + String doChangeEmailAddress (); + +} diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionBean.java index 00ff14bc..1b2055a8 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionBean.java @@ -37,6 +37,7 @@ import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; import org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.UserUtils; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; @@ -140,7 +141,7 @@ public class UserLoginWebSessionBean implements UserLoginWebSessionController { @Override public String getCurrentPassword () { - return currentPassword; + return this.currentPassword; } @Override @@ -168,6 +169,24 @@ public class UserLoginWebSessionBean implements UserLoginWebSessionController { this.templateType = templateType; } + @Override + public boolean ifCurrentPasswordMatches () { + // The current password must be set and not empty + if (this.getCurrentPassword() == null) { + // Is not set + throw new NullPointerException("this.currentPassword is null"); //NOI18N + } else if (this.getCurrentPassword().isEmpty()) { + // Is set empty + throw new IllegalStateException("this.currentPassword is empty."); //NOI18N + } + + // Create "container" + LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getCurrentPassword()); + + // Now check if it matches + return UserUtils.ifPasswordMatches(container, this.getLoggedInUser()); + } + @Override public boolean isGuest () { return (!this.isUserLoggedIn()); diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionController.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionController.java index e4846554..2d7da581 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionController.java @@ -95,4 +95,12 @@ public interface UserLoginWebSessionController extends Serializable { * @return Current password */ String getCurrentPassword (); + + /** + * Checks whether the (previously entered) current password matches with from + * the user instance. + *

+ * @return If current password matches + */ + boolean ifCurrentPasswordMatches (); } diff --git a/src/java/org/mxchange/addressbook/validators/password/UserPasswordValidator.java b/src/java/org/mxchange/addressbook/validators/password/UserPasswordValidator.java index 89d2828d..cece958d 100644 --- a/src/java/org/mxchange/addressbook/validators/password/UserPasswordValidator.java +++ b/src/java/org/mxchange/addressbook/validators/password/UserPasswordValidator.java @@ -54,10 +54,10 @@ public class UserPasswordValidator extends BaseStringValidator implements Valida //this.getLogger().logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N // The required field - String[] requiredFileds = {"currentPassword"}; //NOI18N + String[] requiredFields = {"currentPassword"}; //NOI18N // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFileds, false); + super.preValidate(context, component, value, requiredFields, false); // value is known to be an entered password, so instance login container LoginContainer container = new UserLoginContainer(this.loginController.getLoggedInUser(), (String) value); diff --git a/web/login/login_change_email_address.xhtml b/web/login/login_change_email_address.xhtml index 33afeae1..adc9608f 100644 --- a/web/login/login_change_email_address.xhtml +++ b/web/login/login_change_email_address.xhtml @@ -43,7 +43,7 @@

- +
@@ -55,7 +55,7 @@
- +
@@ -67,7 +67,7 @@ -- 2.39.5