]> git.mxchange.org Git - juser-login-core.git/blob - src/org/mxchange/jusercore/model/user/password_history/UserPasswordHistory.java
a2e714b16e674261a900992badb38317000e61cd
[juser-login-core.git] / src / org / mxchange / jusercore / model / user / password_history / UserPasswordHistory.java
1 /*
2  * Copyright (C) 2016 Cho-Time GmbH
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.jusercore.model.user.password_history;
18
19 import java.util.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.OneToOne;
30 import javax.persistence.Table;
31 import javax.persistence.Temporal;
32 import javax.persistence.TemporalType;
33 import javax.persistence.Transient;
34 import org.mxchange.jusercore.model.user.LoginUser;
35 import org.mxchange.jusercore.model.user.User;
36
37 /**
38  * A POJO for user password history
39  * <p>
40  * @author Roland Haeder<rhaeder@cho-time.de>
41  */
42 @Entity (name = "user_password_history")
43 @Table (
44                 name = "user_password_history"
45 )
46 @SuppressWarnings ("PersistenceUnitPresent")
47 public class UserPasswordHistory implements PasswordHistory {
48
49         /**
50          * Serial number
51          */
52         @Transient
53         private static final long serialVersionUID = 1L;
54
55         /**
56          * Timestamp when this entry has been created
57          */
58         @Basic (optional = false)
59         @Column (name = "history_created", nullable = false, updatable = false)
60         @Temporal (TemporalType.TIMESTAMP)
61         private Calendar userPasswordHistoryCreated;
62
63         /**
64          * Id number (primary key)
65          */
66         @Id
67         @Column (name = "history_id", updatable = false)
68         @GeneratedValue (strategy = GenerationType.IDENTITY)
69         private Long userPasswordHistoryId;
70
71         /**
72          * Password hash being used
73          */
74         @Basic (optional = false)
75         @Column (name = "history_password_hash", nullable = false, updatable = false)
76         private String userPasswordHistoryPasswordHash;
77
78         /**
79          * User instance for this history entry
80          */
81         @JoinColumn (name = "history_user_id", nullable = true, updatable = false)
82         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
83         private User userPasswordHistoryUser;
84
85         /**
86          * Default constructor
87          */
88         public UserPasswordHistory () {
89         }
90
91         /**
92          * Constructor with password hash and user instance
93          * <p>
94          * @param userPasswordHistoryPasswordHash Password hash
95          * @param userPasswordHistoryUser User instance
96          */
97         public UserPasswordHistory (final String userPasswordHistoryPasswordHash, final User userPasswordHistoryUser) {
98                 // Set all
99                 this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash;
100                 this.userPasswordHistoryUser = userPasswordHistoryUser;
101         }
102
103         @Override
104         public boolean equals (final Object object) {
105                 if (this == object) {
106                         return true;
107                 } else if (object == null) {
108                         return false;
109                 } else if (this.getClass() != object.getClass()) {
110                         return false;
111                 }
112
113                 final PasswordHistory other = (PasswordHistory) object;
114
115                 if (!Objects.equals(this.getUserPasswordHistoryPasswordHash(), other.getUserPasswordHistoryPasswordHash())) {
116                         return false;
117                 } else if (!Objects.equals(this.getUserPasswordHistoryId(), other.getUserPasswordHistoryId())) {
118                         return false;
119                 } else if (!Objects.equals(this.getUserPasswordHistoryUser(), other.getUserPasswordHistoryUser())) {
120                         return false;
121                 }
122
123                 return true;
124         }
125
126         @Override
127         @SuppressWarnings ("ReturnOfDateField")
128         public Calendar getUserPasswordHistoryCreated () {
129                 return this.userPasswordHistoryCreated;
130         }
131
132         @Override
133         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
134         public void setUserPasswordHistoryCreated (final Calendar userPasswordHistoryCreated) {
135                 this.userPasswordHistoryCreated = userPasswordHistoryCreated;
136         }
137
138         @Override
139         public Long getUserPasswordHistoryId () {
140                 return this.userPasswordHistoryId;
141         }
142
143         @Override
144         public void setUserPasswordHistoryId (final Long userPasswordHistoryId) {
145                 this.userPasswordHistoryId = userPasswordHistoryId;
146         }
147
148         @Override
149         public String getUserPasswordHistoryPasswordHash () {
150                 return this.userPasswordHistoryPasswordHash;
151         }
152
153         @Override
154         public void setUserPasswordHistoryPasswordHash (final String userPasswordHistoryPasswordHash) {
155                 this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash;
156         }
157
158         @Override
159         public User getUserPasswordHistoryUser () {
160                 return this.userPasswordHistoryUser;
161         }
162
163         @Override
164         public void setUserPasswordHistoryUser (final User userPasswordHistoryUser) {
165                 this.userPasswordHistoryUser = userPasswordHistoryUser;
166         }
167
168         @Override
169         public int hashCode () {
170                 int hash = 7;
171
172                 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryId());
173                 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryPasswordHash());
174                 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryUser());
175
176                 return hash;
177         }
178
179 }