From ea548db4cd3130b5961d3b01c3ef398aa04c29bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 25 Apr 2016 13:42:26 +0200 Subject: [PATCH] fixed my email address MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../customer/PizzaCustomerWebSessionBean.java | 2 +- .../PizzaMobileProviderWebRequestBean.java | 2 +- ...zzaMobileProviderWebRequestController.java | 2 +- .../PizzaUserProfileWebRequestBean.java | 116 ++++++++++++++++++ .../PizzaProfileModeWebApplicationBean.java | 49 ++++++++ .../password/PizzaUserPasswordValidator.java | 101 +++++++++++++++ 6 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java create mode 100644 src/java/org/mxchange/pizzaapplication/beans/profilemode/PizzaProfileModeWebApplicationBean.java create mode 100644 src/java/org/mxchange/pizzaapplication/validators/password/PizzaUserPasswordValidator.java diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java index 69b8c420..71aa303b 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java @@ -161,7 +161,7 @@ public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionContr contact.setContactCellphoneNumber(this.getCellphoneNumber()); // Set contact in customer - customer.setContact(contact); + customer.setCustomerContact(contact); // Trace message //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer)); diff --git a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java index 32656b23..9c77a095 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Roland Haeder + * Copyright (C) 2016 Roland Haeder * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java index ba780e5c..29fe878a 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Roland Haeder + * Copyright (C) 2016 Roland Haeder * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java new file mode 100644 index 00000000..438f252b --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * 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.profile; + +import java.text.MessageFormat; +import javax.enterprise.context.RequestScoped; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jusercore.exceptions.UserNotFoundException; +import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; +import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; +import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; + +/** + * A web request bean for user profiles + *

+ * @author Roland Haeder + */ +@Named (value = "profileController") +@RequestScoped +public class PizzaUserProfileWebRequestBean implements PizzaUserProfileWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 187_687_145_286_710L; + + /** + * Login controller + */ + @Inject + private PizzaUserLoginWebSessionController loginController; + + /** + * User controller + */ + @Inject + private PizzaUserWebSessionController userController; + + @Override + public boolean isProfileLinkVisibleById (final Long userId) { + // Init user instance + User u = null; + + try { + // Try to get it + u = this.userController.lookupUserById(userId); + } catch (final UserNotFoundException ex) { + // Throw again + throw new FaceletException(ex); + } + + // Is it null? + if (null == u) { + // Not found, not visible. + return false; + } + + // Ask other method + return this.isProfileLinkVisibleByUser(u); + } + + @Override + public boolean isProfileLinkVisibleByUser (final User user) { + // Check on user + if (null == user) { + /* + * Not set, means wrong invocation of this method as the user + * instance needs to be set first. + */ + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + /* + * If the id number is not set it means that the user instance has + * not been persisted and the JPA has not been flushed. Or a + * "virgin" instance (e.g. from registration) has been used. + */ + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + /* + * The id number is set invalid for an unknown reason. + */ + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N + } else if (user.getUserProfileMode() == null) { + /* + * Possibly an out-dated user profile is being used. This should not + * happen. + */ + throw new NullPointerException("user.userProfileMode is null"); //NOI18N + } + + // Get profile mode from user instance (safe now) + ProfileMode profileMode = user.getUserProfileMode(); + + // Check all conditions (except for admin) + // TODO: Add admin role somehow? + return ((profileMode.equals(ProfileMode.PUBLIC)) || + (this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS))); + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/profilemode/PizzaProfileModeWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/profilemode/PizzaProfileModeWebApplicationBean.java new file mode 100644 index 00000000..e60ab41c --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/profilemode/PizzaProfileModeWebApplicationBean.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * 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.profilemode; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; +import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; + +/** + * A profile mode bean + *

+ * @author Roland Haeder + */ +@Named ("profileModeController") +@ApplicationScoped +public class PizzaProfileModeWebApplicationBean implements PizzaProfileModeWebApplicationController { + + /** + * Serial number + */ + private static final long serialVersionUID = 835_482_364_189L; + + /** + * Default constructor + */ + public PizzaProfileModeWebApplicationBean () { + } + + @Override + public ProfileMode[] getAllProfileModes () { + // Return it + return ProfileMode.values(); + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/validators/password/PizzaUserPasswordValidator.java b/src/java/org/mxchange/pizzaapplication/validators/password/PizzaUserPasswordValidator.java new file mode 100644 index 00000000..7b86c4a4 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/validators/password/PizzaUserPasswordValidator.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * 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.validators.password; + +import java.text.MessageFormat; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.FacesValidator; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcoreee.validator.string.BaseStringValidator; +import org.mxchange.jcoreeelogger.beans.local.logger.Log; +import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; +import org.mxchange.jusercore.container.login.LoginContainer; +import org.mxchange.jusercore.container.login.UserLoginContainer; +import org.mxchange.jusercore.model.user.UserUtils; +import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; + +/** + * A validator for validating passwords (if they match with stored) + *

+ * @author Roland Haeder + */ +@FacesValidator (value = "PizzaUserPasswordValidator") +public class PizzaUserPasswordValidator extends BaseStringValidator implements Validator { + + /** + * Serial number + */ + private static final long serialVersionUID = 48_581_795_687_317L; + + /** + * Logger instance + */ + @Log + private LoggerBeanLocal loggerBeanLocal; + + /** + * User login controller + */ + private PizzaUserLoginWebSessionController loginController; + + /** + * Default constructor + */ + public PizzaUserPasswordValidator () { + // Try to get it + try { + // Get initial context + Context context = new InitialContext(); + + // Lookup logger + this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw it + throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N + } + } + + @Override + public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // Trace message + this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N + + // The required field + String[] requiredFields = {"currentPassword"}; //NOI18N + + // Pre-validation (example: not null, not a string, empty string ...) + 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); + + // Test it here + if (!UserUtils.ifPasswordMatches(container, this.loginController.getLoggedInUser())) { + // Password mismatches + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Password mismatching.", "The password the user has entered does not match the stored password.")); //NOI18N + } + + // Trace message + this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N + } +} -- 2.39.5