From 6f8b0e78cbcad8d1dca6d93ddfac4332c6d3fb28 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 2 Aug 2016 17:35:05 +0200 Subject: [PATCH] Continued with user passwords: (please cherry-pick) - added POJO/POJI for history for user's passwords (hashed only) to found a way of telling a user to change not to one of previous passwords - fixed spaces --- .../email_address/EmailAddressChange.java | 30 +-- .../password_history/PasswordHistory.java | 95 ++++++++++ .../password_history/UserPasswordHistory.java | 179 ++++++++++++++++++ 3 files changed, 289 insertions(+), 15 deletions(-) create mode 100644 src/org/mxchange/jusercore/model/user/password_history/PasswordHistory.java create mode 100644 src/org/mxchange/jusercore/model/user/password_history/UserPasswordHistory.java diff --git a/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java b/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java index c55cc94..2d8d738 100644 --- a/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java +++ b/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java @@ -126,13 +126,13 @@ public class EmailAddressChange implements ChangeableEmailAddress { /** * Constructor with all fields to set *

- * @param emailChangeId Email change id - * @param user User instance - * @param emailAddress Email address + * @param emailChangeId Email change id + * @param user User instance + * @param emailAddress Email address * @param emailChangeCreated Timestamp for creation - * @param emailChangeStatus Email change status - * @param emailChangeDone When this entry has been done - * @param emailChangeHash Email change hash + * @param emailChangeStatus Email change status + * @param emailChangeDone When this entry has been done + * @param emailChangeHash Email change hash */ public EmailAddressChange (final Long emailChangeId, final User user, final String emailAddress, final Calendar emailChangeCreated, final EmailChangeStatus emailChangeStatus, final Calendar emailChangeDone, final String emailChangeHash) { // Call other constructor @@ -149,7 +149,7 @@ public class EmailAddressChange implements ChangeableEmailAddress { /** * Constructor with user and email address *

- * @param user User instance + * @param user User instance * @param emailAddress Email address */ public EmailAddressChange (final User user, final String emailAddress) { @@ -180,14 +180,6 @@ public class EmailAddressChange implements ChangeableEmailAddress { return Objects.equals(this.getEmailChangeUser(), otherEmail.getEmailChangeUser()); } - @Override - public int hashCode () { - int hash = 5; - hash = 71 * hash + Objects.hashCode(this.getEmailAddress()); - hash = 71 * hash + Objects.hashCode(this.getEmailChangeUser()); - return hash; - } - @Override public String getEmailAddress () { return this.emailAddress; @@ -262,4 +254,12 @@ public class EmailAddressChange implements ChangeableEmailAddress { this.emailChangeUser = emailChangeUser; } + @Override + public int hashCode () { + int hash = 5; + hash = 71 * hash + Objects.hashCode(this.getEmailAddress()); + hash = 71 * hash + Objects.hashCode(this.getEmailChangeUser()); + return hash; + } + } diff --git a/src/org/mxchange/jusercore/model/user/password_history/PasswordHistory.java b/src/org/mxchange/jusercore/model/user/password_history/PasswordHistory.java new file mode 100644 index 0000000..3fcee12 --- /dev/null +++ b/src/org/mxchange/jusercore/model/user/password_history/PasswordHistory.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jusercore.model.user.password_history; + +import java.io.Serializable; +import java.util.Calendar; +import org.mxchange.jusercore.model.user.User; + +/** + * A POJI for user password history + *

+ * @author Roland Haeder + */ +public interface PasswordHistory extends Serializable { + + /** + * Getter for timestamp this history entry has been created (usually in + * EJB). + *

+ * @return Timestamp when this history entry has been created + */ + Calendar getUserPasswordHistoryCreated (); + + /** + * Setter for timestamp this history entry has been created (usually in + * EJB). + *

+ * @param userPasswordHistoryCreated Timestamp when this history entry has + * been created + */ + void setUserPasswordHistoryCreated (final Calendar userPasswordHistoryCreated); + + /** + * Getter for history entry id (primary key) + *

+ * @return History entry id (primary key) + */ + Long getUserPasswordHistoryId (); + + /** + * Setter for history entry id (primary key) + *

+ * @param userPasswordHistoryId History entry id (primary key) + */ + void setUserPasswordHistoryId (final Long userPasswordHistoryId); + + /** + * Getter for user's password hash + *

+ * @return User's password hash + */ + String getUserPasswordHistoryPasswordHash (); + + /** + * Setter for user's password hash + *

+ * @param userPasswordHistoryPasswordHash User's password hash + */ + void setUserPasswordHistoryPasswordHash (final String userPasswordHistoryPasswordHash); + + /** + * Getter for user instance + *

+ * @return User instance + */ + User getUserPasswordHistoryUser (); + + /** + * Setter for user instance + *

+ * @param userPasswordHistoryUser User instance + */ + void setUserPasswordHistoryUser (final User userPasswordHistoryUser); + + @Override + boolean equals (final Object object); + + @Override + int hashCode (); + +} diff --git a/src/org/mxchange/jusercore/model/user/password_history/UserPasswordHistory.java b/src/org/mxchange/jusercore/model/user/password_history/UserPasswordHistory.java new file mode 100644 index 0000000..a2e714b --- /dev/null +++ b/src/org/mxchange/jusercore/model/user/password_history/UserPasswordHistory.java @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jusercore.model.user.password_history; + +import java.util.Calendar; +import java.util.Objects; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; +import org.mxchange.jusercore.model.user.LoginUser; +import org.mxchange.jusercore.model.user.User; + +/** + * A POJO for user password history + *

+ * @author Roland Haeder + */ +@Entity (name = "user_password_history") +@Table ( + name = "user_password_history" +) +@SuppressWarnings ("PersistenceUnitPresent") +public class UserPasswordHistory implements PasswordHistory { + + /** + * Serial number + */ + @Transient + private static final long serialVersionUID = 1L; + + /** + * Timestamp when this entry has been created + */ + @Basic (optional = false) + @Column (name = "history_created", nullable = false, updatable = false) + @Temporal (TemporalType.TIMESTAMP) + private Calendar userPasswordHistoryCreated; + + /** + * Id number (primary key) + */ + @Id + @Column (name = "history_id", updatable = false) + @GeneratedValue (strategy = GenerationType.IDENTITY) + private Long userPasswordHistoryId; + + /** + * Password hash being used + */ + @Basic (optional = false) + @Column (name = "history_password_hash", nullable = false, updatable = false) + private String userPasswordHistoryPasswordHash; + + /** + * User instance for this history entry + */ + @JoinColumn (name = "history_user_id", nullable = true, updatable = false) + @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH) + private User userPasswordHistoryUser; + + /** + * Default constructor + */ + public UserPasswordHistory () { + } + + /** + * Constructor with password hash and user instance + *

+ * @param userPasswordHistoryPasswordHash Password hash + * @param userPasswordHistoryUser User instance + */ + public UserPasswordHistory (final String userPasswordHistoryPasswordHash, final User userPasswordHistoryUser) { + // Set all + this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash; + this.userPasswordHistoryUser = userPasswordHistoryUser; + } + + @Override + public boolean equals (final Object object) { + if (this == object) { + return true; + } else if (object == null) { + return false; + } else if (this.getClass() != object.getClass()) { + return false; + } + + final PasswordHistory other = (PasswordHistory) object; + + if (!Objects.equals(this.getUserPasswordHistoryPasswordHash(), other.getUserPasswordHistoryPasswordHash())) { + return false; + } else if (!Objects.equals(this.getUserPasswordHistoryId(), other.getUserPasswordHistoryId())) { + return false; + } else if (!Objects.equals(this.getUserPasswordHistoryUser(), other.getUserPasswordHistoryUser())) { + return false; + } + + return true; + } + + @Override + @SuppressWarnings ("ReturnOfDateField") + public Calendar getUserPasswordHistoryCreated () { + return this.userPasswordHistoryCreated; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setUserPasswordHistoryCreated (final Calendar userPasswordHistoryCreated) { + this.userPasswordHistoryCreated = userPasswordHistoryCreated; + } + + @Override + public Long getUserPasswordHistoryId () { + return this.userPasswordHistoryId; + } + + @Override + public void setUserPasswordHistoryId (final Long userPasswordHistoryId) { + this.userPasswordHistoryId = userPasswordHistoryId; + } + + @Override + public String getUserPasswordHistoryPasswordHash () { + return this.userPasswordHistoryPasswordHash; + } + + @Override + public void setUserPasswordHistoryPasswordHash (final String userPasswordHistoryPasswordHash) { + this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash; + } + + @Override + public User getUserPasswordHistoryUser () { + return this.userPasswordHistoryUser; + } + + @Override + public void setUserPasswordHistoryUser (final User userPasswordHistoryUser) { + this.userPasswordHistoryUser = userPasswordHistoryUser; + } + + @Override + public int hashCode () { + int hash = 7; + + hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryId()); + hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryPasswordHash()); + hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryUser()); + + return hash; + } + +} -- 2.39.5