123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package sample.data;
- import java.io.Serializable;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import org.hibernate.validator.constraints.Email;
- import org.hibernate.validator.constraints.NotEmpty;
- import org.springframework.security.crypto.password.PasswordEncoder;
- /**
- * Represents a user in our system.
- *
- * <p>
- * In a real system use {@link PasswordEncoder} to ensure the password is secured
- * properly. This demonstration does not address this due to time restrictions.
- * </p>
- *
- * @author Rob Winch
- */
- @Entity
- public class User implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
- @NotEmpty(message = "First name is required.")
- private String firstName;
- @NotEmpty(message = "Last name is required.")
- private String lastName;
- @Email(message = "Please provide a valid email address.")
- @NotEmpty(message = "Email is required.")
- @Column(unique=true, nullable = false)
- private String email;
- @NotEmpty(message = "Password is required.")
- private String password;
- public User() {}
- public User(User user) {
- this.id = user.id;
- this.firstName = user.firstName;
- this.lastName = user.lastName;
- this.email = user.email;
- this.password = user.password;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public String getFirstName() {
- return firstName;
- }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- User other = (User) obj;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- return true;
- }
- private static final long serialVersionUID = 2738859149330833739L;
- }
|