Forgive me if this is an obvious question.
My application uses LDAP authentication, but loads user authorities from it's database, which works perfectly well. Now I'm trying to create JPA entities to manage the users and authorities though a REST interface.
How do I implement the following schema using JPA?
create table users(
username varchar(50) not null primary key,
password varchar(50) not null,
enabled boolean not null
);
create table authorities (
username varchar(50) not null,
authority varchar(50) not null,
constraint fk_authorities_users foreign key(username) references users(username)
);
create unique index ix_auth_username on authorities (username, authority)
This is what I've created so far:
User.java:
@Entity
@Data
@Table(name = "users", uniqueConstraints = {@UniqueConstraint(columnNames = {"username"})})
public class User {
@Id
@NotNull
@Column(length=50)
private String username;
@NotNull
private String password;
@NotNull
boolean enabled;
}
Authority.java:
@Entity
@Data
@Table(name = "authorities", uniqueConstraints = {@UniqueConstraint(columnNames = {"username"})})
public class Authority {
@Id
@NotNull
@Column(length=50)
private String username;
@NotNull
private String authority;
}
UserRepository:
public interface UserRepository extends CrudRepository<User, Long> { }