]> git.mxchange.org Git - juser-login-core.git/blob - src/org/mxchange/juserlogincore/events/user/password_change/UpdatedUserPasswordEvent.java
cac13266b54d2d97110a266a60725ea7b02603ca
[juser-login-core.git] / src / org / mxchange / juserlogincore / events / user / password_change / UpdatedUserPasswordEvent.java
1 /*
2  * Copyright (C) 2016, 2017 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.juserlogincore.events.user.password_change;
18
19 import java.text.MessageFormat;
20 import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
21
22 /**
23  * An event being fired when the user has updated personal data
24  * <p>
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class UpdatedUserPasswordEvent implements ObservableUpdatedUserPasswordEvent {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 14_785_787_174_676_290L;
33
34         /**
35          * Updated user instance
36          */
37         private final PasswordHistory passwordHistory;
38
39         /**
40          * User password
41          */
42         private final String userPassword;
43
44         /**
45          * Constructor with updated user instance
46          * <p>
47          * @param passwordHistory Updated user instance
48          * @param userPassword Clear-text user password
49          */
50         public UpdatedUserPasswordEvent (final PasswordHistory passwordHistory, final String userPassword) {
51                 // Is the user instance valid?
52                 if (null == passwordHistory) {
53                         // Throw NPE
54                         throw new NullPointerException("passwordHistory is null"); //NOI18N
55                 } else if (passwordHistory.getUserPasswordHistoryUser() == null) {
56                         // Throw NPE again
57                         throw new NullPointerException("passwordHistory.userPasswordHistoryUser is null"); //NOI18N
58                 } else if (passwordHistory.getUserPasswordHistoryUser().getUserId() == null) {
59                         // Throw NPE again
60                         throw new NullPointerException("passwordHistory.userPasswordHistoryUser.userId is null"); //NOI18N
61                 } else if (passwordHistory.getUserPasswordHistoryUser().getUserId() < 1) {
62                         // Invalid id number
63                         throw new IllegalArgumentException(MessageFormat.format("passwordHistory.userPasswordHistoryUser.userId={0} is invalid.", passwordHistory.getUserPasswordHistoryUser().getUserId())); //NOI18N
64                 } else if (null == userPassword) {
65                         // Throw NPE here
66                         throw new NullPointerException("userPassword is null");
67                 } else if (userPassword.isEmpty()) {
68                         // Throw NPE here
69                         throw new IllegalArgumentException("userPassword is empty");
70                 }
71
72                 // Set both here
73                 this.passwordHistory = passwordHistory;
74                 this.userPassword = userPassword;
75         }
76
77         @Override
78         public PasswordHistory getPasswordHistory () {
79                 return this.passwordHistory;
80         }
81
82         @Override
83         public String getUserPassword () {
84                 return this.userPassword;
85         }
86
87 }