@Override
public void onLoad(LoadEvent event, LoadType loadType) throws HibernateException {
Object LoadedEntity = event.getResult();
if (LoadedEntity != null && isMultiTenantEntity(LoadedEntity)) {
MultiTenantDomainClass entity = (MultiTenantDomainClass) LoadedEntity;
Integer currentTenantId = currentTenant.get();
// We won't be able to extract tenant-id from an association fetch.
// TODO: This is a bit scary as it means that we potentially can load entities from
// other tenants through various variants of Hibernate collection / lazy loading.
if (!event.isAssociationFetch() && !allowEntityLoad(currentTenantId, entity)) {
log.debug("Refusing tenant {} to load {}", currentTenant.get(), entity.getClass().getSimpleName());
event.setResult(null);
}
}
}