1 | package com.tourMate.entities;
|
---|
2 |
|
---|
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
|
---|
4 | import jakarta.persistence.*;
|
---|
5 | import org.jetbrains.annotations.NotNull;
|
---|
6 | import org.springframework.security.core.GrantedAuthority;
|
---|
7 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
---|
8 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
9 | //import org.springframework.security.core.GrantedAuthority;
|
---|
10 | //import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
---|
11 | //import org.springframework.security.core.userdetails.UserDetails;
|
---|
12 |
|
---|
13 | import java.util.Collection;
|
---|
14 | import java.util.Collections;
|
---|
15 | import java.util.Date;
|
---|
16 |
|
---|
17 | @Entity
|
---|
18 | @Table(name = "users", schema = "public")
|
---|
19 | public class User implements UserDetails {
|
---|
20 | @Id
|
---|
21 | @GeneratedValue(strategy = GenerationType.IDENTITY)
|
---|
22 | @Column(name = "user_id", unique = true, nullable = false)
|
---|
23 | private long userID;
|
---|
24 |
|
---|
25 | @Column(name = "name", unique = false, nullable = false)
|
---|
26 | @NotNull
|
---|
27 | private String name;
|
---|
28 |
|
---|
29 | @Column(name = "surname", unique = false, nullable = false)
|
---|
30 | private String surname;
|
---|
31 |
|
---|
32 | @Column(name = "email", unique = true, nullable = false)
|
---|
33 | @NotNull
|
---|
34 | private String email;
|
---|
35 |
|
---|
36 | @Column(name = "password", unique = true, nullable = false)
|
---|
37 | @NotNull
|
---|
38 | private String password;
|
---|
39 |
|
---|
40 | @Column(name = "birth_date", unique = false, nullable = false)
|
---|
41 | @NotNull
|
---|
42 | private Date birthDate;
|
---|
43 |
|
---|
44 | @Column(name = "address", unique = false, nullable = false)
|
---|
45 | private String address;
|
---|
46 |
|
---|
47 | @Column(name = "contact", unique = false, nullable = false)
|
---|
48 | private String contact;
|
---|
49 |
|
---|
50 | @ManyToOne(fetch = FetchType.EAGER)
|
---|
51 | @JoinColumn(name = "role_id", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_ref_od_user_kon_role"))
|
---|
52 | private Role role;
|
---|
53 | @Column(name = "locked", unique = false, nullable = false)
|
---|
54 | boolean locked = false;
|
---|
55 |
|
---|
56 | @Column(name = "enabled", unique = false, nullable = false)
|
---|
57 | boolean enabled;
|
---|
58 |
|
---|
59 |
|
---|
60 | public User(@NotNull String name, String surname, @NotNull String email, @NotNull String password, @NotNull Date birthDate, String address, String contact, Role role) {
|
---|
61 | this.name = name;
|
---|
62 | this.surname = surname;
|
---|
63 | this.email = email;
|
---|
64 | this.password = password;
|
---|
65 | this.birthDate = birthDate;
|
---|
66 | this.address = address;
|
---|
67 | this.contact = contact;
|
---|
68 | this.role = role;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public User(@NotNull String name, String surname, @NotNull String email, @NotNull String password, @NotNull Date birthDate, String address, String contact) {
|
---|
72 | this.name = name;
|
---|
73 | this.surname = surname;
|
---|
74 | this.email = email;
|
---|
75 | this.password = password;
|
---|
76 | this.birthDate = birthDate;
|
---|
77 | this.address = address;
|
---|
78 | this.contact = contact;
|
---|
79 | }
|
---|
80 |
|
---|
81 | public User(long userID, @NotNull String name, String surname, @NotNull String email, @NotNull String password, @NotNull Date birthDate, String address, String contact, Role role, boolean locked, boolean enabled) {
|
---|
82 | this.userID = userID;
|
---|
83 | this.name = name;
|
---|
84 | this.surname = surname;
|
---|
85 | this.email = email;
|
---|
86 | this.password = password;
|
---|
87 | this.birthDate = birthDate;
|
---|
88 | this.address = address;
|
---|
89 | this.contact = contact;
|
---|
90 | this.role = role;
|
---|
91 | this.locked = locked;
|
---|
92 | this.enabled = enabled;
|
---|
93 | }
|
---|
94 |
|
---|
95 | public User() {
|
---|
96 | }
|
---|
97 |
|
---|
98 | public boolean isLocked() {
|
---|
99 | return locked;
|
---|
100 | }
|
---|
101 |
|
---|
102 | public long getUserID() {
|
---|
103 | return userID;
|
---|
104 | }
|
---|
105 |
|
---|
106 | public void setUserID(long userID) {
|
---|
107 | this.userID = userID;
|
---|
108 | }
|
---|
109 |
|
---|
110 | public String getName() {
|
---|
111 | return name;
|
---|
112 | }
|
---|
113 |
|
---|
114 | public void setName(String name) {
|
---|
115 | this.name = name;
|
---|
116 | }
|
---|
117 |
|
---|
118 | public String getSurname() {
|
---|
119 | return surname;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | public void setSurname(String surname) {
|
---|
124 | this.surname = surname;
|
---|
125 | }
|
---|
126 |
|
---|
127 | public String getEmail() {
|
---|
128 | return email;
|
---|
129 | }
|
---|
130 |
|
---|
131 | public void setEmail(String email) {
|
---|
132 | this.email = email;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | public Role getRole() {
|
---|
137 | return role;
|
---|
138 | }
|
---|
139 |
|
---|
140 | public boolean isEnabled() {
|
---|
141 | return enabled;
|
---|
142 | }
|
---|
143 |
|
---|
144 | @Override
|
---|
145 | @JsonIgnore
|
---|
146 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
147 | SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.getRoleName());
|
---|
148 | return Collections.singleton(authority);
|
---|
149 | }
|
---|
150 |
|
---|
151 | public String getPassword() {
|
---|
152 | return password;
|
---|
153 | }
|
---|
154 |
|
---|
155 | @Override
|
---|
156 | public String getUsername() {
|
---|
157 | return email;
|
---|
158 | }
|
---|
159 |
|
---|
160 | @Override
|
---|
161 | public boolean isAccountNonExpired() {
|
---|
162 | return true;
|
---|
163 | }
|
---|
164 |
|
---|
165 | @Override
|
---|
166 | public boolean isAccountNonLocked() {
|
---|
167 | return locked;
|
---|
168 | }
|
---|
169 |
|
---|
170 | @Override
|
---|
171 | public boolean isCredentialsNonExpired() {
|
---|
172 | return true;
|
---|
173 | }
|
---|
174 |
|
---|
175 | public void setPassword(String password) {
|
---|
176 | this.password = password;
|
---|
177 | }
|
---|
178 |
|
---|
179 | public Date getBirthDate() {
|
---|
180 | return birthDate;
|
---|
181 | }
|
---|
182 |
|
---|
183 | public void setBirthDate(Date birthDate) {
|
---|
184 | this.birthDate = birthDate;
|
---|
185 | }
|
---|
186 |
|
---|
187 | public String getAddress() {
|
---|
188 | return address;
|
---|
189 | }
|
---|
190 |
|
---|
191 | public void setAddress(String address) {
|
---|
192 | this.address = address;
|
---|
193 | }
|
---|
194 |
|
---|
195 | public String getContact() {
|
---|
196 | return contact;
|
---|
197 | }
|
---|
198 |
|
---|
199 | public void setContact(String contact) {
|
---|
200 | this.contact = contact;
|
---|
201 | }
|
---|
202 |
|
---|
203 | public void setRole(Role role) {
|
---|
204 | this.role = role;
|
---|
205 | }
|
---|
206 |
|
---|
207 | public void setLocked(boolean locked) {
|
---|
208 | this.locked = locked;
|
---|
209 | }
|
---|
210 |
|
---|
211 | public void setEnabled(boolean enabled) {
|
---|
212 | this.enabled = enabled;
|
---|
213 | }
|
---|
214 | }
|
---|