revert tenant filter disable
This commit is contained in:
parent
2d2750c44c
commit
6eb01fbd1c
|
@ -1,13 +1,12 @@
|
|||
package org.opencdmp.data.tenant;
|
||||
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.hibernate.Session;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
|
@ -15,7 +14,7 @@ import javax.management.InvalidApplicationException;
|
|||
|
||||
@Aspect
|
||||
@Component
|
||||
@ConditionalOnMissingBean(TenantScope.class)
|
||||
//@ConditionalOnMissingBean(TenantScope.class)
|
||||
public class TenantFilterAspect {
|
||||
|
||||
private final TenantScope tenantScope;
|
||||
|
@ -31,12 +30,12 @@ public class TenantFilterAspect {
|
|||
pointcut = "bean(entityManagerFactory) && execution(* createEntityManager(..))",
|
||||
returning = "retVal")
|
||||
public void getSessionAfter(JoinPoint joinPoint, Object retVal) throws InvalidApplicationException {
|
||||
if (retVal instanceof EntityManager && tenantScope.isSet()) {
|
||||
if (retVal instanceof EntityManager && this.tenantScope.isSet()) {
|
||||
Session session = ((EntityManager) retVal).unwrap(Session.class);
|
||||
if(!tenantScope.isDefaultTenant()) {
|
||||
if(!this.tenantScope.isDefaultTenant()) {
|
||||
session
|
||||
.enableFilter(TenantScopedBaseEntity.TENANT_FILTER)
|
||||
.setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString());
|
||||
.setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, this.tenantScope.getTenant().toString());
|
||||
} else {
|
||||
session
|
||||
.enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.opencdmp.data.tenant;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import org.hibernate.annotations.Filter;
|
||||
import org.hibernate.annotations.FilterDef;
|
||||
|
@ -18,7 +19,7 @@ import java.util.UUID;
|
|||
@FilterDef(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER)
|
||||
@Filter(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER, condition = "(tenant = tenant is null)")
|
||||
@Filter(name = TenantScopedBaseEntity.TENANT_FILTER, condition = "(tenant = (cast(:tenantId as uuid)) or tenant is null)")
|
||||
//@EntityListeners(TenantListener.class)
|
||||
@EntityListeners(TenantListener.class)
|
||||
public abstract class TenantScopedBaseEntity implements TenantScoped, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final String TENANT_FILTER = "tenantFilter";
|
||||
|
|
Loading…
Reference in New Issue