Это класс моей учетной записи: он реализуем UserDetails и CredentialsContainer
Код: Выделить всё
@Entity
@Table(name = "accounts")
public class Account implements UserDetails, CredentialsContainer {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
private String firstName;
private String lastName;
private String username;
private String email;
private String password;
private LocalDateTime createdAt;
private Boolean verified;
private Boolean locked;
private String hashIdentifier;
@OneToMany(mappedBy = "account")
private Set accountsAuthorities;
}
Код: Выделить всё
@Entity
@Table(name = "authorities")
public class Authority {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
private String authorityName;
@OneToMany(mappedBy = "authority")
private Set accountsAuthorities;
}
Код: Выделить всё
@Entity
@Table(name = "accounts_authorities")
public class AccountAuthority implements GrantedAuthority {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
@ManyToOne
@JoinColumn(name = "account_id")
private Account account;
@ManyToOne
@JoinColumn(name = "authority_id")
private Authority authority;
private LocalDateTime assignedAt;
private LocalDateTime revokedAt;
}
Код: Выделить всё
@Repository
public interface AccountRepository extends JpaRepository, JpaSpecificationExecutor {
Optional findByUsername(String username);
}
Код: Выделить всё
@Override
public List loadAllAccounts() {
return accountRepository.findAll();
}
Код: Выделить всё
Hibernate:
select
a1_0.id,
a1_0.created_at,
a1_0.email,
a1_0.first_name,
a1_0.hash_identifier,
a1_0.last_name,
a1_0.locked,
a1_0.password,
a1_0.username,
a1_0.verified
from
accounts a1_0
Hibernate:
select
aa1_0.account_id,
aa1_0.id,
aa1_0.assigned_at,
a2_0.id,
a2_0.authority_name,
aa1_0.revoked_at
from
accounts_authorities aa1_0
left join
authorities a2_0
on a2_0.id=aa1_0.authority_id
where
aa1_0.account_id=?
Мой вопрос: можно ли запретить получение списка полномочий при получении учетной записи, например, чтобы выполнялся только этот запрос:
Код: Выделить всё
Hibernate:
select
a1_0.id,
a1_0.created_at,
a1_0.email,
a1_0.first_name,
a1_0.hash_identifier,
a1_0.last_name,
a1_0.locked,
a1_0.password,
a1_0.username,
a1_0.verified
from
accounts a1_0
Кроме того, база данных будет содержать несколько записей с одним и тем же идентификатором account_id и Authority_id, поскольку я хочу отслеживать историю отзыва полномочий (ролей):
ИЗОБРАЖЕНИЕ ТАБЛИЦЫ — открыть здесь >
Можно ли изменить выборку полномочий, чтобы загружались только те полномочия, где revoked_at равен 9999-12-31 23:59:59, примерно так:
Код: Выделить всё
select
a1_0.id,
a1_0.created_at,
a1_0.email,
a1_0.first_name,
a1_0.hash_identifier,
a1_0.last_name,
a1_0.locked,
a1_0.password,
a1_0.username,
a1_0.verified
from
accounts a1_0
select
aa1_0.account_id,
aa1_0.id,
aa1_0.assigned_at,
a2_0.id,
a2_0.authority_name,
aa1_0.revoked_at
from
accounts_authorities aa1_0
left join
authorities a2_0
on a2_0.id=aa1_0.authority_id
where
aa1_0.account_id=?
and revoked_at='9999-12-31 23:59:59'
Подробнее здесь: https://stackoverflow.com/questions/793 ... new-entity