Do not store RealmModel in CachedOrganizationIds
Closes #33331 Co-authored-by: Pedro Ruivo <pruivo@redhat.com> Signed-off-by: Michal Hajas <mhajas@redhat.com>
This commit is contained in:
parent
a35edeb488
commit
0becdaa2a9
2 changed files with 20 additions and 13 deletions
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.keycloak.models.cache.infinispan.organization;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.keycloak.models.OrganizationModel;
|
||||
|
@ -28,21 +28,28 @@ import org.keycloak.models.cache.infinispan.entities.InRealm;
|
|||
|
||||
public class CachedOrganizationIds extends AbstractRevisioned implements InRealm {
|
||||
|
||||
private final RealmModel realm;
|
||||
private final Set<String> orgIds = new HashSet<>();
|
||||
private final String realmId;
|
||||
private final List<String> orgIds;
|
||||
|
||||
public CachedOrganizationIds(Long revision, String id, RealmModel realm, Stream<OrganizationModel> organizations) {
|
||||
public CachedOrganizationIds(Long revision, String id, RealmModel realm, OrganizationModel model) {
|
||||
super(revision, id);
|
||||
this.realm = realm;
|
||||
organizations.map(OrganizationModel::getId).forEach(orgIds::add);
|
||||
this.realmId = realm.getId();
|
||||
orgIds = List.of(model.getId());
|
||||
}
|
||||
|
||||
public CachedOrganizationIds(Long revision, String id, RealmModel realm, Stream<OrganizationModel> models) {
|
||||
super(revision, id);
|
||||
this.realmId = realm.getId();
|
||||
var ids = models.map(OrganizationModel::getId).toList();
|
||||
orgIds = ids.isEmpty() ? List.of() : ids;
|
||||
}
|
||||
|
||||
public Collection<String> getOrgIds() {
|
||||
return orgIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRealm() {
|
||||
return realm.getId();
|
||||
}
|
||||
|
||||
public Set<String> getOrgIds() {
|
||||
return orgIds;
|
||||
return realmId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class InfinispanOrganizationProvider implements OrganizationProvider {
|
|||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
cached = new CachedOrganizationIds(loaded, cacheKey, getRealm(), Stream.of(model));
|
||||
cached = new CachedOrganizationIds(loaded, cacheKey, getRealm(), model);
|
||||
realmCache.getCache().addRevisioned(cached, realmCache.getStartupRevision());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue