From 9399897114d4bd45841fd3091a651b03ce08e1a4 Mon Sep 17 00:00:00 2001 From: Idevaldo De Lira Date: Mon, 16 Dec 2024 16:04:02 +0100 Subject: [PATCH] Uses fetchTenant whenever possible which uses the internal cache instead of relying on the value set at the reference Fixes: SIRI-1039 --- .../sirius/biz/tenants/TenantUserManager.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/sirius/biz/tenants/TenantUserManager.java b/src/main/java/sirius/biz/tenants/TenantUserManager.java index 3ef340c0c..9a313a206 100644 --- a/src/main/java/sirius/biz/tenants/TenantUserManager.java +++ b/src/main/java/sirius/biz/tenants/TenantUserManager.java @@ -526,7 +526,7 @@ private UserInfo verifyIpRange(WebContext webContext, UserInfo info) { return defaultUser; } - T tenant = account.getTenant().fetchValue(); + T tenant = fetchTenant(account.getTenant().getIdAsString()); if (tenant != null && !tenant.getTenantData().matchesIPRange(webContext)) { return createUserWithLimitedRoles(info, tenant.getTenantData().getRolesToKeepAsSet()); @@ -606,7 +606,8 @@ private UserInfo asUserWithRoles(U account, Set roles, @Nullable Supplie return UserInfo.Builder.createUser(account.getUniqueName()) .withUsername(account.getUserAccountData().getLogin().getUsername()) .withTenantId(String.valueOf(account.getTenant().getId())) - .withTenantName(account.getTenant().fetchValue().getTenantData().getName()) + .withTenantName(fetchTenant(account.getTenant().getIdAsString()).getTenantData() + .getName()) .withLanguage(computeLanguage(null, account.getUniqueName())) .withPermissions(roles) .withSettingsSupplier(user -> getUserSettings(getScopeSettings(), user)) @@ -639,13 +640,12 @@ public UserInfo findUserByCredentials(@Nullable WebContext webContext, String us } U account = result.getUserObject(getUserClass()); + T tenant = fetchTenant(account.getTenant().getIdAsString()); if (account.getUserAccountData().isExternalLoginRequired() && !isWithinInterval(account.getUserAccountData() .getLogin() .getLastExternalLogin(), - account.getTenant() - .fetchValue() - .getTenantData() - .getExternalLoginIntervalDays())) { + tenant.getTenantData() + .getExternalLoginIntervalDays())) { completeAuditLogForUser(auditLog.negative("AuditLog.externalLoginRequired"), account); throw Exceptions.createHandled().withNLSKey("UserAccount.externalLoginMustBePerformed").handle(); } @@ -674,8 +674,7 @@ public UserInfo findUserByCredentials(@Nullable WebContext webContext, String us auditLog.negative("AuditLog.loginRejected") .forUser(account.getUniqueName(), account.getUserAccountData().getLogin().getUsername()) - .forTenant(String.valueOf(account.getTenant().getId()), - account.getTenant().fetchValue().getTenantData().getName()) + .forTenant(tenant.getIdAsString(), tenant.getTenantData().getName()) .log(); return null; @@ -720,7 +719,7 @@ protected void completeAuditLogForUser(AuditLog.AuditLogBuilder builder, U accou builder.causedByUser(account.getUniqueName(), account.getUserAccountData().getLogin().getUsername()) .forUser(account.getUniqueName(), account.getUserAccountData().getLogin().getUsername()) .forTenant(String.valueOf(account.getTenant().getId()), - account.getTenant().fetchValue().getTenantData().getName()) + fetchTenant(account.getTenant().getIdAsString()).getTenantData().getName()) .log(); } @@ -793,7 +792,7 @@ protected U getUserObject(UserInfo userInfo) { protected UserSettings getUserSettings(UserSettings scopeSettings, UserInfo userInfo) { U user = userInfo.getUserObject(getUserClass()); Config userAccountConfig = user.getUserAccountData().getPermissions().getConfig(); - Config tenantConfig = user.getTenant().fetchValue().getTenantData().getConfig(); + Config tenantConfig = fetchTenant(user.getTenant().getIdAsString()).getTenantData().getConfig(); if (userAccountConfig == null) { if (tenantConfig == null) { @@ -854,7 +853,7 @@ protected boolean isUserStillValid(String userId, WebContext webContext) { } LoginData loginData = user.getUserAccountData().getLogin(); - TenantData tenantData = user.getTenant().fetchValue().getTenantData(); + TenantData tenantData = fetchTenant(user.getTenant().getIdAsString()).getTenantData(); if (loginData.isAccountLocked()) { return false; @@ -968,7 +967,7 @@ protected Set computeRoles(WebContext webContext, String accountUniqueNa } Set roles = computeRoles(user, - user.getTenant().fetchValue(), + fetchTenant(user.getTenant().getIdAsString()), Strings.areEqual(systemTenant, String.valueOf(user.getTenant().getId()))); rolesCache.put(accountUniqueName, Tuple.create(roles, user.getTenant().getUniqueObjectName())); @@ -1043,7 +1042,7 @@ protected String computeLanguage(WebContext webContext, String userId) { return NLS.getDefaultLanguage(); } return Strings.firstFilled(userAccount.getUserAccountData().getLanguage().getValue(), - userAccount.getTenant().fetchValue().getTenantData().getLanguage().getValue(), + fetchTenant(userAccount.getTenant().getIdAsString()).getTenantData().getLanguage().getValue(), NLS.getDefaultLanguage()); } }