Eu imaginei algo mais ou menos assim para o UserCredentials:
@Entity
@Table(name = "user_credentials")
public class UserCredentials implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String username;
private String senha;
private boolean enabled;
@JsonIgnore
@OneToMany(mappedBy = "userCredentials")
List<Authorities> userAuthorities = new ArrayList<>();
public UserCredentials() {
}
public UserCredentials(String username, String senha, boolean enabled) {
this.username = username;
this.senha = senha;
this.enabled = enabled;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
E algo assim para o Authorities:
@Entity
@Table(name = "authorities")
public class Authorities {
@ManyToOne
@JoinColumn(name = "username")
private UserCredentials userCredentials;
private String authority;
public Authorities() {
}
public Authorities(UserCredentials userCredentials, String authority) {
this.userCredentials = userCredentials;
this.authority = authority;
}
public UserCredentials getUserCredentials() {
return userCredentials;
}
public void setUserCredentials(UserCredentials userCredentials) {
this.userCredentials = userCredentials;
}
public String getAuthority() {
return authority;
}
public void setAuthority(String authority) {
this.authority = authority;
}
}
Isso faz sentido? Funcionaria corretamente em uma situação real supondo que um usuário poderia ter mais de uma permissão?