Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

148 lines
3.5 KiB
Java
Raw Normal View History

2023-08-12 02:29:10 +01:00
package stirling.software.SPDF.model;
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
import jakarta.persistence.*;
2023-08-12 02:29:10 +01:00
@Entity
@Table(name = "users")
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
@Column(name = "roleName")
private String roleName;
@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<>();
@ElementCollection
2023-08-13 01:12:29 +01:00
@MapKeyColumn(name = "setting_key")
@Lob
@Column(name = "setting_value", columnDefinition = "CLOB")
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
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
2023-08-15 00:39:13 +01:00
public Long getId() {
return id;
}
2023-12-30 19:11:27 +00:00
2023-08-15 00:39:13 +01:00
public void setId(Long id) {
this.id = id;
}
2023-12-30 19:11:27 +00:00
2023-08-13 10:53:00 +01:00
public String getApiKey() {
return apiKey;
}
2023-12-30 19:11:27 +00:00
2023-08-13 10:53:00 +01:00
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
2023-12-30 19:11:27 +00:00
2023-08-13 01:12:29 +01:00
public Map<String, String> getSettings() {
return settings;
}
2023-12-30 19:11:27 +00:00
2023-08-13 01:12:29 +01:00
public void setSettings(Map<String, String> settings) {
this.settings = settings;
}
2023-12-30 19:11:27 +00:00
2023-08-12 02:29:10 +01:00
public String getUsername() {
return username;
}
2023-12-30 19:11:27 +00:00
2023-08-12 02:29:10 +01:00
public void setUsername(String username) {
this.username = username;
}
2023-12-30 19:11:27 +00:00
2023-08-12 02:29:10 +01:00
public String getPassword() {
return password;
}
2023-12-30 19:11:27 +00:00
2023-08-12 02:29:10 +01:00
public void setPassword(String password) {
this.password = password;
}
2023-12-30 19:11:27 +00:00
2023-08-12 02:29:10 +01:00
public boolean isEnabled() {
return enabled;
}
2023-12-30 19:11:27 +00:00
2023-08-12 02:29:10 +01:00
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
2023-12-30 19:11:27 +00:00
public String getAuthenticationType() {
return authenticationType;
}
public void setAuthenticationType(AuthenticationType authenticationType) {
this.authenticationType = authenticationType.toString().toLowerCase();
}
2023-08-12 02:29:10 +01:00
public Set<Authority> getAuthorities() {
return authorities;
}
2023-12-30 19:11:27 +00:00
2023-08-12 02:29:10 +01:00
public void setAuthorities(Set<Authority> authorities) {
this.authorities = authorities;
}
2023-12-30 19:11:27 +00:00
2023-08-13 01:12:29 +01:00
public void addAuthorities(Set<Authority> authorities) {
this.authorities.addAll(authorities);
}
public void addAuthority(Authority authorities) {
this.authorities.add(authorities);
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
}
public boolean hasPassword() {
return this.password != null && !this.password.isEmpty();
}
2023-08-12 02:29:10 +01:00
}