[SECARSP-111] +Auth API [SECARSP-115 +Get Devices]
[platform/core/security/suspicious-activity-monitor.git] / server / src / main / java / com / samsung / samserver / domain / User.java
1 /*
2  * In Samsung Ukraine R&D Center (SRK under a contract between)
3  * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
5  */
6 package  com.samsung.samserver.domain;
7
8 import com.fasterxml.jackson.annotation.JsonIgnore;
9 import com.samsung.samserver.config.Constants;
10 import org.apache.commons.lang3.StringUtils;
11 import org.hibernate.annotations.BatchSize;
12 import org.hibernate.validator.constraints.Email;
13
14 import javax.persistence.*;
15 import javax.validation.constraints.NotNull;
16 import javax.validation.constraints.Pattern;
17 import javax.validation.constraints.Size;
18 import java.io.Serializable;
19 import java.util.HashSet;
20 import java.util.Locale;
21 import java.util.Objects;
22 import java.util.Set;
23 import java.time.Instant;
24
25 /**
26  * A user.
27  */
28 @Entity
29 @Table(name = "jhi_user")
30
31 public class User extends AbstractAuditingEntity implements Serializable {
32
33     private static final long serialVersionUID = 1L;
34
35     @Id
36     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
37     @SequenceGenerator(name = "sequenceGenerator")
38     private Long id;
39
40     @NotNull
41     @Pattern(regexp = Constants.LOGIN_REGEX)
42     @Size(min = 1, max = 50)
43     @Column(length = 50, unique = true, nullable = false)
44     private String login;
45
46     @JsonIgnore
47     @NotNull
48     @Size(min = 60, max = 60)
49     @Column(name = "password_hash", length = 60)
50     private String password;
51
52     @Size(max = 50)
53     @Column(name = "first_name", length = 50)
54     private String firstName;
55
56     @Size(max = 50)
57     @Column(name = "last_name", length = 50)
58     private String lastName;
59
60     @Email
61     @Size(min = 5, max = 100)
62     @Column(length = 100, unique = true)
63     private String email;
64
65     @NotNull
66     @Column(nullable = false)
67     private boolean activated = false;
68
69     @Size(min = 2, max = 6)
70     @Column(name = "lang_key", length = 6)
71     private String langKey;
72
73     @Size(max = 256)
74     @Column(name = "image_url", length = 256)
75     private String imageUrl;
76
77     @Size(max = 20)
78     @Column(name = "activation_key", length = 20)
79     @JsonIgnore
80     private String activationKey;
81
82     @Size(max = 20)
83     @Column(name = "reset_key", length = 20)
84     @JsonIgnore
85     private String resetKey;
86
87     @Column(name = "reset_date")
88     private Instant resetDate = null;
89
90     @JsonIgnore
91     @ManyToMany
92     @JoinTable(
93         name = "jhi_user_authority",
94         joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
95         inverseJoinColumns = {@JoinColumn(name = "authority_name", referencedColumnName = "name")})
96
97     @BatchSize(size = 20)
98     private Set<Authority> authorities = new HashSet<>();
99
100     public Long getId() {
101         return id;
102     }
103
104     public void setId(Long id) {
105         this.id = id;
106     }
107
108     public String getLogin() {
109         return login;
110     }
111
112     // Lowercase the login before saving it in database
113     public void setLogin(String login) {
114         this.login = StringUtils.lowerCase(login, Locale.ENGLISH);
115     }
116
117     public String getPassword() {
118         return password;
119     }
120
121     public void setPassword(String password) {
122         this.password = password;
123     }
124
125     public String getFirstName() {
126         return firstName;
127     }
128
129     public void setFirstName(String firstName) {
130         this.firstName = firstName;
131     }
132
133     public String getLastName() {
134         return lastName;
135     }
136
137     public void setLastName(String lastName) {
138         this.lastName = lastName;
139     }
140
141     public String getEmail() {
142         return email;
143     }
144
145     public void setEmail(String email) {
146         this.email = email;
147     }
148
149     public String getImageUrl() {
150         return imageUrl;
151     }
152
153     public void setImageUrl(String imageUrl) {
154         this.imageUrl = imageUrl;
155     }
156
157     public boolean getActivated() {
158         return activated;
159     }
160
161     public void setActivated(boolean activated) {
162         this.activated = activated;
163     }
164
165     public String getActivationKey() {
166         return activationKey;
167     }
168
169     public void setActivationKey(String activationKey) {
170         this.activationKey = activationKey;
171     }
172
173     public String getResetKey() {
174         return resetKey;
175     }
176
177     public void setResetKey(String resetKey) {
178         this.resetKey = resetKey;
179     }
180
181     public Instant getResetDate() {
182         return resetDate;
183     }
184
185     public void setResetDate(Instant resetDate) {
186         this.resetDate = resetDate;
187     }
188
189     public String getLangKey() {
190         return langKey;
191     }
192
193     public void setLangKey(String langKey) {
194         this.langKey = langKey;
195     }
196
197     public Set<Authority> getAuthorities() {
198         return authorities;
199     }
200
201     public void setAuthorities(Set<Authority> authorities) {
202         this.authorities = authorities;
203     }
204
205     @Override
206     public boolean equals(Object o) {
207         if (this == o) {
208             return true;
209         }
210         if (o == null || getClass() != o.getClass()) {
211             return false;
212         }
213
214         User user = (User) o;
215         return !(user.getId() == null || getId() == null) && Objects.equals(getId(), user.getId());
216     }
217
218     @Override
219     public int hashCode() {
220         return Objects.hashCode(getId());
221     }
222
223     @Override
224     public String toString() {
225         return "User{" +
226             "login='" + login + '\'' +
227             ", firstName='" + firstName + '\'' +
228             ", lastName='" + lastName + '\'' +
229             ", email='" + email + '\'' +
230             ", imageUrl='" + imageUrl + '\'' +
231             ", activated='" + activated + '\'' +
232             ", langKey='" + langKey + '\'' +
233             ", activationKey='" + activationKey + '\'' +
234             "}";
235     }
236 }