public boolean isPartOfTenant(final TenantDO tenant, final PFUserDO user) { if (tenantService.isMultiTenancyAvailable() == false) { return true; } if (tenant == null || user == null || tenant.getAssignedUsers() == null) { return false; } return tenant.getAssignedUsers().contains(user); }
public boolean isPartOfTenant(final Integer tenantId, final BaseDO<?> obj) { if (tenantService.isMultiTenancyAvailable() == false) { return true; } if (obj == null) { return false; } if (tenantId == null || obj.getTenantId() == null) { return false; } return tenantId.equals(obj.getTenantId()); }
/** * @param tenant * @param obj * @return true if id of tenant is equals to tenant id of the given object, otherwise false. */ public boolean isPartOfTenant(final TenantDO tenant, final BaseDO<?> obj) { if (tenantService.isMultiTenancyAvailable() == false) { return true; } if (tenant == null) { return false; } return isPartOfTenant(tenant.getId(), obj); }
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); }
private void initActualTenant() { if (ThreadLocalUserContext.getUserContext() == null) { return; } UserContext userContext = ThreadLocalUserContext.getUserContext(); TenantService tenantService = ApplicationContextProvider.getApplicationContext().getBean(TenantService.class); PFUserDO user = userContext.getUser(); if (user.getId() != null && tenantService.isMultiTenancyAvailable() == true) { // Try to find the last used tenant of the user: final Integer currentTenantId = (Integer) UserPreferencesHelper.getEntry(USER_PREF_KEY_CURRENT_TENANT); if (currentTenantId != null) { setCurrentTenant(tenantService.getTenant(currentTenantId)); } else { final Collection<TenantDO> tenants = tenantService.getTenantsOfUser(user.getId()); if (CollectionUtils.isNotEmpty(tenants) == true) { setCurrentTenant(tenants.iterator().next()); } } } }
/** * * @param filter * @param ignoreTenant default is false. */ public QueryFilter(final BaseSearchFilter filter, final boolean ignoreTenant) { if (filter == null) { this.filter = new BaseSearchFilter(); } else { this.filter = filter; } TenantService tenantService = ApplicationContextProvider.getApplicationContext().getBean(TenantService.class); if (ignoreTenant == false && tenantService.isMultiTenancyAvailable() == true) { final UserContext userContext = ThreadLocalUserContext.getUserContext(); final TenantDO currentTenant = userContext.getCurrentTenant(); if (currentTenant != null) { if (currentTenant.isDefault() == true) { this.add(Restrictions.or(Restrictions.eq("tenant", userContext.getCurrentTenant()), Restrictions.isNull("tenant"))); } else { this.add(Restrictions.eq("tenant", userContext.getCurrentTenant())); } } } }
/** * 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 TenantRegistry getTenantRegistry(TenantDO tenant) if (tenantService.isMultiTenancyAvailable() == false) { if (tenant != null && !tenant.isDefault()) { log.warn("Oups, why call getTenantRegistry with tenant " + tenant.getId()
if (applicationContext.getBean(TenantService.class).isMultiTenancyAvailable() == true && TenantChecker.isSuperAdmin(ThreadLocalUserContext.getUser()) == false) { final List<PFUserDO> origList = list;
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); } }
final Collection<TenantDO> tenants = tenantService.isMultiTenancyAvailable() == true ? tenantService.getTenantsOfLoggedInUser() : null; if (tenants == null || tenants.size() <= 1) {