2023-08-12 02:29:10 +01:00
|
|
|
package stirling.software.SPDF.model;
|
|
|
|
|
2024-08-19 16:02:40 +02:00
|
|
|
import java.io.Serializable;
|
2023-08-27 00:39:22 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Map;
|
2023-08-12 02:29:10 +01:00
|
|
|
import java.util.Set;
|
2023-08-13 01:12:29 +01:00
|
|
|
import java.util.stream.Collectors;
|
2023-08-12 02:29:10 +01:00
|
|
|
|
2024-09-05 22:24:38 +05:30
|
|
|
import jakarta.persistence.*;
|
|
|
|
|
2025-04-25 15:35:12 +02:00
|
|
|
import lombok.EqualsAndHashCode;
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
import lombok.Setter;
|
|
|
|
import lombok.ToString;
|
|
|
|
|
2023-08-12 02:29:10 +01:00
|
|
|
@Entity
|
|
|
|
@Table(name = "users")
|
2025-04-25 15:35:12 +02:00
|
|
|
@NoArgsConstructor
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
|
|
|
@ToString(onlyExplicitlyIncluded = true)
|
2024-08-19 16:02:40 +02:00
|
|
|
public class User implements Serializable {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
2023-08-12 02:29:10 +01:00
|
|
|
|
2023-08-15 00:39:13 +01:00
|
|
|
@Id
|
|
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
|
|
@Column(name = "user_id")
|
|
|
|
private Long id;
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-08-15 00:39:13 +01:00
|
|
|
@Column(name = "username", unique = true)
|
2023-08-12 02:29:10 +01:00
|
|
|
private String username;
|
|
|
|
|
|
|
|
@Column(name = "password")
|
|
|
|
private String password;
|
|
|
|
|
2023-08-13 10:53:00 +01:00
|
|
|
@Column(name = "apiKey")
|
|
|
|
private String apiKey;
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-08-12 02:29:10 +01:00
|
|
|
@Column(name = "enabled")
|
|
|
|
private boolean enabled;
|
|
|
|
|
2023-09-03 16:40:40 +01:00
|
|
|
@Column(name = "isFirstLogin")
|
|
|
|
private Boolean isFirstLogin = false;
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-03-06 23:14:02 +01:00
|
|
|
@Column(name = "roleName")
|
|
|
|
private String roleName;
|
|
|
|
|
2024-05-12 19:58:34 +02:00
|
|
|
@Column(name = "authenticationtype")
|
|
|
|
private String authenticationType;
|
|
|
|
|
2023-08-12 02:29:10 +01:00
|
|
|
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "user")
|
2023-08-13 01:12:29 +01:00
|
|
|
private Set<Authority> authorities = new HashSet<>();
|
|
|
|
|
2024-08-23 23:37:45 +03:00
|
|
|
@ElementCollection
|
2023-08-13 01:12:29 +01:00
|
|
|
@MapKeyColumn(name = "setting_key")
|
2024-06-26 22:48:50 +02:00
|
|
|
@Lob
|
2025-01-06 18:58:26 +00:00
|
|
|
@Column(name = "setting_value", columnDefinition = "text")
|
2023-08-15 00:39:13 +01:00
|
|
|
@CollectionTable(name = "user_settings", joinColumns = @JoinColumn(name = "user_id"))
|
2023-08-13 01:12:29 +01:00
|
|
|
private Map<String, String> settings = new HashMap<>(); // Key-value pairs of settings.
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-03-06 23:14:02 +01:00
|
|
|
public String getRoleName() {
|
|
|
|
return Role.getRoleNameByRoleId(getRolesAsString());
|
|
|
|
}
|
|
|
|
|
2023-09-03 16:40:40 +01:00
|
|
|
public boolean isFirstLogin() {
|
|
|
|
return isFirstLogin != null && isFirstLogin;
|
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-09-03 16:40:40 +01:00
|
|
|
public void setFirstLogin(boolean isFirstLogin) {
|
|
|
|
this.isFirstLogin = isFirstLogin;
|
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-12-24 09:52:53 +00:00
|
|
|
public void setAuthenticationType(AuthenticationType authenticationType) {
|
|
|
|
this.authenticationType = authenticationType.toString().toLowerCase();
|
|
|
|
}
|
|
|
|
|
2023-08-13 01:12:29 +01:00
|
|
|
public void addAuthorities(Set<Authority> authorities) {
|
|
|
|
this.authorities.addAll(authorities);
|
|
|
|
}
|
|
|
|
|
2025-04-25 15:35:12 +02:00
|
|
|
public void addAuthority(Authority authority) {
|
|
|
|
this.authorities.add(authority);
|
2023-12-30 19:11:27 +00:00
|
|
|
}
|
2023-08-12 02:29:10 +01:00
|
|
|
|
2023-08-13 01:12:29 +01:00
|
|
|
public String getRolesAsString() {
|
|
|
|
return this.authorities.stream()
|
|
|
|
.map(Authority::getAuthority)
|
|
|
|
.collect(Collectors.joining(", "));
|
2023-12-30 19:11:27 +00:00
|
|
|
}
|
2024-05-12 19:58:34 +02:00
|
|
|
|
|
|
|
public boolean hasPassword() {
|
2024-05-18 23:47:05 +02:00
|
|
|
return this.password != null && !this.password.isEmpty();
|
2024-05-12 19:58:34 +02:00
|
|
|
}
|
2023-08-12 02:29:10 +01:00
|
|
|
}
|