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;
|
package org.keycloak.models.cache.infinispan.organization;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.keycloak.models.OrganizationModel;
|
import org.keycloak.models.OrganizationModel;
|
||||||
|
@ -28,21 +28,28 @@ import org.keycloak.models.cache.infinispan.entities.InRealm;
|
||||||
|
|
||||||
public class CachedOrganizationIds extends AbstractRevisioned implements InRealm {
|
public class CachedOrganizationIds extends AbstractRevisioned implements InRealm {
|
||||||
|
|
||||||
private final RealmModel realm;
|
private final String realmId;
|
||||||
private final Set<String> orgIds = new HashSet<>();
|
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);
|
super(revision, id);
|
||||||
this.realm = realm;
|
this.realmId = realm.getId();
|
||||||
organizations.map(OrganizationModel::getId).forEach(orgIds::add);
|
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
|
@Override
|
||||||
public String getRealm() {
|
public String getRealm() {
|
||||||
return realm.getId();
|
return realmId;
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getOrgIds() {
|
|
||||||
return orgIds;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class InfinispanOrganizationProvider implements OrganizationProvider {
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
return 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());
|
realmCache.getCache().addRevisioned(cached, realmCache.getStartupRevision());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue