From 90155862f31cf221ad139d24ca6f66eb11e3615c Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Fri, 22 Apr 2022 12:28:42 +0200 Subject: [PATCH] LdapMapStorageProvider to use a full inline class for MapStorage Closes #11373 --- .../storage/ldap/LdapMapStorageProvider.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/model/map-ldap/src/main/java/org/keycloak/models/map/storage/ldap/LdapMapStorageProvider.java b/model/map-ldap/src/main/java/org/keycloak/models/map/storage/ldap/LdapMapStorageProvider.java index 6db8624b60..1c5002b6b8 100644 --- a/model/map-ldap/src/main/java/org/keycloak/models/map/storage/ldap/LdapMapStorageProvider.java +++ b/model/map-ldap/src/main/java/org/keycloak/models/map/storage/ldap/LdapMapStorageProvider.java @@ -16,6 +16,7 @@ */ package org.keycloak.models.map.storage.ldap; +import org.keycloak.models.KeycloakSession; import org.keycloak.models.map.common.AbstractEntity; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; @@ -39,13 +40,18 @@ public class LdapMapStorageProvider implements MapStorageProvider { @Override @SuppressWarnings("unchecked") public MapStorage getStorage(Class modelType, Flag... flags) { - return session -> { - MapKeycloakTransaction sessionTx = session.getAttribute(sessionTxPrefix + modelType.hashCode(), MapKeycloakTransaction.class); - if (sessionTx == null) { - sessionTx = factory.createTransaction(session, modelType); - session.setAttribute(sessionTxPrefix + modelType.hashCode(), sessionTx); + // MapStorage is not a functional interface, therefore don't try to convert it to a lambda as additional methods might be added in the future + //noinspection Convert2Lambda + return new MapStorage() { + @Override + public MapKeycloakTransaction createTransaction(KeycloakSession session) { + MapKeycloakTransaction sessionTx = session.getAttribute(sessionTxPrefix + modelType.hashCode(), MapKeycloakTransaction.class); + if (sessionTx == null) { + sessionTx = factory.createTransaction(session, modelType); + session.setAttribute(sessionTxPrefix + modelType.hashCode(), sessionTx); + } + return sessionTx; } - return sessionTx; }; }