forked from springboot-angular2-tutorial/boot-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
103 lines (85 loc) · 2.39 KB
/
User.java
File metadata and controls
103 lines (85 loc) · 2.39 KB
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
package com.myapp.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@Entity
@Table(name = "user", uniqueConstraints = @UniqueConstraint(columnNames = {"username"}))
@ToString
public class User implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Getter
@Setter
private Long id;
@NotNull
@Size(min = 4, max = 30)
@Setter
@Pattern(regexp = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$")
private String username;
@NotNull
private String password;
@NotNull
@Size(min = 4, max = 30)
@Getter
@Setter
private String name;
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, orphanRemoval = true)
@JsonIgnore
private List<Micropost> microposts;
@OneToMany(mappedBy = "follower", fetch = FetchType.LAZY, orphanRemoval = true)
@JsonIgnore
private List<Relationship> followerRelations;
@OneToMany(mappedBy = "followed", fetch = FetchType.LAZY, orphanRemoval = true)
@JsonIgnore
private List<Relationship> followedRelations;
@Override
@JsonProperty("email")
public String getUsername() {
return username;
}
@Override
@JsonIgnore
public String getPassword() {
return password;
}
@JsonProperty
public void setPassword(String password) {
this.password = password;
}
@Override
@JsonIgnore
public Collection<? extends GrantedAuthority> getAuthorities() {
return Collections.singleton(() -> "ROLE_USER");
}
@Override
@JsonIgnore
public boolean isAccountNonExpired() {
return true;
}
@Override
@JsonIgnore
public boolean isAccountNonLocked() {
return true;
}
@Override
@JsonIgnore
public boolean isCredentialsNonExpired() {
return true;
}
@Override
@JsonIgnore
public boolean isEnabled() {
return true;
}
}