forked from semaphoreci-demos/semaphore-demo-java-spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.java
161 lines (130 loc) · 3.67 KB
/
User.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.example.springpipelinedemo.model;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
/**
* Created by Rimantas Jacikevičius on 19.2.12.
*/
@Table(name = "users")
@EntityListeners({AuditingEntityListener.class})
@Entity
public class User implements UserDetails {
public User() {
}
public User(String email, String password) {
this.email = email;
this.password = password;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(unique = true)
private String email;
private String password;
@CreatedDate
private Date createdDate;
@LastModifiedDate
private Date modifiedDate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
//<editor-fold defaultstate="collapsed" desc="UserDetails heritage"
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
// TODO
return new ArrayList<>();
}
@Override
public String getUsername() {
return email;
}
@Override
public boolean isAccountNonExpired() {
// TODO
return true;
}
@Override
public boolean isAccountNonLocked() {
// TODO
return true;
}
@Override
public boolean isCredentialsNonExpired() {
// TODO
return true;
}
@Override
public boolean isEnabled() {
// TODO
return true;
}
// </editor-fold>
public void setPassword(String password) {
this.password = password;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Date getModifiedDate() {
return modifiedDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return new EqualsBuilder()
.append(createdDate, user.createdDate)
.append(modifiedDate, user.modifiedDate)
.append(id, user.id)
.append(email, user.email)
.append(password, user.password)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(id)
.append(email)
.append(password)
.append(createdDate)
.append(modifiedDate)
.toHashCode();
}
@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", email='" + email + '\'' +
", password='" + password + '\'' +
", createdDate=" + createdDate +
", modifiedDate=" + modifiedDate +
'}';
}
}