diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/InfinispanOrganizationProvider.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/InfinispanOrganizationProvider.java index 4f08231b31..0a17163143 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/InfinispanOrganizationProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/InfinispanOrganizationProvider.java @@ -154,8 +154,7 @@ public class InfinispanOrganizationProvider implements OrganizationProvider { @Override public OrganizationModel getByMember(UserModel member) { - // Return cache delegate to ensure cache invalidation during write operations - return getCacheDelegate(orgDelegate.getByMember(member)); + return orgDelegate.getByMember(member); } @Override @@ -235,11 +234,7 @@ public class InfinispanOrganizationProvider implements OrganizationProvider { return realm; } - private OrganizationModel getCacheDelegate(OrganizationModel model) { - return model == null ? null : getById(model.getId()); - } - private Stream getCacheDelegates(Stream backendOrganizations) { - return backendOrganizations.map(this::getCacheDelegate); + return backendOrganizations.map(OrganizationModel::getId).map(this::getById); } } diff --git a/model/jpa/src/main/java/org/keycloak/organization/jpa/JpaOrganizationProvider.java b/model/jpa/src/main/java/org/keycloak/organization/jpa/JpaOrganizationProvider.java index 1597a2ebe9..62ff493926 100644 --- a/model/jpa/src/main/java/org/keycloak/organization/jpa/JpaOrganizationProvider.java +++ b/model/jpa/src/main/java/org/keycloak/organization/jpa/JpaOrganizationProvider.java @@ -274,7 +274,8 @@ public class JpaOrganizationProvider implements OrganizationProvider { return null; } - return getById(orgId); + // need to go via the session to avoid bypassing the cache + return session.getProvider(OrganizationProvider.class).getById(orgId); } @Override