2 * Copyright (C) 2016 Cho-Time GmbH
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.
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.
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/>.
17 package org.mxchange.jusercore.model.user.password_history;
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;
38 * A POJO for user password history
40 * @author Roland Haeder<rhaeder@cho-time.de>
42 @Entity (name = "user_password_history")
44 name = "user_password_history"
46 @SuppressWarnings ("PersistenceUnitPresent")
47 public class UserPasswordHistory implements PasswordHistory {
53 private static final long serialVersionUID = 1L;
56 * Timestamp when this entry has been created
58 @Basic (optional = false)
59 @Column (name = "history_created", nullable = false, updatable = false)
60 @Temporal (TemporalType.TIMESTAMP)
61 private Calendar userPasswordHistoryCreated;
64 * Id number (primary key)
67 @Column (name = "history_id", updatable = false)
68 @GeneratedValue (strategy = GenerationType.IDENTITY)
69 private Long userPasswordHistoryId;
72 * Password hash being used
74 @Basic (optional = false)
75 @Column (name = "history_password_hash", nullable = false, updatable = false)
76 private String userPasswordHistoryPasswordHash;
79 * User instance for this history entry
81 @JoinColumn (name = "history_user_id", nullable = true, updatable = false)
82 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
83 private User userPasswordHistoryUser;
88 public UserPasswordHistory () {
92 * Constructor with password hash and user instance
94 * @param userPasswordHistoryPasswordHash Password hash
95 * @param userPasswordHistoryUser User instance
97 public UserPasswordHistory (final String userPasswordHistoryPasswordHash, final User userPasswordHistoryUser) {
99 this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash;
100 this.userPasswordHistoryUser = userPasswordHistoryUser;
104 public boolean equals (final Object object) {
105 if (this == object) {
107 } else if (object == null) {
109 } else if (this.getClass() != object.getClass()) {
113 final PasswordHistory other = (PasswordHistory) object;
115 if (!Objects.equals(this.getUserPasswordHistoryPasswordHash(), other.getUserPasswordHistoryPasswordHash())) {
117 } else if (!Objects.equals(this.getUserPasswordHistoryId(), other.getUserPasswordHistoryId())) {
119 } else if (!Objects.equals(this.getUserPasswordHistoryUser(), other.getUserPasswordHistoryUser())) {
127 @SuppressWarnings ("ReturnOfDateField")
128 public Calendar getUserPasswordHistoryCreated () {
129 return this.userPasswordHistoryCreated;
133 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
134 public void setUserPasswordHistoryCreated (final Calendar userPasswordHistoryCreated) {
135 this.userPasswordHistoryCreated = userPasswordHistoryCreated;
139 public Long getUserPasswordHistoryId () {
140 return this.userPasswordHistoryId;
144 public void setUserPasswordHistoryId (final Long userPasswordHistoryId) {
145 this.userPasswordHistoryId = userPasswordHistoryId;
149 public String getUserPasswordHistoryPasswordHash () {
150 return this.userPasswordHistoryPasswordHash;
154 public void setUserPasswordHistoryPasswordHash (final String userPasswordHistoryPasswordHash) {
155 this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash;
159 public User getUserPasswordHistoryUser () {
160 return this.userPasswordHistoryUser;
164 public void setUserPasswordHistoryUser (final User userPasswordHistoryUser) {
165 this.userPasswordHistoryUser = userPasswordHistoryUser;
169 public int hashCode () {
172 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryId());
173 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryPasswordHash());
174 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryUser());