]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sat, 22 Apr 2017 20:04:26 +0000 (22:04 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 22 Apr 2017 21:09:13 +0000 (23:09 +0200)
- Let's always call super constructor (not the default one, of course), maybe
  one day there will be something added
- sorted members a bit
- some constructors still contain EJB-lookup code, moved to init()
  (@PostConstruct) method

Signed-off-by: Roland Häder <roland@mxchange.org>
28 files changed:
src/java/org/mxchange/pizzaapplication/beans/BasePizzaController.java
src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java
src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeatureWebApplicationBean.java
src/java/org/mxchange/pizzaapplication/beans/gender/PizzaGenderWebApplicationBean.java
src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperBean.java
src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionController.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaAdminMobileProviderWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationBean.java
src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/profilemode/PizzaProfileModeWebApplicationBean.java
src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java

index 93f367c13fb8a5d0497de236cd86c8dfca754508..023c468caa1bb5de5b455f1db35cd4db6fb26d12 100644 (file)
 package org.mxchange.pizzaapplication.beans;
 
 import java.io.Serializable;
+import java.security.Principal;
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
+import org.mxchange.jusercore.model.user.UserUtils;
 
 /**
  * A general controller
@@ -32,6 +38,35 @@ public abstract class BasePizzaController implements Serializable {
         */
        private static final long serialVersionUID = 50_837_597_127_567_140L;
 
+       /**
+        * Protected constructor
+        */
+       protected BasePizzaController () {
+       }
+
+       /**
+        * Determines principal's name or returns null if no principal (security) is
+        * set.
+        * <p>
+        * @return Principal's name or null
+        */
+       protected String determinePrincipalName () {
+               // Get principal
+               Principal userPrincipal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
+
+               // Init with null
+               String principalName = null;
+
+               // Is the principal set?
+               if (userPrincipal instanceof Principal) {
+                       // Get principal's name
+                       principalName = userPrincipal.getName();
+               }
+
+               // Return it
+               return principalName;
+       }
+
        /**
         * Returns given property key or throws an exception if not found.
         * <p>
@@ -66,7 +101,7 @@ public abstract class BasePizzaController implements Serializable {
                // Is it null?
                if (null == contextValue) {
                        // Throw NPE
-                       throw new NullPointerException("parameterKey=" + parameterKey + " is not set.");
+                       throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N
                }
 
                // Return it
@@ -91,15 +126,39 @@ public abstract class BasePizzaController implements Serializable {
                }
 
                // Try to get context parameter
-               String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N
+               String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N
 
                // Is it set and true?
-               boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.equals("true"))); //NOI18N
+               boolean isEnabled = (Boolean.parseBoolean(contextParameter) == Boolean.TRUE);
 
                // Return it
                return isEnabled;
        }
 
+       /**
+        * Checks if given password is to weak to be used
+        * <p>
+        * @param password Clear-text password
+        * <p>
+        * @return Whether the entered password is to weak
+        */
+       protected boolean isWeakPassword (final String password) {
+               // Is parameter set?
+               if (null == password) {
+                       // Throw NPE
+                       throw new NullPointerException("password is null"); //NOI18N
+               }
+
+               // Get score value
+               double passwordScore = UserUtils.calculatePasswordScore(password);
+
+               // Is the score within range?
+               boolean isWeak = (passwordScore <= this.getIntegerContextParameter("min_user_password_score")); //NOI18N
+
+               // Return it
+               return isWeak;
+       }
+
        /**
         * Shows a faces message for given causing exception. The message from the
         * exception is being inserted into the message.
@@ -113,12 +172,47 @@ public abstract class BasePizzaController implements Serializable {
        }
 
        /**
-        * Shows a faces message with given message.
+        * Shows a faces message with given message (i18n) key.
         * <p>
         * @param clientId Client id to send message to
-        * @param message Causing exception
+        * @param i18nKey  Message key
+        * <p>
+        * @throws NullPointerException If clientId or i18nKey is null
+        * @throws IllegalArgumentException If clientId or i18nKey is empty
         */
-       protected void showFacesMessage (final String clientId, final String message) {
+       protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException {
+               // Both parameter must be valid
+               if (null == clientId) {
+                       // Throw NPE
+                       throw new NullPointerException("clientId is null"); //NOI18N
+               } else if (clientId.isEmpty()) {
+                       // Is empty
+                       throw new IllegalArgumentException("clientId is null"); //NOI18N
+               } else if (null == i18nKey) {
+                       // Throw NPE
+                       throw new NullPointerException("i18nKey is null"); //NOI18N
+               } else if (i18nKey.isEmpty()) {
+                       // Is empty
+                       throw new IllegalArgumentException("i18nKey is null"); //NOI18N
+               }
+
+               // Get current locale
+               Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
+
+               // Get bundle bundle
+               ResourceBundle bundle = ResourceBundle.getBundle("org.mxchange.localization.bundle", locale);
+
+               // Default is i18nKey
+               String message = i18nKey;
+
+               // Try it
+               try {
+                       // Get message
+                       message = bundle.getString(i18nKey);
+               } catch (final MissingResourceException ex) {
+                       // Did not find it, ignored
+               }
+
                // Get context and add message
                FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));
        }
index 9a80c2cca83b28c2d67a9cb276b5820b7b7baf13..f5ac8966472728dbfb54e895e4b9d14c76bbf432 100644 (file)
@@ -89,6 +89,8 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
         * Default constructor
         */
        public PizzaConfirmationLinkWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 9925c2c3813cb6088ff8cd44c44be34023528003..5bb3fe650f5624e6f7773c3b7f459089c67dc747 100644 (file)
@@ -247,6 +247,8 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
         * Default constructor
         */
        public PizzaAdminContactWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index fee0808b9f7093a30716c30721a9ea4902889af1..fa011585cafd581dd60bc139e783ffc467deeac9 100644 (file)
@@ -56,7 +56,7 @@ import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
 
 /**
@@ -234,6 +234,9 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P
         * Default constructor
         */
        public PizzaContactWebSessionBean () {
+               // Call super constructor
+               super();
+
                // Init lists/maps
                this.contactList = new LinkedList<>();
                this.emailAddressList = new LinkedList<>();
index 1305fed7fb5b878c5706923c41e39fa7acd82092..dc11a210e740927c5d168aad07d07e8399357d55 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.pizzaapplication.beans.contact.phone;
 
 import java.text.MessageFormat;
+import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
@@ -140,20 +141,11 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         * Default constructor
         */
        public PizzaAdminContactPhoneWebRequestBean () {
+               // Call super constructor
+               super();
+
                // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
                // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
-
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the beans
-                       this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
        }
 
        /**
@@ -414,6 +406,24 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                return "admin_show_contact"; //NOI18N
        }
 
+       /**
+        * Post-construction method
+        */
+       @PostConstruct
+       public void init () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the beans
+                       this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+       }
+
        @Override
        public String unlinkFaxContactData () {
                // Is all data set
index cf6c47911225e362316ea787dec21b4273a8d478..9b250778fe8d7df3ec3c795a9af61c99f0efa1ae 100644 (file)
@@ -78,6 +78,9 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme
         * Default constructor
         */
        public PizzaContactPhoneWebSessionBean () {
+               // Call super constructor
+               super();
+
                // Init lists/maps
                this.contacts = new HashMap<>(10);
        }
index 4fc4d27c793ee0bbd6fef96a79a2ebbceeaefa95..3566dfc9d3d17c4b85d5d29fc3389fb08df76158 100644 (file)
@@ -103,6 +103,8 @@ public class PizzaAdminCountryWebRequestBean extends BasePizzaController impleme
         * Default constructor
         */
        public PizzaAdminCountryWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 123bdbeed72895ffbeaf012cb4c42261dafb57b1..89a1cff374adec70ae83ae46227bb9a5cf94fb8f 100644 (file)
@@ -59,6 +59,8 @@ public class PizzaCountryWebApplicationBean extends BasePizzaController implemen
         * Default constructor
         */
        public PizzaCountryWebApplicationBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index 038767f5acb323a671b9a48173fbd8c4a74cf0ae..8aa85996190e3181606a7cd76b9686b41fc33818 100644 (file)
@@ -36,7 +36,7 @@ import org.mxchange.jusercore.model.email_address.UserEmailChangeSessionBeanRemo
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
 import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
 
 /**
  * A web session-scoped bean for changing email addresses
@@ -88,6 +88,8 @@ public class PizzaEmailChangeWebSessionBean extends BasePizzaController implemen
         * Default constructor
         */
        public PizzaEmailChangeWebSessionBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index b6fd1807925e1cb065faf09a7bf5f8a1613e14e8..0c8889ecde69cb2a858b40f625fd4ef738a0be99 100644 (file)
@@ -39,6 +39,8 @@ public class PizzaFeatureWebApplicationBean extends BasePizzaController implemen
         * Default constructor
         */
        public PizzaFeatureWebApplicationBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index a1d65d20569d0b6f50a185856bb758a9da9da66c..b7925a2f0564e1fcefeed1952e630205c1a9de67 100644 (file)
@@ -42,6 +42,8 @@ public class PizzaGenderWebApplicationBean extends BasePizzaController implement
         * Default constructor
         */
        public PizzaGenderWebApplicationBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index a60e098065b77011ab9f4e570ec526504c83db02..e1fdb68f3300304bcd802a4920e319b0544ae584 100644 (file)
@@ -115,6 +115,9 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
         * Default constructor
         */
        public PizzaWebRequestHelperBean () {
+               // Call super constructor
+               super();
+
                // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
                // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
        }
index bbece457c1840dd4b7faf21ebe3780238664cb8d..6920a5dbb0d53d67e0ff5104f9f569b962054c23 100644 (file)
@@ -53,6 +53,8 @@ public class PizzaLocalizationSessionBean extends BasePizzaController implements
         * Default constructor
         */
        public PizzaLocalizationSessionBean () {
+               // Call super constructor
+               super();
        }
 
        /**
diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java
deleted file mode 100644 (file)
index f02526a..0000000
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Häder
- *
- * 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.login;
-
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Any;
-import javax.faces.context.FacesContext;
-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.container.login.LoginContainer;
-import org.mxchange.jusercore.container.login.UserLoginContainer;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.jusercore.events.login.UserLoggedInEvent;
-import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent;
-import org.mxchange.jusercore.events.logout.UserLogoutEvent;
-import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
-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.login.UserLoginSessionBeanRemote;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserUtils;
-import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
-import org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
-
-/**
- * A web bean for user registration
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("userLoginController")
-@SessionScoped
-public class PizzaUserLoginWebSessionBean extends BasePizzaController implements PizzaUserLoginWebSessionController {
-
-       /**
-        * Path name for guest base template
-        */
-       private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest";
-
-       /**
-        * Path name for logged-in user base template
-        */
-       private static final String USER_BASE_TEMPLATE_NAME = "login/user/user";
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 47_828_986_719_691_592L;
-
-       /**
-        * Template type for pages that might be displayed in guest area and login
-        * area.
-        */
-       private String baseTemplatePathName;
-
-       /**
-        * Logged-in user instance
-        */
-       private User loggedInUser;
-
-       /**
-        * Event fired when user has logged in
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserLoggedInEvent> loginEvent;
-
-       /**
-        * User controller
-        */
-       @Inject
-       private PizzaUserWebSessionController userController;
-
-       /**
-        * Current password
-        */
-       private String userCurrentPassword;
-
-       /**
-        * Flag whether the user has logged-in, set only from inside
-        */
-       private boolean userLoggedIn;
-
-       /**
-        * Remote register session-scoped bean
-        */
-       private UserLoginSessionBeanRemote userLoginBean;
-
-       /**
-        * Event fired when user has logged in
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserLoggedInEvent> userLoginEvent;
-
-       /**
-        * Event fired when user has logged out
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserLogoutEvent> userLogoutEvent;
-
-       /**
-        * User's password history
-        */
-       private List<PasswordHistory> userPasswordHistory;
-
-       /**
-        * EJB for user's password history
-        */
-       private UserPasswordHistorySessionBeanRemote userPasswordHistoryBean;
-
-       /**
-        * Default constructor
-        */
-       public PizzaUserLoginWebSessionBean () {
-               // Defaul template is guest
-               this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
-       }
-
-       /**
-        * Method being call after user's password has been updated (and history
-        * entry has been created).
-        * <p>
-        * @param event Event being observed
-        */
-       public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
-               // Check parameter
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getPasswordHistory() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.passwordHistory is null"); //NOI18N
-               } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
-                       // ... and again
-                       throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
-               } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
-                       // Invalid value
-                       throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
-               }
-
-               // All fine, so update list
-               this.updatePasswordHistory(event.getPasswordHistory());
-       }
-
-       @Override
-       public String doAdminLogout () {
-               // Is a user logged-in?
-               if (this.isUserLoggedIn()) {
-                       // Call other logout
-                       return this.doUserLogout();
-               }
-
-               // Invalidate session
-               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
-
-               // Set template type to guest
-               this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
-
-               // Redirect to index
-               return "index?faces-redirect=true"; //NOI18N
-       }
-
-       @Override
-       public String doUserLogin () {
-               // Get user instance
-               User user = this.userController.createUserLogin();
-
-               // Create login container
-               LoginContainer container = new UserLoginContainer(user, this.userController.getUserPassword());
-
-               try {
-                       // Call bean
-                       User confirmedUser = this.userLoginBean.validateUserAccountStatus(container);
-
-                       // All fine here so set it here
-                       this.setLoggedInUser(confirmedUser);
-
-                       // Retrieve user's password list
-                       this.userPasswordHistory = this.userPasswordHistoryBean.getUserPasswordHistory(confirmedUser);
-
-                       // Set template to "login"
-                       this.setBaseTemplatePathName(USER_BASE_TEMPLATE_NAME); //NOI18N
-
-                       // Fire event away. Keep this last before return statement.
-                       this.userLoginEvent.fire(new UserLoggedInEvent(confirmedUser));
-
-                       // Clear this bean
-                       this.clear();
-
-                       // All fine
-                       return "login_user"; //NOI18N
-               } catch (final UserNotFoundException ex) {
-                       // Show JSF message
-                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N
-                       return ""; //NOI18N
-               } catch (final UserStatusLockedException ex) {
-                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N
-                       return ""; //NOI18N
-               } catch (final UserStatusUnconfirmedException ex) {
-                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N
-                       return ""; //NOI18N
-               } catch (final UserPasswordMismatchException ex) {
-                       // Show JSF message
-                       this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N
-                       return ""; //NOI18N
-               }
-       }
-
-       @Override
-       public String doUserLogout () {
-               // Is loggedInUser set?
-               if (this.getLoggedInUser() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("this.loggedInUser is null"); //NOI18N
-               } else if (this.getLoggedInUser().getUserId() == null) {
-                       // Throw again
-                       throw new NullPointerException("this.loggedInUser.userId is null"); //NOI18N
-               } else if (this.getLoggedInUser().getUserId() < 1) {
-                       // Invalid user id
-                       throw new IllegalStateException(MessageFormat.format("this.loggedInUser.userId={0} is not valid.", this.getLoggedInUser().getUserId())); //NOI18N
-               }
-
-               // Fire event
-               this.userLogoutEvent.fire(new UserLogoutEvent(this.getLoggedInUser()));
-
-               // Invalidate session
-               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
-
-               // Unset any user instances
-               this.setLoggedInUser(null);
-               this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
-
-               // Redirect to index
-               return "index"; //NOI18N
-       }
-
-       @Override
-       public String getBaseTemplatePathName () {
-               return this.baseTemplatePathName;
-       }
-
-       @Override
-       public void setBaseTemplatePathName (final String baseTemplatePathName) {
-               this.baseTemplatePathName = baseTemplatePathName;
-       }
-
-       @Override
-       public User getLoggedInUser () {
-               return this.loggedInUser;
-       }
-
-       @Override
-       public void setLoggedInUser (final User loggedInUser) {
-               this.loggedInUser = loggedInUser;
-       }
-
-       @Override
-       public String getUserCurrentPassword () {
-               return this.userCurrentPassword;
-       }
-
-       @Override
-       public void setUserCurrentPassword (final String userCurrentPassword) {
-               this.userCurrentPassword = userCurrentPassword;
-       }
-
-       @Override
-       public List<PasswordHistory> getUserPasswordHistory () {
-               return Collections.unmodifiableList(this.userPasswordHistory);
-       }
-
-       @Override
-       public boolean ifCurrentPasswordMatches () {
-               // The current password must be set and not empty
-               if (this.getUserCurrentPassword() == null) {
-                       // Is not set
-                       throw new NullPointerException("this.userCurrentPassword is null"); //NOI18N
-               } else if (this.getUserCurrentPassword().isEmpty()) {
-                       // Is set empty
-                       throw new IllegalStateException("this.userCurrentPassword is empty."); //NOI18N
-               }
-
-               // Create "container"
-               LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getUserCurrentPassword());
-
-               // Now check if it matches
-               return UserUtils.ifPasswordMatches(container, this.getLoggedInUser());
-       }
-
-       @Override
-       public boolean ifUserMustChangePassword () {
-               return ((this.isUserLoggedIn()) && (Objects.equals(this.getLoggedInUser().getUserMustChangePassword(), Boolean.TRUE)));
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userLoginBean = (UserLoginSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/login!org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote"); //NOI18N
-
-                       // Also find this
-                       this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N
-
-                       // Defaul template is guest
-                       this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
-               } catch (final NamingException ex) {
-                       // Continue to throw
-                       throw new FaceletException(ex);
-               }
-       }
-
-       @Override
-       public boolean isInvisible () {
-               // Check on login
-               if (!this.isUserLoggedIn()) {
-                       // Not logged in!
-                       throw new IllegalStateException("isInvisible() has been invoked for a guest."); //NOI18N
-               }
-
-               // Check logged-in first, then invisibility
-               return Objects.equals(this.getLoggedInUser().getUserProfileMode(), ProfileMode.INVISIBLE);
-       }
-
-       @Override
-       public boolean isPasswordInHistory (final String userPassword) {
-               // Default is not found
-               boolean isPasswordInHistory = false;
-
-               // Init variables
-               int count = 1;
-               int maxEntries = this.getIntegerContextParameter("max_user_password_history"); //NOI18N
-
-               // Check all passwords
-               for (final PasswordHistory entry : this.getUserPasswordHistory()) {
-                       // Is password the same?
-                       if (UserUtils.ifPasswordMatches(userPassword, entry.getUserPasswordHistoryUser())) {
-                               // Yes, found it
-                               isPasswordInHistory = true;
-                               break;
-                       } else if (count == maxEntries) {
-                               // Maximum reached
-                               break;
-                       }
-
-                       // Count up
-                       count++;
-               }
-
-               // Return status
-               return isPasswordInHistory;
-       }
-
-       @Override
-       public boolean isUserLoggedIn () {
-               // Compare instance
-               this.userLoggedIn = ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));
-
-               // Return it
-               return this.userLoggedIn;
-       }
-
-       /**
-        * Clears this bean
-        */
-       private void clear () {
-               // Clear all fields
-               this.setUserCurrentPassword(null);
-       }
-
-       /**
-        * Updates password history by adding given entry to it as long as it is not
-        * there.
-        * <p>
-        * @param passwordHistory Password history entry
-        */
-       private void updatePasswordHistory (final PasswordHistory passwordHistory) {
-               if (null == passwordHistory) {
-                       // Throw NPE
-                       throw new NullPointerException("passwordHistory is null"); //NOI18N
-               } else if (passwordHistory.getUserPasswordHistoryId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("passwordHistory.userPasswordHistoryId is null"); //NOI18N
-               } else if (passwordHistory.getUserPasswordHistoryId() < 1) {
-                       // Invalid id
-                       throw new IllegalArgumentException(MessageFormat.format("passwordHistory.userPasswordHistoryId={0} is not valid.", passwordHistory.getUserPasswordHistoryId())); //NOI18N
-               }
-
-               // Is it there?
-               if (this.userPasswordHistory.contains(passwordHistory)) {
-                       // Excact copy found
-                       return;
-               }
-
-               // Check all entries
-               for (final PasswordHistory entry : this.userPasswordHistory) {
-                       // Is same id number?
-                       if (Objects.equals(entry.getUserPasswordHistoryId(), passwordHistory.getUserPasswordHistoryId())) {
-                               // Found it
-                               return;
-                       }
-               }
-
-               // Not found, so add it
-               this.userPasswordHistory.add(passwordHistory);
-       }
-
-}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java
deleted file mode 100644 (file)
index 4468ecd..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Häder
- *
- * 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.login;
-
-import java.io.Serializable;
-import java.util.List;
-import javax.ejb.Local;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
-
-/**
- * An interface for registration web controllers
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Local
-public interface PizzaUserLoginWebSessionController extends Serializable {
-
-       /**
-        * Checks whether given clear-text password is in user's password history.
-        * <p>
-        * @param userPassword Clear-text password
-        * <p>
-        * @return Whether clear-text password is in user's password history
-        */
-       boolean isPasswordInHistory (final String userPassword);
-
-       /**
-        * Getter for base template type
-        * <p>
-        * @return Template type
-        */
-       String getBaseTemplatePathName ();
-
-       /**
-        * Setter for base template type
-        * <p>
-        * @param baseTemplatePathName Template type
-        */
-       void setBaseTemplatePathName (final String baseTemplatePathName);
-
-       /**
-        * Logout for administrator area. If a logged-in user instance exists, it is
-        * being logged-out, too.
-        * <p>
-        * @return Outcome (should be redirected)
-        */
-       String doAdminLogout ();
-
-       /**
-        * Logins the user, if the account is found, confirmed and unlocked.
-        * <p>
-        * @return Redirect target
-        */
-       String doUserLogin ();
-
-       /**
-        * Logout for current user by invalidating the current session.
-        * <p>
-        * @return Outcome (should be redirected)
-        */
-       String doUserLogout ();
-
-       /**
-        * Getter for logged-in user instance
-        * <p>
-        * @return Logged-in user instance
-        */
-       User getLoggedInUser ();
-
-       /**
-        * Setter for logged-in user instance
-        * <p>
-        * @param loggedInUser Logged-in user instance
-        */
-       void setLoggedInUser (final User loggedInUser);
-
-       /**
-        * Checks whether the user is logged-in
-        * <p>
-        * @return Whether the user is logged-in
-        */
-       boolean isUserLoggedIn ();
-
-       /**
-        * Checks whether the user needs to change password
-        * <p>
-        * @return Whether the user needs to change password
-        */
-       boolean ifUserMustChangePassword ();
-
-       /**
-        * Whether the currently logged-in user is invisible
-        * <p>
-        * @return Whether the currently logged-in user is invisible
-        */
-       boolean isInvisible ();
-
-       /**
-        * Setter for current password (clear text)
-        * <p>
-        * @param userCurrentPassword Current password
-        */
-       void setUserCurrentPassword (final String userCurrentPassword);
-
-       /**
-        * Getter for current password (clear text)
-        * <p>
-        * @return Current password
-        */
-       String getUserCurrentPassword ();
-
-       /**
-        * Checks whether the (previously entered) current password matches with
-        * from the user instance.
-        * <p>
-        * @return If current password matches
-        */
-       boolean ifCurrentPasswordMatches ();
-
-       /**
-        * Getter for user's password history
-        * <p>
-        * @return User's password history
-        */
-       List<PasswordHistory> getUserPasswordHistory ();
-
-}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionBean.java
new file mode 100644 (file)
index 0000000..2287bb3
--- /dev/null
@@ -0,0 +1,448 @@
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * 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.login.user;
+
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
+import javax.faces.context.FacesContext;
+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.container.login.LoginContainer;
+import org.mxchange.jusercore.container.login.UserLoginContainer;
+import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent;
+import org.mxchange.jusercore.events.logout.UserLogoutEvent;
+import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
+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.login.UserLoginSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserUtils;
+import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
+import org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
+
+/**
+ * A web bean for user registration
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("userLoginController")
+@SessionScoped
+public class PizzaUserLoginWebSessionBean extends BasePizzaController implements PizzaUserLoginWebSessionController {
+
+       /**
+        * Path name for guest base template
+        */
+       private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest";
+
+       /**
+        * Path name for logged-in user base template
+        */
+       private static final String USER_BASE_TEMPLATE_NAME = "login/user/user";
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 47_828_986_719_691_592L;
+
+       /**
+        * Template type for pages that might be displayed in guest area and login
+        * area.
+        */
+       private String baseTemplatePathName;
+
+       /**
+        * Logged-in user instance
+        */
+       private User loggedInUser;
+
+       /**
+        * Event fired when user has logged in
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserLoggedInEvent> loginEvent;
+
+       /**
+        * User controller
+        */
+       @Inject
+       private PizzaUserWebSessionController userController;
+
+       /**
+        * Current password
+        */
+       private String userCurrentPassword;
+
+       /**
+        * Flag whether the user has logged-in, set only from inside
+        */
+       private boolean userLoggedIn;
+
+       /**
+        * Remote register session-scoped bean
+        */
+       private UserLoginSessionBeanRemote userLoginBean;
+
+       /**
+        * Event fired when user has logged in
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserLoggedInEvent> userLoginEvent;
+
+       /**
+        * Event fired when user has logged out
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserLogoutEvent> userLogoutEvent;
+
+       /**
+        * User's password history
+        */
+       private List<PasswordHistory> userPasswordHistory;
+
+       /**
+        * EJB for user's password history
+        */
+       private UserPasswordHistorySessionBeanRemote userPasswordHistoryBean;
+
+       /**
+        * Default constructor
+        */
+       public PizzaUserLoginWebSessionBean () {
+               // Call super constructor
+               super();
+
+               // Defaul template is guest
+               this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
+       }
+
+       /**
+        * Method being call after user's password has been updated (and history
+        * entry has been created).
+        * <p>
+        * @param event Event being observed
+        */
+       public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
+               // Check parameter
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getPasswordHistory() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.passwordHistory is null"); //NOI18N
+               } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
+                       // ... and again
+                       throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
+               } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
+                       // Invalid value
+                       throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
+               }
+
+               // All fine, so update list
+               this.updatePasswordHistory(event.getPasswordHistory());
+       }
+
+       @Override
+       public String doAdminLogout () {
+               // Is a user logged-in?
+               if (this.isUserLoggedIn()) {
+                       // Call other logout
+                       return this.doUserLogout();
+               }
+
+               // Invalidate session
+               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
+
+               // Set template type to guest
+               this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
+
+               // Redirect to index
+               return "index?faces-redirect=true"; //NOI18N
+       }
+
+       @Override
+       public String doUserLogin () {
+               // Get user instance
+               User user = this.userController.createUserLogin();
+
+               // Create login container
+               LoginContainer container = new UserLoginContainer(user, this.userController.getUserPassword());
+
+               try {
+                       // Call bean
+                       User confirmedUser = this.userLoginBean.validateUserAccountStatus(container);
+
+                       // All fine here so set it here
+                       this.setLoggedInUser(confirmedUser);
+
+                       // Retrieve user's password list
+                       this.userPasswordHistory = this.userPasswordHistoryBean.getUserPasswordHistory(confirmedUser);
+
+                       // Set template to "login"
+                       this.setBaseTemplatePathName(USER_BASE_TEMPLATE_NAME); //NOI18N
+
+                       // Fire event away. Keep this last before return statement.
+                       this.userLoginEvent.fire(new UserLoggedInEvent(confirmedUser));
+
+                       // Clear this bean
+                       this.clear();
+
+                       // All fine
+                       return "login_user"; //NOI18N
+               } catch (final UserNotFoundException ex) {
+                       // Show JSF message
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserStatusLockedException ex) {
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserStatusUnconfirmedException ex) {
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserPasswordMismatchException ex) {
+                       // Show JSF message
+                       this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N
+                       return ""; //NOI18N
+               }
+       }
+
+       @Override
+       public String doUserLogout () {
+               // Is loggedInUser set?
+               if (this.getLoggedInUser() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.loggedInUser is null"); //NOI18N
+               } else if (this.getLoggedInUser().getUserId() == null) {
+                       // Throw again
+                       throw new NullPointerException("this.loggedInUser.userId is null"); //NOI18N
+               } else if (this.getLoggedInUser().getUserId() < 1) {
+                       // Invalid user id
+                       throw new IllegalStateException(MessageFormat.format("this.loggedInUser.userId={0} is not valid.", this.getLoggedInUser().getUserId())); //NOI18N
+               }
+
+               // Fire event
+               this.userLogoutEvent.fire(new UserLogoutEvent(this.getLoggedInUser()));
+
+               // Invalidate session
+               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
+
+               // Unset any user instances
+               this.setLoggedInUser(null);
+               this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
+
+               // Redirect to index
+               return "index"; //NOI18N
+       }
+
+       @Override
+       public String getBaseTemplatePathName () {
+               return this.baseTemplatePathName;
+       }
+
+       @Override
+       public void setBaseTemplatePathName (final String baseTemplatePathName) {
+               this.baseTemplatePathName = baseTemplatePathName;
+       }
+
+       @Override
+       public User getLoggedInUser () {
+               return this.loggedInUser;
+       }
+
+       @Override
+       public void setLoggedInUser (final User loggedInUser) {
+               this.loggedInUser = loggedInUser;
+       }
+
+       @Override
+       public String getUserCurrentPassword () {
+               return this.userCurrentPassword;
+       }
+
+       @Override
+       public void setUserCurrentPassword (final String userCurrentPassword) {
+               this.userCurrentPassword = userCurrentPassword;
+       }
+
+       @Override
+       public List<PasswordHistory> getUserPasswordHistory () {
+               return Collections.unmodifiableList(this.userPasswordHistory);
+       }
+
+       @Override
+       public boolean ifCurrentPasswordMatches () {
+               // The current password must be set and not empty
+               if (this.getUserCurrentPassword() == null) {
+                       // Is not set
+                       throw new NullPointerException("this.userCurrentPassword is null"); //NOI18N
+               } else if (this.getUserCurrentPassword().isEmpty()) {
+                       // Is set empty
+                       throw new IllegalStateException("this.userCurrentPassword is empty."); //NOI18N
+               }
+
+               // Create "container"
+               LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getUserCurrentPassword());
+
+               // Now check if it matches
+               return UserUtils.ifPasswordMatches(container, this.getLoggedInUser());
+       }
+
+       @Override
+       public boolean ifUserMustChangePassword () {
+               return ((this.isUserLoggedIn()) && (Objects.equals(this.getLoggedInUser().getUserMustChangePassword(), Boolean.TRUE)));
+       }
+
+       /**
+        * Post-construction method
+        */
+       @PostConstruct
+       public void init () {
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.userLoginBean = (UserLoginSessionBeanRemote) context.lookup("java:global/jrecruiter-ejb/userLogin!org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote"); //NOI18N
+
+                       // Also find this
+                       this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/jrecruiter-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N
+
+                       // Defaul template is guest
+                       this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
+               } catch (final NamingException ex) {
+                       // Continue to throw
+                       throw new FaceletException(ex);
+               }
+       }
+
+       @Override
+       public boolean isInvisible () {
+               // Check on login
+               if (!this.isUserLoggedIn()) {
+                       // Not logged in!
+                       throw new IllegalStateException("isInvisible() has been invoked for a guest."); //NOI18N
+               }
+
+               // Check logged-in first, then invisibility
+               return Objects.equals(this.getLoggedInUser().getUserProfileMode(), ProfileMode.INVISIBLE);
+       }
+
+       @Override
+       public boolean isPasswordInHistory (final String userPassword) {
+               // Default is not found
+               boolean isPasswordInHistory = false;
+
+               // Init variables
+               int count = 1;
+               int maxEntries = this.getIntegerContextParameter("max_user_password_history"); //NOI18N
+
+               // Check all passwords
+               for (final PasswordHistory entry : this.getUserPasswordHistory()) {
+                       // Is password the same?
+                       if (UserUtils.ifPasswordMatches(userPassword, entry.getUserPasswordHistoryUser())) {
+                               // Yes, found it
+                               isPasswordInHistory = true;
+                               break;
+                       } else if (count == maxEntries) {
+                               // Maximum reached
+                               break;
+                       }
+
+                       // Count up
+                       count++;
+               }
+
+               // Return status
+               return isPasswordInHistory;
+       }
+
+       @Override
+       public boolean isUserLoggedIn () {
+               // Compare instance
+               this.userLoggedIn = ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));
+
+               // Return it
+               return this.userLoggedIn;
+       }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all fields
+               this.setUserCurrentPassword(null);
+       }
+
+       /**
+        * Updates password history by adding given entry to it as long as it is not
+        * there.
+        * <p>
+        * @param passwordHistory Password history entry
+        */
+       private void updatePasswordHistory (final PasswordHistory passwordHistory) {
+               if (null == passwordHistory) {
+                       // Throw NPE
+                       throw new NullPointerException("passwordHistory is null"); //NOI18N
+               } else if (passwordHistory.getUserPasswordHistoryId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("passwordHistory.userPasswordHistoryId is null"); //NOI18N
+               } else if (passwordHistory.getUserPasswordHistoryId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("passwordHistory.userPasswordHistoryId={0} is not valid.", passwordHistory.getUserPasswordHistoryId())); //NOI18N
+               }
+
+               // Is it there?
+               if (this.userPasswordHistory.contains(passwordHistory)) {
+                       // Excact copy found
+                       return;
+               }
+
+               // Check all entries
+               for (final PasswordHistory entry : this.userPasswordHistory) {
+                       // Is same id number?
+                       if (Objects.equals(entry.getUserPasswordHistoryId(), passwordHistory.getUserPasswordHistoryId())) {
+                               // Found it
+                               return;
+                       }
+               }
+
+               // Not found, so add it
+               this.userPasswordHistory.add(passwordHistory);
+       }
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionController.java
new file mode 100644 (file)
index 0000000..9bae6a9
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * 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.login.user;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.ejb.Local;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
+
+/**
+ * An interface for registration web controllers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Local
+public interface PizzaUserLoginWebSessionController extends Serializable {
+
+       /**
+        * Checks whether given clear-text password is in user's password history.
+        * <p>
+        * @param userPassword Clear-text password
+        * <p>
+        * @return Whether clear-text password is in user's password history
+        */
+       boolean isPasswordInHistory (final String userPassword);
+
+       /**
+        * Getter for base template type
+        * <p>
+        * @return Template type
+        */
+       String getBaseTemplatePathName ();
+
+       /**
+        * Setter for base template type
+        * <p>
+        * @param baseTemplatePathName Template type
+        */
+       void setBaseTemplatePathName (final String baseTemplatePathName);
+
+       /**
+        * Logout for administrator area. If a logged-in user instance exists, it is
+        * being logged-out, too.
+        * <p>
+        * @return Outcome (should be redirected)
+        */
+       String doAdminLogout ();
+
+       /**
+        * Logins the user, if the account is found, confirmed and unlocked.
+        * <p>
+        * @return Redirect target
+        */
+       String doUserLogin ();
+
+       /**
+        * Logout for current user by invalidating the current session.
+        * <p>
+        * @return Outcome (should be redirected)
+        */
+       String doUserLogout ();
+
+       /**
+        * Getter for logged-in user instance
+        * <p>
+        * @return Logged-in user instance
+        */
+       User getLoggedInUser ();
+
+       /**
+        * Setter for logged-in user instance
+        * <p>
+        * @param loggedInUser Logged-in user instance
+        */
+       void setLoggedInUser (final User loggedInUser);
+
+       /**
+        * Checks whether the user is logged-in
+        * <p>
+        * @return Whether the user is logged-in
+        */
+       boolean isUserLoggedIn ();
+
+       /**
+        * Checks whether the user needs to change password
+        * <p>
+        * @return Whether the user needs to change password
+        */
+       boolean ifUserMustChangePassword ();
+
+       /**
+        * Whether the currently logged-in user is invisible
+        * <p>
+        * @return Whether the currently logged-in user is invisible
+        */
+       boolean isInvisible ();
+
+       /**
+        * Setter for current password (clear text)
+        * <p>
+        * @param userCurrentPassword Current password
+        */
+       void setUserCurrentPassword (final String userCurrentPassword);
+
+       /**
+        * Getter for current password (clear text)
+        * <p>
+        * @return Current password
+        */
+       String getUserCurrentPassword ();
+
+       /**
+        * Checks whether the (previously entered) current password matches with
+        * from the user instance.
+        * <p>
+        * @return If current password matches
+        */
+       boolean ifCurrentPasswordMatches ();
+
+       /**
+        * Getter for user's password history
+        * <p>
+        * @return User's password history
+        */
+       List<PasswordHistory> getUserPasswordHistory ();
+
+}
index f2fd5eece021d9c533c27843758e8a2067344bb6..4cb720bfae31a39b5d8a72321c19b31d1c51c4da 100644 (file)
@@ -94,6 +94,8 @@ public class PizzaAdminMobileProviderWebRequestBean extends BasePizzaController
         * Default constructor
         */
        public PizzaAdminMobileProviderWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 8ec2a31a7e6452f14f240c0addb750ed92c2a723..5e9f511d7072090c04a3bbe9ebbba6b0e2bc9f57 100644 (file)
@@ -59,6 +59,8 @@ public class PizzaMobileProviderWebRequestBean extends BasePizzaController imple
         * Default constructor
         */
        public PizzaMobileProviderWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index 8cdec597f027457a5ca020c2e7e7ea27bf29526f..30e705c3911668921facdaac83441e8100a844bf 100644 (file)
@@ -196,6 +196,9 @@ public class PizzaAdminPhoneWebRequestBean extends BasePizzaController implement
         * Default constructor
         */
        public PizzaAdminPhoneWebRequestBean () {
+               // Call super constructor
+               super();
+
                // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
                // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
        }
index 045d41254cdac1b3b6a8e57b08c83d30ca60ebc0..17de1124e4bb6daacbc40225b24f6fb6fb200ac4 100644 (file)
@@ -85,17 +85,8 @@ public class PizzaPhoneWebApplicationBean extends BasePizzaController implements
         * Default constructor
         */
        public PizzaPhoneWebApplicationBean () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the beans
-                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw it again
-                       throw new FaceletException(e);
-               }
+               // Call super constructor
+               super();
 
                // Init all lists
                this.mobileNumbers = new LinkedList<>();
@@ -450,6 +441,18 @@ public class PizzaPhoneWebApplicationBean extends BasePizzaController implements
         */
        @PostConstruct
        public void init () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the beans
+                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw it again
+                       throw new FaceletException(e);
+               }
+
                // All phone numbers
                this.allMobileNumbers().addAll(this.phoneBean.allMobileNumbers());
                this.allFaxNumbers().addAll(this.phoneBean.allFaxNumbers());
index 308ff3d64acfbbdfecb1f5aa6127739ec1fda0cd..1716c9b9511f47bb2a126f5054bf827d7960aff8 100644 (file)
@@ -26,7 +26,7 @@ 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.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
 
 /**
@@ -59,6 +59,8 @@ public class PizzaUserProfileWebRequestBean extends BasePizzaController implemen
         * Default constructor
         */
        public PizzaUserProfileWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index e2008ecd93f07ec51f29ea980d005bcf67ef37ae..85c6032aff58bb12199518d664c8bd5e35b9367d 100644 (file)
@@ -40,6 +40,8 @@ public class PizzaProfileModeWebApplicationBean extends BasePizzaController impl
         * Default constructor
         */
        public PizzaProfileModeWebApplicationBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 74578568c39ad3515f861fd112439a8a795e2265..c90f482dc0fac55183a6c067ea17ad287393df34 100644 (file)
@@ -83,22 +83,24 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme
        private UserRegistrationSessionBeanRemote registerBean;
 
        /**
-        * An en event fireable when a new user has registered
+        * User controller
         */
        @Inject
-       @Any
-       private Event<ObservableUserRegisteredEvent> registeredEvent;
+       private PizzaUserWebSessionController userController;
 
        /**
-        * User controller
+        * An en event fireable when a new user has registered
         */
        @Inject
-       private PizzaUserWebSessionController userController;
+       @Any
+       private Event<ObservableUserRegisteredEvent> userRegisteredEvent;
 
        /**
         * Default constructor
         */
        public PizzaUserRegisterWebSessionBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
@@ -165,7 +167,7 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme
                        assert (registeredUser.getUserId() instanceof Long) : "registeredUser.userId is null after registerUser() was called."; //NOI18N
 
                        // Fire event
-                       this.registeredEvent.fire(new UserRegisteredEvent(registeredUser));
+                       this.userRegisteredEvent.fire(new UserRegisteredEvent(registeredUser));
 
                        // All fine, redirect to proper page
                        return "register_done"; //NOI18N
index a0ce634cc571cba1acb2ac8d6095d1cd1dc92609..4f2b4d22f89f187bd5b1966e9c18705857450fbd 100644 (file)
@@ -58,17 +58,17 @@ public class PizzaResendLinkWebSessionBean extends BasePizzaController implement
         */
        private String emailAddress;
 
-       /**
-        * EJB for resending confirmation link
-        */
-       private ResendLinkSessionBeanRemote resendLinkBean;
-
        /**
         * Localization controller
         */
        @Inject
        private PizzaLocalizationSessionController localizationController;
 
+       /**
+        * EJB for resending confirmation link
+        */
+       private ResendLinkSessionBeanRemote resendLinkBean;
+
        /**
         * Regular user controller
         */
@@ -86,6 +86,8 @@ public class PizzaResendLinkWebSessionBean extends BasePizzaController implement
         * Default constructor
         */
        public PizzaResendLinkWebSessionBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 48fa242f52d67b9d33faa0b52c0abcc667b4ff58..35cad3b4878e1c046db30c80a17f1d30600eae92 100644 (file)
@@ -197,6 +197,8 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
         * Default constructor
         */
        public PizzaAdminUserWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 1a310886a3f4f44cb8548d1e1ab8204d0840c221..28d438f30013447e562c0bfa33a2e9b57bcbf4dd 100644 (file)
@@ -56,7 +56,7 @@ import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
 import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
 import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
 
 /**
  * A user bean (controller)
@@ -149,6 +149,8 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
         * Default constructor
         */
        public PizzaUserWebSessionBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index 044468e3f86af7646046e3d31ea3b2fcbf640b70..094808fcea32227f4488a772f394845056f8e203 100644 (file)
@@ -40,7 +40,7 @@ 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;
+import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
 
 /**
  * A user password (change) bean (controller)
@@ -99,6 +99,8 @@ public class PizzaUserPasswordWebRequestBean extends BasePizzaController impleme
         * Default constructor
         */
        public PizzaUserPasswordWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override