/** * @return The user of ThreadLocal if exists. */ public final static PFUserDO getUser() { final UserContext userContext = getUserContext(); if (userContext == null) { return null; } return userContext.getUser(); }
public TenantDO getCurrentTenant() { final UserContext userContext = ThreadLocalUserContext.getUserContext(); final TenantDO currentTenant = userContext != null ? userContext.getCurrentTenant() : tenantService.getDefaultTenant(); return 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()); } } } }
/** * Runs the update method of the given update entry. * * @param updateScript */ public void update(final UpdateEntry updateEntry) { UserContext uc = ThreadLocalUserContext.getUserContext(); exService.submit(() -> { setUpdating(true); try { ThreadLocalUserContext.setUserContext(uc); updateEntry.setRunningStatus(updateEntry.runUpdate()); //getDatabaseUpdateDao().writeUpdateEntryLog(updateEntry); updateEntry.setPreCheckStatus(updateEntry.runPreCheckSafely()); runAllPreChecks(); } catch (Error e) { log.error("Error while updating entry: " + updateEntry.getVersion(), e); } finally { setUpdating(false); } }); }
/** * * @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())); } } } }
list = new LinkedList<PFUserDO>(); for (final PFUserDO user : origList) { if (tenantChecker.isPartOfTenant(ThreadLocalUserContext.getUserContext().getCurrentTenant(), user) == true) { list.add(user);
public MySession(final Request request) { super(request); setLocale(request); final ClientInfo info = getClientInfo(); if (info instanceof WebClientInfo) { clientProperties = ((WebClientInfo) clientInfo).getProperties(); clientProperties.setTimeZone(ThreadLocalUserContext.getTimeZone()); userAgent = ((WebClientInfo) info).getUserAgent(); userAgentDevice = UserAgentDevice.getUserAgentDevice(userAgent); userAgentOS = UserAgentOS.getUserAgentOS(userAgent); mobileUserAgent = userAgentDevice.isMobile(); final UserAgentDetection userAgentDetection = UserAgentDetection.browserDetect(userAgent); userAgentBrowser = userAgentDetection.getUserAgentBrowser(); userAgentBrowserVersionString = userAgentDetection.getUserAgentBrowserVersion(); } else { log.error("Oups, ClientInfo is not from type WebClientInfo: " + info); } setUserContext(ThreadLocalUserContext.getUserContext()); initActualTenant(); this.csrfToken = NumberHelper.getSecureRandomUrlSaveString(20); }