public TenantRegistry getTenantRegistry() { if (tenantService.isMultiTenancyAvailable() == false) { return getSingleTenantRegistry(); } final TenantDO tenant = tenantChecker.getCurrentTenant(); return getTenantRegistry(tenant); }
/** * Sets the current tenant (of the logged-in user) for the given object. If no current tenant found, the default * tenant of the system is used (if exist). If no such tenant exist, null is set as the object's tenant. <br/> * If no multi-tenancy is configured, nothing is done. * * @param obj */ public void setCurrentTenant(final BaseDO<?> obj) { if (tenantService.isMultiTenancyAvailable() == false) { return; } TenantDO currentTenant = getCurrentTenant(); if (currentTenant == null) { currentTenant = tenantService.getDefaultTenant(); } obj.setTenant(currentTenant); }
/** * Checks only if the current chosen tenant of the logged-in-user fit the tenant of the given object. This means the * user's current tenant is the same tenant the given object is assigned to, or the current tenant is the default * tenant and the given object is not assigned to a tenant.<br/> * If no multi-tenancy is configured, always true is returned. * * @param obj * @return */ public boolean isPartOfCurrentTenant(final BaseDO<?> obj) { if (tenantService.isMultiTenancyAvailable() == false) { return true; } if (obj == null) { return false; } if (obj instanceof TenantDO && isSuperAdmin(ThreadLocalUserContext.getUser()) == true) { return true; } final TenantDO currentTenant = getCurrentTenant(); if (currentTenant == null) { return false; } if (obj.getTenantId() == null) { // The given object isn't assigned to a tenant, so assuming the default tenant. return currentTenant.isDefault(); } return obj.getTenantId().equals(currentTenant.getId()); }
public void checkPartOfCurrentTenant(final BaseDO<?> obj) { if (tenantService.isMultiTenancyAvailable() == false) { return; } if (isPartOfCurrentTenant(obj) == false) { final TenantDO currentTenant = getCurrentTenant(); final String currentTenantString = currentTenant != null ? currentTenant.getName() : ThreadLocalUserContext .getLocalizedString("multitenancy.defaultTenant"); final TenantDO objectTenant = obj.getTenant(); final String objectTenantString = objectTenant != null ? objectTenant.getName() : ThreadLocalUserContext .getLocalizedString("multitenancy.defaultTenant"); throw new AccessException(ThreadLocalUserContext.getUser(), "access.exception.usersCurrentTenantDoesNotMatch", currentTenantString, objectTenantString); } }