User.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright 2002-2013 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package sample.data;
  17. import java.io.Serializable;
  18. import javax.persistence.Column;
  19. import javax.persistence.Entity;
  20. import javax.persistence.GeneratedValue;
  21. import javax.persistence.GenerationType;
  22. import javax.persistence.Id;
  23. import org.hibernate.validator.constraints.Email;
  24. import org.hibernate.validator.constraints.NotEmpty;
  25. import org.springframework.security.crypto.password.PasswordEncoder;
  26. /**
  27. * Represents a user in our system.
  28. *
  29. * <p>
  30. * In a real system use {@link PasswordEncoder} to ensure the password is secured
  31. * properly. This demonstration does not address this due to time restrictions.
  32. * </p>
  33. *
  34. * @author Rob Winch
  35. */
  36. @Entity
  37. public class User implements Serializable {
  38. @Id
  39. @GeneratedValue(strategy = GenerationType.AUTO)
  40. private Long id;
  41. @NotEmpty(message = "First name is required.")
  42. private String firstName;
  43. @NotEmpty(message = "Last name is required.")
  44. private String lastName;
  45. @Email(message = "Please provide a valid email address.")
  46. @NotEmpty(message = "Email is required.")
  47. @Column(unique=true, nullable = false)
  48. private String email;
  49. @NotEmpty(message = "Password is required.")
  50. private String password;
  51. public User() {}
  52. public User(User user) {
  53. this.id = user.id;
  54. this.firstName = user.firstName;
  55. this.lastName = user.lastName;
  56. this.email = user.email;
  57. this.password = user.password;
  58. }
  59. public String getPassword() {
  60. return password;
  61. }
  62. public void setPassword(String password) {
  63. this.password = password;
  64. }
  65. public Long getId() {
  66. return id;
  67. }
  68. public void setId(Long id) {
  69. this.id = id;
  70. }
  71. public String getFirstName() {
  72. return firstName;
  73. }
  74. public void setFirstName(String firstName) {
  75. this.firstName = firstName;
  76. }
  77. public String getLastName() {
  78. return lastName;
  79. }
  80. public void setLastName(String lastName) {
  81. this.lastName = lastName;
  82. }
  83. public String getEmail() {
  84. return email;
  85. }
  86. public void setEmail(String email) {
  87. this.email = email;
  88. }
  89. @Override
  90. public int hashCode() {
  91. final int prime = 31;
  92. int result = 1;
  93. result = prime * result + ((id == null) ? 0 : id.hashCode());
  94. return result;
  95. }
  96. @Override
  97. public boolean equals(Object obj) {
  98. if (this == obj)
  99. return true;
  100. if (obj == null)
  101. return false;
  102. if (getClass() != obj.getClass())
  103. return false;
  104. User other = (User) obj;
  105. if (id == null) {
  106. if (other.id != null)
  107. return false;
  108. } else if (!id.equals(other.id))
  109. return false;
  110. return true;
  111. }
  112. private static final long serialVersionUID = 2738859149330833739L;
  113. }