source: trip-planner/src/main/java/finki/diplomska/tripplanner/models/User.java@ 84d0fbb

Last change on this file since 84d0fbb was 84d0fbb, checked in by Ema <ema_spirova@…>, 3 years ago

spring security 2.0

  • Property mode set to 100644
File size: 2.3 KB
Line 
1package finki.diplomska.tripplanner.models;
2
3import com.fasterxml.jackson.annotation.JsonIgnore;
4import lombok.AllArgsConstructor;
5import lombok.Getter;
6import lombok.Setter;
7import org.springframework.security.core.GrantedAuthority;
8import org.springframework.security.core.userdetails.UserDetails;
9
10import javax.persistence.*;
11import javax.validation.constraints.Email;
12import javax.validation.constraints.NotBlank;
13import java.util.ArrayList;
14import java.util.Collection;
15import java.util.Date;
16import java.util.List;
17
18@Entity
19@Table(name = "users")
20@AllArgsConstructor
21@Getter
22@Setter
23public class User implements UserDetails {
24
25 @Id
26 @GeneratedValue(strategy = GenerationType.IDENTITY)
27 private Long id;
28
29 @Email(message = "Username needs to be an email")
30 @NotBlank(message = "username is required")
31 @Column(unique = true)
32 private String username;
33 @NotBlank(message = "Please enter your full name")
34 private String fullName;
35 @NotBlank(message = "Password field is required")
36 private String password;
37 @Transient
38 private String confirmPassword;
39 private Date create_At;
40 private Date update_At;
41
42 //OneToMany with Planners
43 @OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "user", orphanRemoval = true)
44 @JsonIgnore
45 private List<Planner> planners = new ArrayList<>();
46
47 public User() {
48 }
49
50 public User(String username, String fullName, String password, String confirmPassword) {
51 this.username = username;
52 this.fullName = fullName;
53 this.password = password;
54 this.confirmPassword = confirmPassword;
55 }
56
57 @PrePersist
58 protected void onCreate(){
59 this.create_At = new Date();
60 }
61 @PreUpdate
62 protected void onUpdate(){
63 this.update_At = new Date();
64 }
65
66 @Override
67 @JsonIgnore
68 public Collection<? extends GrantedAuthority> getAuthorities() {
69 return null;
70 }
71
72 @Override
73 @JsonIgnore
74 public boolean isAccountNonExpired() {
75 return true;
76 }
77
78 @Override
79 @JsonIgnore
80 public boolean isAccountNonLocked() {
81 return true;
82 }
83
84 @Override
85 @JsonIgnore
86 public boolean isCredentialsNonExpired() {
87 return true;
88 }
89
90 @Override
91 @JsonIgnore
92 public boolean isEnabled() {
93 return true;
94 }
95}
Note: See TracBrowser for help on using the repository browser.