Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumps sirius-biz and applies breaking changes #2064

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<properties>
<sirius.kernel>dev-44.1.0</sirius.kernel>
<sirius.web>dev-86.1.0</sirius.web>
<sirius.db>dev-59.0.0</sirius.db>
<sirius.db>dev-60.0.0</sirius.db>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class SQLVariant extends SQLEntity implements BlobVariant {

@AfterDelete
protected void onDelete() {
SQLBlob sqlBlob = sourceBlob.fetchValue();
SQLBlob sqlBlob = sourceBlob.fetchCachedValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Doesn't use of the ref-cache here potentially lead to trying to delete a blob that may be already deleted otherwise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, will review the places.

if (sqlBlob == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class MongoVariant extends MongoEntity implements BlobVariant {

@AfterDelete
protected void onDelete() {
MongoBlob mongoBlob = blob.fetchValue();
MongoBlob mongoBlob = blob.fetchCachedValue();
if (mongoBlob == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void computeVersion(VirtualObject object, String version) {
}

private void performVersionComputation(VirtualObjectVersion objectVersion) {
VirtualObject object = objectVersion.getVirtualObject().fetchValue();
VirtualObject object = objectVersion.getVirtualObject().fetchCachedValue();
try {
Tuple<Integer, Integer> size = Tuple.create(0, 0);
Tuple<Integer, Integer> extendedSize = Tuple.create(0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ protected void removePhysicalFile() {
@AfterDelete
protected void removeVersionFromCaches() {
if (this.getVirtualObject().isFilled()) {
versionManager.clearCacheForVirtualObject(this.getVirtualObject().fetchValue());
storage.clearCacheForVirtualObject(this.getVirtualObject().fetchValue());
versionManager.clearCacheForVirtualObject(this.getVirtualObject().fetchCachedValue());
storage.clearCacheForVirtualObject(this.getVirtualObject().fetchCachedValue());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/biz/tenants/SAMLController.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected List<T> querySAMLTenants() {

private void verifyUser(SAMLResponse response, UserInfo user) {
U account = user.getUserObject(getUserClass());
T tenant = account.getTenant().fetchValue();
T tenant = account.getTenant().fetchCachedValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Wouldn't it be better to use the cache of the Tenants part here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. Extrapolates the purpose of the change/ticket though which requires additional/special testing.


if (!checkIssuer(tenant, response)) {
throw Exceptions.createHandled().withSystemErrorMessage("SAML Error: Issuer mismatch!").handle();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/biz/tenants/TenantController.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public void selectTenant(final WebContext webContext, String tenantId) {
.causedByUser(account.getUniqueName(), account.getUserAccountData().getLogin().getUsername())
.forUser(account.getUniqueName(), account.getUserAccountData().getLogin().getUsername())
.forTenant(account.getTenant().getIdAsString(),
account.getTenant().fetchValue().getTenantData().getName())
account.getTenant().fetchCachedValue().getTenantData().getName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

.log();

webContext.setSessionValue(UserContext.getCurrentScope().getScopeId()
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/sirius/biz/tenants/TenantUserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public UserInfo findUserByName(@Nullable WebContext webContext, String user) {
U account = optionalAccount.get();

userAccountCache.put(account.getUniqueName(), account);
tenantsCache.put(account.getTenant().fetchValue().getIdAsString(), account.getTenant().fetchValue());
tenantsCache.put(account.getTenant().fetchCachedValue().getIdAsString(), account.getTenant().fetchCachedValue());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think its a good idea to fill a cache with a cached value

rolesCache.remove(account.getUniqueName());
configCache.remove(account.getUniqueName());

Expand Down Expand Up @@ -525,7 +525,7 @@ private UserInfo verifyIpRange(WebContext webContext, UserInfo info) {
return defaultUser;
}

T tenant = account.getTenant().fetchValue();
T tenant = account.getTenant().fetchCachedValue();

if (tenant != null && !tenant.getTenantData().matchesIPRange(webContext)) {
return createUserWithLimitedRoles(info, tenant.getTenantData().getRolesToKeepAsSet());
Expand Down Expand Up @@ -569,7 +569,8 @@ protected U fetchAccount(@Nonnull String accountId) {
return null;
}
userAccountCache.put(account.getUniqueName(), account);
tenantsCache.put(account.getTenant().fetchValue().getIdAsString(), account.getTenant().fetchValue());
tenantsCache.put(account.getTenant().fetchCachedValue().getIdAsString(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

account.getTenant().fetchCachedValue());
rolesCache.remove(account.getUniqueName());
configCache.remove(account.getUniqueName());

Expand Down Expand Up @@ -604,7 +605,7 @@ private UserInfo asUserWithRoles(U account, Set<String> 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(account.getTenant().fetchCachedValue().getTenantData().getName())
.withLanguage(computeLanguage(null, account.getUniqueName()))
.withPermissions(roles)
.withSettingsSupplier(user -> getUserSettings(getScopeSettings(), user))
Expand Down Expand Up @@ -641,7 +642,7 @@ public UserInfo findUserByCredentials(@Nullable WebContext webContext, String us
.getLogin()
.getLastExternalLogin(),
account.getTenant()
.fetchValue()
.fetchCachedValue()
.getTenantData()
.getExternalLoginIntervalDays())) {
completeAuditLogForUser(auditLog.negative("AuditLog.externalLoginRequired"), account);
Expand Down Expand Up @@ -673,7 +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())
account.getTenant().fetchCachedValue().getTenantData().getName())
.log();

return null;
Expand Down Expand Up @@ -718,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())
account.getTenant().fetchCachedValue().getTenantData().getName())
.log();
}

Expand Down Expand Up @@ -791,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 = user.getTenant().fetchCachedValue().getTenantData().getConfig();

if (userAccountConfig == null) {
if (tenantConfig == null) {
Expand Down Expand Up @@ -852,7 +853,7 @@ protected boolean isUserStillValid(String userId, WebContext webContext) {
}

LoginData loginData = user.getUserAccountData().getLogin();
TenantData tenantData = user.getTenant().fetchValue().getTenantData();
TenantData tenantData = user.getTenant().fetchCachedValue().getTenantData();

if (loginData.isAccountLocked()) {
return false;
Expand Down Expand Up @@ -966,7 +967,7 @@ protected Set<String> computeRoles(WebContext webContext, String accountUniqueNa
}

Set<String> roles = computeRoles(user,
user.getTenant().fetchValue(),
user.getTenant().fetchCachedValue(),
Strings.areEqual(systemTenant, String.valueOf(user.getTenant().getId())));

rolesCache.put(accountUniqueName, Tuple.create(roles, user.getTenant().getUniqueObjectName()));
Expand Down Expand Up @@ -1041,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(),
userAccount.getTenant().fetchCachedValue().getTenantData().getLanguage().getValue(),
NLS.getDefaultLanguage());
}
}
4 changes: 2 additions & 2 deletions src/main/java/sirius/biz/tenants/Tenants.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public Optional<T> fetchCachedTenant(BaseEntityRef<I, T> tenantRef) {
}

if (tenantRef.isValueLoaded()) {
return Optional.of(tenantRef.fetchValue());
return Optional.of(tenantRef.fetchCachedValue());
}

return fetchCachedTenant(String.valueOf(tenantRef.getId()));
Expand Down Expand Up @@ -402,7 +402,7 @@ public Optional<U> fetchCachedUserAccount(BaseEntityRef<I, U> userRef) {
}

if (userRef.isValueLoaded()) {
return Optional.of(userRef.fetchValue());
return Optional.of(userRef.fetchCachedValue());
}

return fetchCachedUserAccount(userRef.getIdAsString());
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/sirius/biz/tenants/UserAccountData.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public <A> Optional<A> tryAs(Class<A> adapterType) {
}

protected Tenant<?> getTenant() {
return ((UserAccount<?, ?>) userObject).getTenant().fetchValue();
return ((UserAccount<?, ?>) userObject).getTenant().fetchCachedValue();
}

@Override
Expand Down Expand Up @@ -369,7 +369,8 @@ public boolean isOwnUser() {
* @return <tt>true</tt> if this user belongs to the current user's tenant, <tt>false</tt> otherwise
*/
public boolean isOwnTenant() {
return Objects.equals(UserContext.getCurrentUser().as(UserAccount.class).getTenant().fetchValue(), getTenant());
return Objects.equals(UserContext.getCurrentUser().as(UserAccount.class).getTenant().fetchCachedValue(),
getTenant());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void query(String query, int maxResults, Consumer<OpenSearchResult> resul
} else {
openSearchResult.withDescription(userAccount
+ " ("
+ userAccount.getTenant().fetchValue().toString()
+ userAccount.getTenant().fetchCachedValue().toString()
+ ")")
.withURL("/tenants/select/"
+ userAccount.getTenant().getIdAsString()
Expand All @@ -103,9 +103,9 @@ public void query(String query, int maxResults, Consumer<OpenSearchResult> resul
<t:smartValue type="tenant"
id="@generateId('smarty-useraccount-%s')"
payload="@user.getTenantAsString()"
label="@user.getTenant().fetchValue().toString()"/>
label="@user.getTenant().fetchCachedValue().toString()"/>
<i:else>
@user.getTenant().fetchValue().toString()
@user.getTenant().fetchCachedValue().toString()
</i:else>
</i:if>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
suggestionUri="/tenants/autocomplete">
<i:if test="tenant.getParent().isFilled()">
<option value="@tenant.getParent().getId()" selected="selected">
@tenant.getParent().fetchValue()
@tenant.getParent().fetchCachedValue()
</option>
</i:if>
</t:singleSelect>
Expand Down
Loading