]> git.mxchange.org Git - jjobs-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 20:57:41 +0000 (22:57 +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>
29 files changed:
src/java/org/mxchange/jjobs/beans/BaseJobsController.java
src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionBean.java
src/java/org/mxchange/jjobs/beans/confirmlink/JobsConfirmationLinkWebRequestBean.java
src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java
src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java
src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java
src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebSessionBean.java
src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebRequestBean.java
src/java/org/mxchange/jjobs/beans/country/JobsCountryWebApplicationBean.java
src/java/org/mxchange/jjobs/beans/email_address/JobsEmailChangeWebSessionBean.java
src/java/org/mxchange/jjobs/beans/features/JobsFeatureWebApplicationBean.java
src/java/org/mxchange/jjobs/beans/gender/JobsGenderWebApplicationBean.java
src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java
src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java
src/java/org/mxchange/jjobs/beans/login/JobsUserLoginWebSessionBean.java [deleted file]
src/java/org/mxchange/jjobs/beans/login/JobsUserLoginWebSessionController.java [deleted file]
src/java/org/mxchange/jjobs/beans/login/user/JobsUserLoginWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/beans/login/user/JobsUserLoginWebSessionController.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java
src/java/org/mxchange/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java
src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java
src/java/org/mxchange/jjobs/beans/phone/JobsPhoneWebApplicationBean.java
src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java
src/java/org/mxchange/jjobs/beans/profilemode/JobsProfileModeWebApplicationBean.java
src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java
src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkWebSessionBean.java
src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java
src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java
src/java/org/mxchange/jjobs/beans/user/password/JobsUserPasswordWebRequestBean.java

index 03acfab3b2296bb1b22996c71814cb678d4d4db6..7cbbacd408fafaf32548f3b4637ba2970f8d9bba 100644 (file)
@@ -38,6 +38,12 @@ public abstract class BaseJobsController implements Serializable {
         */
        private static final long serialVersionUID = 50_837_597_127_567_140L;
 
+       /**
+        * Protected constructor
+        */
+       protected BaseJobsController () {
+       }
+
        /**
         * Determines principal's name or returns null if no principal (security) is
         * set.
index cd9fb5854d5d5f2f57b0dfeb2140f074a35155d2..7bf277ac0d70a79b5d113833c476bc4184fa7ae0 100644 (file)
@@ -35,16 +35,16 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
 import org.mxchange.jaddressbookcore.events.addressbook.AddressbookLoadedEvent;
+import org.mxchange.jaddressbookcore.events.addressbook.ObservableAddressbookLoadedEvent;
 import org.mxchange.jaddressbookcore.exceptions.AddressbookNameAlreadyUsedException;
 import org.mxchange.jaddressbookcore.exceptions.AddressbookNotFoundException;
 import org.mxchange.jaddressbookcore.model.addressbook.Addressbook;
 import org.mxchange.jaddressbookcore.model.addressbook.UserAddressbook;
 import org.mxchange.jaddressbookcore.model.addressbook.entry.AddressbookEntry;
 import org.mxchange.jjobs.beans.BaseJobsController;
-import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jaddressbookcore.events.addressbook.ObservableAddressbookLoadedEvent;
+import org.mxchange.jjobs.beans.login.user.JobsUserLoginWebSessionController;
 import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.jusercore.model.user.User;
 
 /**
  * An address book bean (controller)
@@ -112,17 +112,8 @@ public class JobsAddressbookWebSessionBean extends BaseJobsController implements
         * Default constructor
         */
        public JobsAddressbookWebSessionBean () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.addressbookBean = (AddressbookSessionBeanRemote) context.lookup("java:global/jjobs-ejb/jjobs-adr!org.mxchange.jjobs.model.addressbook.JobsAddressbookSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
+               // Call super constructor
+               super();
        }
 
        @Override
@@ -315,6 +306,18 @@ public class JobsAddressbookWebSessionBean extends BaseJobsController implements
         */
        @PostConstruct
        public void init () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.addressbookBean = (AddressbookSessionBeanRemote) context.lookup("java:global/jjobs-ejb/jjobs-adr!org.mxchange.jjobs.model.addressbook.JobsAddressbookSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+
                // Init list
                this.usersAddressbooks = new LinkedList<>();
 
@@ -424,4 +427,5 @@ public class JobsAddressbookWebSessionBean extends BaseJobsController implements
                // Fill list with entries
                this.usersAddressbooks = this.addressbookBean.getUsersAddressbookList(user);
        }
+
 }
index 6ed77d52e4c127823860377099ca62a18768ba07..cdabd7804e25fe978315c61d3aceb6c1df27725b 100644 (file)
@@ -89,6 +89,8 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple
         * Default constructor
         */
        public JobsConfirmationLinkWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 9ffc2b85cff8ad21dbb7d91c3c8b198a0cea5d46..86afccbe92a012ad73e5241311f4209795777171 100644 (file)
@@ -254,6 +254,8 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
         * Default constructor
         */
        public JobsAdminContactWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index ccde6746d0b39d0c12c6843344238ce38669611e..abbaea24e8e3df9ea91985620b734fc7f96890e7 100644 (file)
@@ -42,7 +42,7 @@ import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContac
 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
 import org.mxchange.jcountry.data.Country;
 import org.mxchange.jjobs.beans.BaseJobsController;
-import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
+import org.mxchange.jjobs.beans.login.user.JobsUserLoginWebSessionController;
 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
@@ -234,6 +234,9 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job
         * Default constructor
         */
        public JobsContactWebSessionBean () {
+               // Call super constructor
+               super();
+
                // Init lists/maps
                this.contactList = new LinkedList<>();
                this.emailAddressList = new LinkedList<>();
index d0a8d1903f8024935d1009f8a7ccc8646b3a450f..8e82d443ccc24975c1dbfe9cdf093b70ad132e98 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jjobs.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 JobsAdminContactPhoneWebRequestBean extends BaseJobsController impl
         * Default constructor
         */
        public JobsAdminContactPhoneWebRequestBean () {
+               // 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/jjobs-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
        }
 
        /**
@@ -414,6 +406,24 @@ public class JobsAdminContactPhoneWebRequestBean extends BaseJobsController impl
                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/jjobs-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 ee524e2b889999abc5610cc94c9dcbe3d0f28fe3..8390f8c4b8875e177c07661b252b0ad4c669b36e 100644 (file)
@@ -78,6 +78,9 @@ public class JobsContactPhoneWebSessionBean extends BaseJobsController implement
         * Default constructor
         */
        public JobsContactPhoneWebSessionBean () {
+               // Call super constructor
+               super();
+
                // Init lists/maps
                this.contacts = new HashMap<>(10);
        }
index af393e61524e3d3a9c44c7a5f54bdcd53ee44efb..3d6314a809f8ccdd596742b5fd68e0d3f786c02d 100644 (file)
@@ -103,6 +103,8 @@ public class JobsAdminCountryWebRequestBean extends BaseJobsController implement
         * Default constructor
         */
        public JobsAdminCountryWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 7fd86a2b9369ed8f180477b2f2836ecaf2f0e539..b7ae7e401364849d2f6ad0dfe297e60e44a987d5 100644 (file)
@@ -59,6 +59,8 @@ public class JobsCountryWebApplicationBean extends BaseJobsController implements
         * Default constructor
         */
        public JobsCountryWebApplicationBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index 41f1520b144b4c13b7c69fc11233be720ddae42f..cca1199a11ca461ce7f10a285da363b3eeaf1afd 100644 (file)
@@ -31,7 +31,7 @@ import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcoreee.utils.FacesUtils;
 import org.mxchange.jjobs.beans.BaseJobsController;
 import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
-import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
+import org.mxchange.jjobs.beans.login.user.JobsUserLoginWebSessionController;
 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
 import org.mxchange.jusercore.model.email_address.EmailAddressChange;
@@ -88,6 +88,8 @@ public class JobsEmailChangeWebSessionBean extends BaseJobsController implements
         * Default constructor
         */
        public JobsEmailChangeWebSessionBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index ab2e88ab239280937f1fc0258412706744aa6cd5..d0bc78b38bc601b2861a10fce8ed08291ed23dc1 100644 (file)
@@ -39,6 +39,8 @@ public class JobsFeatureWebApplicationBean extends BaseJobsController implements
         * Default constructor
         */
        public JobsFeatureWebApplicationBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index 0b254a28644dea3ccd8ad42c65748a7f5f8cf554..58fe20cb16eef36266339ef3f2bf581983282b8a 100644 (file)
@@ -42,6 +42,8 @@ public class JobsGenderWebApplicationBean extends BaseJobsController implements
         * Default constructor
         */
        public JobsGenderWebApplicationBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index 4079e115e9d8fcfece7b4e5284ffceabb11d4c17..f6b7b1e3b81614c2ba6d9398a4a966b64b30bd23 100644 (file)
@@ -103,6 +103,9 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs
         * Default constructor
         */
        public JobsWebRequestHelperBean () {
+               // 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 57b1d0479f0fef7cee46fb076903b06defadd62a..9b35a04cfade1324de1d84fc85693f181f8f3013 100644 (file)
@@ -53,6 +53,8 @@ public class JobsLocalizationSessionBean extends BaseJobsController implements J
         * Default constructor
         */
        public JobsLocalizationSessionBean () {
+               // Call super constructor
+               super();
        }
 
        /**
diff --git a/src/java/org/mxchange/jjobs/beans/login/JobsUserLoginWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/login/JobsUserLoginWebSessionBean.java
deleted file mode 100644 (file)
index 6f11c04..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.jjobs.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.jjobs.beans.BaseJobsController;
-import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
-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;
-
-/**
- * A web bean for user registration
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("userLoginController")
-@SessionScoped
-public class JobsUserLoginWebSessionBean extends BaseJobsController implements JobsUserLoginWebSessionController {
-
-       /**
-        * 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 JobsUserWebSessionController 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 JobsUserLoginWebSessionBean () {
-               // 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/jjobs-ejb/login!org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote"); //NOI18N
-
-                       // Also find this
-                       this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/jjobs-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/jjobs/beans/login/JobsUserLoginWebSessionController.java b/src/java/org/mxchange/jjobs/beans/login/JobsUserLoginWebSessionController.java
deleted file mode 100644 (file)
index 467c505..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.jjobs.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 JobsUserLoginWebSessionController 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/jjobs/beans/login/user/JobsUserLoginWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/login/user/JobsUserLoginWebSessionBean.java
new file mode 100644 (file)
index 0000000..a3cb9d9
--- /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.jjobs.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.jjobs.beans.BaseJobsController;
+import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
+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;
+
+/**
+ * A web bean for user registration
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("userLoginController")
+@SessionScoped
+public class JobsUserLoginWebSessionBean extends BaseJobsController implements JobsUserLoginWebSessionController {
+
+       /**
+        * 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 JobsUserWebSessionController 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 JobsUserLoginWebSessionBean () {
+               // 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/jjobs-ejb/login!org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote"); //NOI18N
+
+                       // Also find this
+                       this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/jjobs-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/jjobs/beans/login/user/JobsUserLoginWebSessionController.java b/src/java/org/mxchange/jjobs/beans/login/user/JobsUserLoginWebSessionController.java
new file mode 100644 (file)
index 0000000..bd61933
--- /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.jjobs.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 JobsUserLoginWebSessionController 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 bc7c8c4726e07b80f733cc0ef0954b705a36ca65..90184036903e628134e81b2891c5a6b51dfd8637 100644 (file)
@@ -94,6 +94,8 @@ public class JobsAdminMobileProviderWebRequestBean extends BaseJobsController im
         * Default constructor
         */
        public JobsAdminMobileProviderWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index e47377ce70ac2c0d841c67e7e020bec21bcf4dab..f161c5cdec0707cc73ee9f4086c42d5d82163af9 100644 (file)
@@ -59,6 +59,8 @@ public class JobsMobileProviderWebRequestBean extends BaseJobsController impleme
         * Default constructor
         */
        public JobsMobileProviderWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index 387eb8a0c309c5602bcf01a9c61e68aa5ba18348..965627045dcde243f21c0670a64865bcc92ac694 100644 (file)
@@ -196,6 +196,9 @@ public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements
         * Default constructor
         */
        public JobsAdminPhoneWebRequestBean () {
+               // 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 7c43385594f1b9579b1c70f3121b6bdd08bc5452..3d14b2894382c5df1e74f4658f3830f12667d759 100644 (file)
@@ -85,17 +85,8 @@ public class JobsPhoneWebApplicationBean extends BaseJobsController implements J
         * Default constructor
         */
        public JobsPhoneWebApplicationBean () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the beans
-                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jjobs-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 JobsPhoneWebApplicationBean extends BaseJobsController implements J
         */
        @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/jjobs-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 34bb6c51f432685e69ee592ec01551bb0cefabc2..5d4ffe7678f10984197daa3c1cad48973b57c39d 100644 (file)
@@ -23,7 +23,7 @@ import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
 import org.mxchange.jjobs.beans.BaseJobsController;
-import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
+import org.mxchange.jjobs.beans.login.user.JobsUserLoginWebSessionController;
 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.model.user.User;
@@ -59,6 +59,8 @@ public class JobsUserProfileWebRequestBean extends BaseJobsController implements
         * Default constructor
         */
        public JobsUserProfileWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index 524699bdeb1b7e167887a67ae325f1ecf25175cf..1bbc7df18584cae5a52ebe4321c87323042d5aff 100644 (file)
@@ -40,6 +40,8 @@ public class JobsProfileModeWebApplicationBean extends BaseJobsController implem
         * Default constructor
         */
        public JobsProfileModeWebApplicationBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index f99ba705a665f35bbd1b146be34fe9eb8ae84f64..cfd96b369f91ac553e929f3ab047b9e4a85d0ca0 100644 (file)
@@ -83,22 +83,24 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement
        private UserRegistrationSessionBeanRemote registerBean;
 
        /**
-        * An en event fireable when a new user has registered
+        * User controller
         */
        @Inject
-       @Any
-       private Event<ObservableUserRegisteredEvent> registeredEvent;
+       private JobsUserWebSessionController userController;
 
        /**
-        * User controller
+        * An en event fireable when a new user has registered
         */
        @Inject
-       private JobsUserWebSessionController userController;
+       @Any
+       private Event<ObservableUserRegisteredEvent> userRegisteredEvent;
 
        /**
         * Default constructor
         */
        public JobsUserRegisterWebSessionBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
@@ -191,7 +193,7 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement
                        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 "user_register_done"; //NOI18N
index ed028b378550143bfc963c9cf19541766ec087e5..3183074474e845304a50493c5c7334fa5076b4a2 100644 (file)
@@ -58,17 +58,17 @@ public class JobsResendLinkWebSessionBean extends BaseJobsController implements
         */
        private String emailAddress;
 
-       /**
-        * EJB for resending confirmation link
-        */
-       private ResendLinkSessionBeanRemote resendLinkBean;
-
        /**
         * Localization controller
         */
        @Inject
        private JobsLocalizationSessionController localizationController;
 
+       /**
+        * EJB for resending confirmation link
+        */
+       private ResendLinkSessionBeanRemote resendLinkBean;
+
        /**
         * Regular user controller
         */
@@ -86,6 +86,8 @@ public class JobsResendLinkWebSessionBean extends BaseJobsController implements
         * Default constructor
         */
        public JobsResendLinkWebSessionBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index a8f992fbbd71c7a58f49f473656906b1fca7b642..41840a099281cd71d9588b2702c0d7bc2d9ae93c 100644 (file)
@@ -197,6 +197,8 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
         * Default constructor
         */
        public JobsAdminUserWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override
index e9817e6c24473b667be7ebcb6e2c03478c52ea11..bcdb7a9891658c97ff3194d742988c8d73e33bcb 100644 (file)
@@ -36,7 +36,7 @@ import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jjobs.beans.BaseJobsController;
 import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
 import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
-import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
+import org.mxchange.jjobs.beans.login.user.JobsUserLoginWebSessionController;
 import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
 import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
@@ -149,6 +149,8 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
         * Default constructor
         */
        public JobsUserWebSessionBean () {
+               // Call super constructor
+               super();
        }
 
        /**
index 7aeadf35efc2e6eb7d00980df76d6bc1c09b935d..80bc5a97438e41cb9f6009d0841963166849fe35 100644 (file)
@@ -30,7 +30,7 @@ import javax.naming.NamingException;
 import org.mxchange.jcoreee.utils.FacesUtils;
 import org.mxchange.jjobs.beans.BaseJobsController;
 import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
-import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
+import org.mxchange.jjobs.beans.login.user.JobsUserLoginWebSessionController;
 import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
@@ -99,6 +99,8 @@ public class JobsUserPasswordWebRequestBean extends BaseJobsController implement
         * Default constructor
         */
        public JobsUserPasswordWebRequestBean () {
+               // Call super constructor
+               super();
        }
 
        @Override