Stirling-PDF/src/main/java/stirling/software/SPDF/model/User.java

100 lines
2.3 KiB
Java
Raw Normal View History

2023-08-12 03:29:10 +02:00
package stirling.software.SPDF.model;
import java.util.Set;
2023-08-13 02:12:29 +02:00
import java.util.stream.Collectors;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.CascadeType;
2023-08-13 02:12:29 +02:00
import jakarta.persistence.CollectionTable;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.Column;
2023-08-13 02:12:29 +02:00
import jakarta.persistence.ElementCollection;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
2023-08-13 02:12:29 +02:00
import jakarta.persistence.MapKeyColumn;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
2023-08-13 02:12:29 +02:00
import jakarta.persistence.JoinColumn;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
2023-08-12 03:29:10 +02:00
@Entity
@Table(name = "users")
public class User {
@Id
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "enabled")
private boolean enabled;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "user")
2023-08-13 02:12:29 +02:00
private Set<Authority> authorities = new HashSet<>();
@ElementCollection
@MapKeyColumn(name = "setting_key")
@Column(name = "setting_value")
@CollectionTable(name = "user_settings", joinColumns = @JoinColumn(name = "username"))
private Map<String, String> settings = new HashMap<>(); // Key-value pairs of settings.
public Map<String, String> getSettings() {
return settings;
}
public void setSettings(Map<String, String> settings) {
this.settings = settings;
}
2023-08-12 03:29:10 +02:00
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Set<Authority> getAuthorities() {
return authorities;
}
public void setAuthorities(Set<Authority> authorities) {
this.authorities = authorities;
}
2023-08-13 02:12:29 +02:00
public void addAuthorities(Set<Authority> authorities) {
this.authorities.addAll(authorities);
}
public void addAuthority(Authority authorities) {
this.authorities.add(authorities);
}
public String getRolesAsString() {
return this.authorities.stream()
.map(Authority::getAuthority)
.collect(Collectors.joining(", "));
}
2023-08-12 03:29:10 +02:00
}