From d41764b19bbb682b187f37a60b71de9a6eb7d612 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Wed, 18 May 2022 10:55:49 +0200 Subject: [PATCH] Inline deprecated methods in legacy code --- .../storage/ldap/LDAPStorageProvider.java | 9 ++-- .../ldap/LDAPStorageProviderFactory.java | 5 +- .../models/cache/infinispan/RealmAdapter.java | 3 +- .../migration/migrators/MigrateTo1_4_0.java | 2 +- .../keycloak/storage/UserStorageManager.java | 4 +- .../datastore/LegacyExportImportManager.java | 3 +- .../util/MultipleStepsExportProvider.java | 5 +- .../org/keycloak/storage/UserStorageUtil.java | 12 +++++ .../AbstractUserAdapterFederatedStorage.java | 3 +- .../exportimport/util/ExportUtils.java | 21 +++++--- .../BackwardsCompatibilityUserStorage.java | 3 +- ...ssThroughFederatedUserStorageProvider.java | 15 +++--- .../testsuite/federation/UserMapStorage.java | 3 +- .../authz/UmaRepresentationTest.java | 2 +- .../ldap/LDAPMultipleAttributesTest.java | 5 +- .../ldap/LDAPProvidersIntegrationTest.java | 11 ++-- .../federation/ldap/LDAPSyncTest.java | 4 +- .../LDAPMultipleAttributesNoImportTest.java | 3 +- .../LDAPRoleMappingsNoImportTest.java | 15 +++--- .../federation/storage/ClientStorageTest.java | 8 +-- .../FederatedStorageExportImportTest.java | 53 ++++++++++--------- .../federation/storage/GroupStorageTest.java | 4 +- .../federation/storage/RoleStorageTest.java | 4 +- .../storage/UserStorageFailureTest.java | 3 +- .../federation/storage/UserStorageTest.java | 5 +- .../testsuite/model/UserModelTest.java | 9 ++-- 26 files changed, 124 insertions(+), 90 deletions(-) rename {server-spi => model/legacy}/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java (99%) diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java index dbf9803b1b..d66aa59993 100755 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java @@ -64,6 +64,7 @@ import org.keycloak.storage.StorageId; import org.keycloak.storage.UserStoragePrivateUtil; import org.keycloak.storage.UserStorageProvider; import org.keycloak.storage.UserStorageProviderModel; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.adapter.InMemoryUserAdapter; import org.keycloak.storage.adapter.UpdateOnlyChangeUserModelDelegate; import org.keycloak.storage.ldap.idm.model.LDAPObject; @@ -240,7 +241,7 @@ public class LDAPStorageProvider implements UserStorageProvider, logger.debugf("Updated LDAP DN of user '%s' to '%s'", local.getUsername(), ldapDn); local.setSingleAttribute(LDAPConstants.LDAP_ENTRY_DN, ldapDn); - UserCache userCache = session.userCache(); + UserCache userCache = UserStorageUtil.userCache(session); if (userCache != null) { userCache.evict(realm, local); } @@ -530,8 +531,8 @@ public class LDAPStorageProvider implements UserStorageProvider, if(existingLocalUser != null){ imported = existingLocalUser; // Need to evict the existing user from cache - if (session.userCache() != null) { - session.userCache().evict(realm, existingLocalUser); + if (UserStorageUtil.userCache(session) != null) { + UserStorageUtil.userCache(session).evict(realm, existingLocalUser); } } else { imported = UserStoragePrivateUtil.userLocalStorage(session).addUser(realm, ldapUsername); @@ -792,7 +793,7 @@ public class LDAPStorageProvider implements UserStorageProvider, logger.warnf("User with username [%s] aready exists and is linked to provider [%s] but is not valid. Stale LDAP_ID on local user is: %s", username, model.getName(), user.getFirstAttribute(LDAPConstants.LDAP_ID)); logger.warn("Will re-create user"); - UserCache userCache = session.userCache(); + UserCache userCache = UserStorageUtil.userCache(session); if (userCache != null) { userCache.evict(realm, user); } diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java index 6a95317974..a4dcbfdbbe 100755 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java @@ -43,6 +43,7 @@ import org.keycloak.storage.UserStoragePrivateUtil; import org.keycloak.storage.UserStorageProvider; import org.keycloak.storage.UserStorageProviderFactory; import org.keycloak.storage.UserStorageProviderModel; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.ldap.idm.model.LDAPObject; import org.keycloak.storage.ldap.idm.query.Condition; import org.keycloak.storage.ldap.idm.query.internal.LDAPQuery; @@ -630,7 +631,7 @@ public class LDAPStorageProviderFactory implements UserStorageProviderFactory> entry : userRep.getAttributes().entrySet()) { String key = entry.getKey(); diff --git a/model/legacy-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java b/model/legacy-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java index e88479bf2e..88e7529153 100755 --- a/model/legacy-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java +++ b/model/legacy-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java @@ -28,6 +28,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.storage.UserStorageUtil; import java.io.IOException; import java.util.List; @@ -83,7 +84,7 @@ public abstract class MultipleStepsExportProvider implements ExportProvider { // Count total number of users if (!exportUsersIntoRealmFile) { usersHolder.totalCount = session.users().getUsersCount(realm, true); - federatedUsersHolder.totalCount = session.userFederatedStorage().getStoredUsersCount(realm); + federatedUsersHolder.totalCount = UserStorageUtil.userFederatedStorage(session).getStoredUsersCount(realm); } } @@ -141,7 +142,7 @@ public abstract class MultipleStepsExportProvider implements ExportProvider { @Override protected void runExportImportTask(KeycloakSession session) throws IOException { RealmModel realm = session.realms().getRealmByName(realmName); - federatedUsersHolder.users = session.userFederatedStorage() + federatedUsersHolder.users = UserStorageUtil.userFederatedStorage(session) .getStoredUsersStream(realm, federatedUsersHolder.currentPageStart, federatedUsersHolder.currentPageEnd - federatedUsersHolder.currentPageStart) .collect(Collectors.toList()); diff --git a/model/legacy/src/main/java/org/keycloak/storage/UserStorageUtil.java b/model/legacy/src/main/java/org/keycloak/storage/UserStorageUtil.java index 51eb6069a3..4bd7cfad28 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/UserStorageUtil.java +++ b/model/legacy/src/main/java/org/keycloak/storage/UserStorageUtil.java @@ -1,6 +1,9 @@ package org.keycloak.storage; +import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; +import org.keycloak.models.cache.UserCache; +import org.keycloak.storage.federated.UserFederatedStorageProvider; import java.util.stream.Stream; @@ -18,4 +21,13 @@ public class UserStorageUtil { .map(UserStorageProviderModel::new) .sorted(UserStorageProviderModel.comparator); } + + public static UserFederatedStorageProvider userFederatedStorage(KeycloakSession session) { + return session.getProvider(UserFederatedStorageProvider.class); + } + + public static UserCache userCache(KeycloakSession session) { + return session.getProvider(UserCache.class); + } + } diff --git a/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java b/model/legacy/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java similarity index 99% rename from server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java rename to model/legacy/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java index d7756a3042..15c37b28f6 100644 --- a/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java +++ b/model/legacy/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java @@ -29,6 +29,7 @@ import org.keycloak.models.UserModel; import org.keycloak.models.UserModelDefaultMethods; import org.keycloak.models.utils.RoleUtils; import org.keycloak.storage.StorageId; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.federated.UserFederatedStorageProvider; import java.util.Collections; @@ -69,7 +70,7 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau } public UserFederatedStorageProvider getFederatedStorage() { - return session.userFederatedStorage(); + return UserStorageUtil.userFederatedStorage(session); } @Override diff --git a/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java b/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java index c77fbe8051..98a213a099 100755 --- a/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java +++ b/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java @@ -58,6 +58,7 @@ import org.keycloak.representations.idm.authorization.ResourceOwnerRepresentatio import org.keycloak.representations.idm.authorization.ResourceRepresentation; import org.keycloak.representations.idm.authorization.ResourceServerRepresentation; import org.keycloak.representations.idm.authorization.ScopeRepresentation; +import org.keycloak.storage.federated.UserFederatedStorageProvider; import org.keycloak.util.JsonSerialization; import java.io.IOException; @@ -234,7 +235,7 @@ public class ExportUtils { rep.setUsers(users); } - List federatedUsers = session.userFederatedStorage().getStoredUsersStream(realm, 0, -1) + List federatedUsers = userFederatedStorage(session).getStoredUsersStream(realm, 0, -1) .map(user -> exportFederatedUser(session, realm, user, options)).collect(Collectors.toList()); if (federatedUsers.size() > 0) { rep.setFederatedUsers(federatedUsers); @@ -613,20 +614,20 @@ public class ExportUtils { public static UserRepresentation exportFederatedUser(KeycloakSession session, RealmModel realm, String id, ExportOptions options) { UserRepresentation userRep = new UserRepresentation(); userRep.setId(id); - MultivaluedHashMap attributes = session.userFederatedStorage().getAttributes(realm, id); + MultivaluedHashMap attributes = userFederatedStorage(session).getAttributes(realm, id); if (attributes.size() > 0) { Map> attrs = new HashMap<>(); attrs.putAll(attributes); userRep.setAttributes(attrs); } - List requiredActions = session.userFederatedStorage().getRequiredActionsStream(realm, id).collect(Collectors.toList()); + List requiredActions = userFederatedStorage(session).getRequiredActionsStream(realm, id).collect(Collectors.toList()); if (requiredActions.size() > 0) { userRep.setRequiredActions(requiredActions); } // Social links - List socialLinkReps = session.userFederatedStorage().getFederatedIdentitiesStream(id, realm) + List socialLinkReps = userFederatedStorage(session).getFederatedIdentitiesStream(id, realm) .map(ExportUtils::exportSocialLink).collect(Collectors.toList()); if (socialLinkReps.size() > 0) { @@ -635,7 +636,7 @@ public class ExportUtils { // Role mappings if (options.isGroupsAndRolesIncluded()) { - Set roles = session.userFederatedStorage().getRoleMappingsStream(realm, id).collect(Collectors.toSet()); + Set roles = userFederatedStorage(session).getRoleMappingsStream(realm, id).collect(Collectors.toSet()); List realmRoleNames = new ArrayList<>(); Map> clientRoleNames = new HashMap<>(); for (RoleModel role : roles) { @@ -663,7 +664,7 @@ public class ExportUtils { } // Credentials - List credReps = session.userFederatedStorage().getStoredCredentialsStream(realm, id) + List credReps = userFederatedStorage(session).getStoredCredentialsStream(realm, id) .map(ExportUtils::exportCredential).collect(Collectors.toList()); userRep.setCredentials(credReps); @@ -675,15 +676,19 @@ public class ExportUtils { } // Not Before - int notBefore = session.userFederatedStorage().getNotBeforeOfUser(realm, userRep.getId()); + int notBefore = userFederatedStorage(session).getNotBeforeOfUser(realm, userRep.getId()); userRep.setNotBefore(notBefore); if (options.isGroupsAndRolesIncluded()) { - List groups = session.userFederatedStorage().getGroupsStream(realm, id) + List groups = userFederatedStorage(session).getGroupsStream(realm, id) .map(ModelToRepresentation::buildGroupPath).collect(Collectors.toList()); userRep.setGroups(groups); } return userRep; } + + private static UserFederatedStorageProvider userFederatedStorage(KeycloakSession session) { + return session.getProvider(UserFederatedStorageProvider.class); + } } diff --git a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/BackwardsCompatibilityUserStorage.java b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/BackwardsCompatibilityUserStorage.java index f4f8ce2d09..fc6c56d737 100644 --- a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/BackwardsCompatibilityUserStorage.java +++ b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/BackwardsCompatibilityUserStorage.java @@ -48,6 +48,7 @@ import org.keycloak.models.credential.PasswordUserCredentialModel; import org.keycloak.models.utils.TimeBasedOTP; import org.keycloak.storage.StorageId; import org.keycloak.storage.UserStorageProvider; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.adapter.AbstractUserAdapterFederatedStorage; import org.keycloak.storage.user.UserLookupProvider; import org.keycloak.storage.user.UserQueryProvider; @@ -158,7 +159,7 @@ public class BackwardsCompatibilityUserStorage implements UserLookupProvider, Us users.get(translateUserName(user.getUsername())).hashedPassword = newPassword; - UserCache userCache = session.userCache(); + UserCache userCache = UserStorageUtil.userCache(session); if (userCache != null) { userCache.evict(realm, user); } diff --git a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/PassThroughFederatedUserStorageProvider.java b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/PassThroughFederatedUserStorageProvider.java index 9d44c4e9ec..3a79435d31 100644 --- a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/PassThroughFederatedUserStorageProvider.java +++ b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/PassThroughFederatedUserStorageProvider.java @@ -29,6 +29,7 @@ import org.keycloak.models.UserModel; import org.keycloak.models.credential.PasswordCredentialModel; import org.keycloak.storage.StorageId; import org.keycloak.storage.UserStorageProvider; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.adapter.AbstractUserAdapterFederatedStorage; import org.keycloak.storage.user.UserLookupProvider; @@ -84,7 +85,7 @@ public class PassThroughFederatedUserStorageProvider implements if (INITIAL_PASSWORD.equals(input.getChallengeResponse())) { return true; } - return session.userFederatedStorage().getStoredCredentialsByTypeStream(realm, user.getId(), "CLEAR_TEXT_PASSWORD") + return UserStorageUtil.userFederatedStorage(session).getStoredCredentialsByTypeStream(realm, user.getId(), "CLEAR_TEXT_PASSWORD") .map(credentialModel -> credentialModel.getSecretData()) .anyMatch(Predicate.isEqual("{\"value\":\"" + input.getChallengeResponse() + "\"}")); } @@ -95,19 +96,19 @@ public class PassThroughFederatedUserStorageProvider implements public boolean updateCredential(RealmModel realm, UserModel user, CredentialInput input) { // testing federated credential attributes if (input.getType().equals(PasswordCredentialModel.TYPE)) { - Optional existing = session.userFederatedStorage() + Optional existing = UserStorageUtil.userFederatedStorage(session) .getStoredCredentialsByTypeStream(realm, user.getId(), "CLEAR_TEXT_PASSWORD") .findFirst(); if (existing.isPresent()) { CredentialModel model = existing.get(); model.setType("CLEAR_TEXT_PASSWORD"); model.setSecretData("{\"value\":\"" + input.getChallengeResponse() + "\"}"); - session.userFederatedStorage().updateCredential(realm, user.getId(), model); + UserStorageUtil.userFederatedStorage(session).updateCredential(realm, user.getId(), model); } else { CredentialModel model = new CredentialModel(); model.setType("CLEAR_TEXT_PASSWORD"); model.setSecretData("{\"value\":\"" + input.getChallengeResponse() + "\"}"); - session.userFederatedStorage().createCredential(realm, user.getId(), model); + UserStorageUtil.userFederatedStorage(session).createCredential(realm, user.getId(), model); } return true; } @@ -116,9 +117,9 @@ public class PassThroughFederatedUserStorageProvider implements @Override public void disableCredentialType(RealmModel realm, UserModel user, String credentialType) { - session.userFederatedStorage().getStoredCredentialsByTypeStream(realm, user.getId(), "CLEAR_TEXT_PASSWORD") + UserStorageUtil.userFederatedStorage(session).getStoredCredentialsByTypeStream(realm, user.getId(), "CLEAR_TEXT_PASSWORD") .collect(Collectors.toList()) - .forEach(credModel -> session.userFederatedStorage().removeStoredCredential(realm, user.getId(), credModel.getId())); + .forEach(credModel -> UserStorageUtil.userFederatedStorage(session).removeStoredCredential(realm, user.getId(), credModel.getId())); } @Override @@ -146,7 +147,7 @@ public class PassThroughFederatedUserStorageProvider implements @Override public UserModel getUserByEmail(RealmModel realm, String email) { - Optional result = session.userFederatedStorage() + Optional result = UserStorageUtil.userFederatedStorage(session) .getUsersByUserAttributeStream(realm, AbstractUserAdapterFederatedStorage.EMAIL_ATTRIBUTE, email) .map(StorageId::new) .filter(storageId -> Objects.equals(storageId.getExternalId(), PASSTHROUGH_USERNAME)) diff --git a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/UserMapStorage.java b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/UserMapStorage.java index bb34b195ad..131024e138 100644 --- a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/UserMapStorage.java +++ b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/federation/UserMapStorage.java @@ -36,6 +36,7 @@ import org.keycloak.storage.ReadOnlyException; import org.keycloak.storage.StorageId; import org.keycloak.storage.UserStoragePrivateUtil; import org.keycloak.storage.UserStorageProvider; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.adapter.AbstractUserAdapterFederatedStorage; import org.keycloak.storage.federated.UserGroupMembershipFederatedStorage; import org.keycloak.storage.user.ImportedUserValidation; @@ -364,7 +365,7 @@ public class UserMapStorage implements UserLookupProvider.Streams, UserStoragePr if (isImportEnabled()) { return UserStoragePrivateUtil.userLocalStorage(session).searchForUserByUserAttributeStream(realm, attrName, attrValue); } else { - return session.userFederatedStorage().getUsersByUserAttributeStream(realm, attrName, attrValue) + return UserStorageUtil.userFederatedStorage(session).getUsersByUserAttributeStream(realm, attrName, attrValue) .map(userName -> createUser(realm, userName)); } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UmaRepresentationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UmaRepresentationTest.java index 85dba874b9..36d7b510d4 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UmaRepresentationTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UmaRepresentationTest.java @@ -158,7 +158,7 @@ public class UmaRepresentationTest extends AbstractResourceServerTest { AuthorizationBean authorizationBean = new AuthorizationBean(session, realm, null, session.getContext().getUri()); ClientModel client = session.getContext().getRealm().getClientByClientId("resource-server-test"); - UserModel user = session.userStorageManager().getUserByUsername(session.getContext().getRealm(), "marta"); + UserModel user = session.users().getUserByUsername(session.getContext().getRealm(), "marta"); ResourceServer resourceServer = authorization.getStoreFactory().getResourceServerStore().findByClient(client); ResourceBean resourceBean = authorizationBean.new ResourceBean( authorization.getStoreFactory().getResourceStore().findByName( diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPMultipleAttributesTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPMultipleAttributesTest.java index 20af03b39b..2548006286 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPMultipleAttributesTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPMultipleAttributesTest.java @@ -33,6 +33,7 @@ import org.keycloak.protocol.oidc.OIDCLoginProtocol; import org.keycloak.protocol.oidc.mappers.UserAttributeMapper; import org.keycloak.representations.IDToken; import org.keycloak.storage.UserStoragePrivateUtil; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.ldap.LDAPStorageProvider; import org.keycloak.storage.ldap.idm.model.LDAPObject; import org.keycloak.testsuite.ProfileAssume; @@ -117,7 +118,7 @@ public class LDAPMultipleAttributesTest extends AbstractLDAPTest { Assume.assumeTrue("User cache disabled.", isUserCacheEnabled()); testingClient.server().run(session -> { LDAPTestContext ctx = LDAPTestContext.init(session); - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); RealmModel appRealm = ctx.getRealm(); // Test user imported in local storage now @@ -133,7 +134,7 @@ public class LDAPMultipleAttributesTest extends AbstractLDAPTest { Assume.assumeTrue("User cache disabled.", isUserCacheEnabled()); testingClient.server().run(session -> { LDAPTestContext ctx = LDAPTestContext.init(session); - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); RealmModel appRealm = ctx.getRealm(); UserModel user = session.users().getUserByUsername(appRealm, "bwilson"); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersIntegrationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersIntegrationTest.java index a93238345e..7785eb1a0a 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersIntegrationTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersIntegrationTest.java @@ -52,6 +52,7 @@ import org.keycloak.storage.StorageId; import org.keycloak.storage.UserStoragePrivateUtil; import org.keycloak.storage.UserStorageProvider; import org.keycloak.storage.UserStorageProviderModel; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.ldap.LDAPConfig; import org.keycloak.storage.ldap.LDAPStorageProvider; import org.keycloak.storage.ldap.idm.model.LDAPObject; @@ -624,7 +625,7 @@ public class LDAPProvidersIntegrationTest extends AbstractLDAPTest { LDAPTestContext ctx = LDAPTestContext.init(session); RealmModel appRealm = ctx.getRealm(); - session.userCache().evict(appRealm, session.users().getUserByUsername(appRealm, "register123")); + UserStorageUtil.userCache(session).evict(appRealm, session.users().getUserByUsername(appRealm, "register123")); // See that user don't yet have any description UserModel user = session.users().getUserByUsername(appRealm, "register123"); @@ -915,7 +916,7 @@ public class LDAPProvidersIntegrationTest extends AbstractLDAPTest { testingClient.server().run(session -> { LDAPTestContext ctx = LDAPTestContext.init(session); RealmModel appRealm = ctx.getRealm(); - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); // Add custom filter again ctx.getLdapModel().getConfig().putSingle(LDAPConstants.CUSTOM_USER_SEARCH_FILTER, "(|(mail=user5@email.org)(mail=user6@email.org))"); @@ -925,7 +926,7 @@ public class LDAPProvidersIntegrationTest extends AbstractLDAPTest { testingClient.server().run(session -> { LDAPTestContext ctx = LDAPTestContext.init(session); RealmModel appRealm = ctx.getRealm(); - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); // search by id using custom filter. Must return the user UserModel testUser5 = session.users().getUserById(appRealm, user5Id); @@ -1063,7 +1064,7 @@ public class LDAPProvidersIntegrationTest extends AbstractLDAPTest { public void testSearchWithPartiallyCachedUser() { Assume.assumeTrue("User cache disabled.", isUserCacheEnabled()); testingClient.server().run(session -> { - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); }); @@ -1090,7 +1091,7 @@ public class LDAPProvidersIntegrationTest extends AbstractLDAPTest { public void testLDAPUserRefreshCache() { Assume.assumeTrue("User cache disabled.", isUserCacheEnabled()); testingClient.server().run(session -> { - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); }); testingClient.server().run(session -> { diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSyncTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSyncTest.java index a847d925c4..a988240970 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSyncTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSyncTest.java @@ -359,7 +359,7 @@ public class LDAPSyncTest extends AbstractLDAPTest { .peek(user -> System.out.println("trying to delete user: " + user.getUsername())) .collect(Collectors.toList()) .forEach(user -> { - UserCache userCache = session.userCache(); + UserCache userCache = UserStorageUtil.userCache(session); if (userCache != null) { userCache.evict(ctx.getRealm(), user); } @@ -513,7 +513,7 @@ public class LDAPSyncTest extends AbstractLDAPTest { .peek(user -> System.out.println("trying to delete user: " + user.getUsername())) .collect(Collectors.toList()) .forEach(user -> { - UserCache userCache = session.userCache(); + UserCache userCache = UserStorageUtil.userCache(session); if (userCache != null) { userCache.evict(ctx.getRealm(), user); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/noimport/LDAPMultipleAttributesNoImportTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/noimport/LDAPMultipleAttributesNoImportTest.java index c7e674aaca..f6b7b9e14d 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/noimport/LDAPMultipleAttributesNoImportTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/noimport/LDAPMultipleAttributesNoImportTest.java @@ -25,6 +25,7 @@ import org.junit.runners.MethodSorters; import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; import org.keycloak.storage.UserStoragePrivateUtil; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.testsuite.federation.ldap.LDAPMultipleAttributesTest; import org.keycloak.testsuite.federation.ldap.LDAPTestAsserts; import org.keycloak.testsuite.federation.ldap.LDAPTestContext; @@ -47,7 +48,7 @@ public class LDAPMultipleAttributesNoImportTest extends LDAPMultipleAttributesTe Assume.assumeTrue("User cache disabled.", isUserCacheEnabled()); testingClient.server().run(session -> { LDAPTestContext ctx = LDAPTestContext.init(session); - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); RealmModel appRealm = ctx.getRealm(); // Test user NOT imported in local storage now. He is available just through "session.users()" diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/noimport/LDAPRoleMappingsNoImportTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/noimport/LDAPRoleMappingsNoImportTest.java index 58bf620813..652cf57795 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/noimport/LDAPRoleMappingsNoImportTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/noimport/LDAPRoleMappingsNoImportTest.java @@ -34,6 +34,7 @@ import org.keycloak.models.RoleModel; import org.keycloak.models.UserModel; import org.keycloak.storage.UserStoragePrivateUtil; import org.keycloak.storage.UserStorageProviderModel; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.ldap.LDAPStorageProvider; import org.keycloak.storage.ldap.idm.model.LDAPObject; import org.keycloak.storage.ldap.mappers.membership.LDAPGroupMapperMode; @@ -146,7 +147,7 @@ public class LDAPRoleMappingsNoImportTest extends AbstractLDAPTest { } ); testingClient.server().run(session -> { - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); LDAPTestContext ctx = LDAPTestContext.init(session); RealmModel appRealm = ctx.getRealm(); @@ -175,7 +176,7 @@ public class LDAPRoleMappingsNoImportTest extends AbstractLDAPTest { }); testingClient.server().run(session -> { - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); LDAPTestContext ctx = LDAPTestContext.init(session); RealmModel appRealm = ctx.getRealm(); @@ -196,7 +197,7 @@ public class LDAPRoleMappingsNoImportTest extends AbstractLDAPTest { @Test public void test02WriteMappings() { testingClient.server().run(session -> { - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); LDAPTestContext ctx = LDAPTestContext.init(session); RealmModel appRealm = ctx.getRealm(); @@ -234,11 +235,11 @@ public class LDAPRoleMappingsNoImportTest extends AbstractLDAPTest { RoleModel manageAccountRole = accountApp.getRole(AccountRoles.MANAGE_ACCOUNT); RoleModel financeRole1 = financeApp.getRole("financeRole1"); john.grantRole(financeRole1); - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); }); testingClient.server().run(session -> { - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); LDAPTestContext ctx = LDAPTestContext.init(session); RealmModel appRealm = ctx.getRealm(); @@ -288,7 +289,7 @@ public class LDAPRoleMappingsNoImportTest extends AbstractLDAPTest { // Cleanup mary.deleteRoleMapping(realmRole2); mary.deleteRoleMapping(realmRole3); - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); }); } @@ -298,7 +299,7 @@ public class LDAPRoleMappingsNoImportTest extends AbstractLDAPTest { // Check user group memberships testingClient.server().run(session -> { - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); LDAPTestContext ctx = LDAPTestContext.init(session); RealmModel appRealm = ctx.getRealm(); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/ClientStorageTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/ClientStorageTest.java index 4992e2346b..7c782423a6 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/ClientStorageTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/ClientStorageTest.java @@ -143,7 +143,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST); - assertThat(session.clientStorageManager() + assertThat(session.clients() .searchClientsByClientIdStream(realm, "client", null, null) .map(ClientModel::getClientId) .collect(Collectors.toList()), @@ -153,7 +153,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { ); // test the pagination; the clients from local storage (root-url-client) are fetched first - assertThat(session.clientStorageManager() + assertThat(session.clients() .searchClientsByClientIdStream(realm, "client", 0, 1) .map(ClientModel::getClientId) .collect(Collectors.toList()), @@ -161,7 +161,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { not(hasItem(hardcodedClient)), hasItem("root-url-client")) ); - assertThat(session.clientStorageManager() + assertThat(session.clients() .searchClientsByClientIdStream(realm, "client", 1, 1) .map(ClientModel::getClientId) .collect(Collectors.toList()), @@ -179,7 +179,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { // search for clients and check hardcoded-client is not present - assertThat(session.clientStorageManager() + assertThat(session.clients() .searchClientsByClientIdStream(session.realms().getRealmByName(AuthRealm.TEST), "client", null, null) .map(ClientModel::getClientId) .collect(Collectors.toList()), diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/FederatedStorageExportImportTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/FederatedStorageExportImportTest.java index 60bfba1933..7ec595e027 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/FederatedStorageExportImportTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/FederatedStorageExportImportTest.java @@ -36,6 +36,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.RoleModel; import org.keycloak.models.credential.PasswordCredentialModel; import org.keycloak.services.managers.RealmManager; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.testsuite.AbstractAuthTest; import org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude; @@ -110,14 +111,14 @@ public class FederatedStorageExportImportTest extends AbstractAuthTest { List attrValues = new LinkedList<>(); attrValues.add("1"); attrValues.add("2"); - session.userFederatedStorage().setSingleAttribute(realm, userId, "single1", "value1"); - session.userFederatedStorage().setAttribute(realm, userId, "list1", attrValues); - session.userFederatedStorage().addRequiredAction(realm, userId, "UPDATE_PASSWORD"); + UserStorageUtil.userFederatedStorage(session).setSingleAttribute(realm, userId, "single1", "value1"); + UserStorageUtil.userFederatedStorage(session).setAttribute(realm, userId, "list1", attrValues); + UserStorageUtil.userFederatedStorage(session).addRequiredAction(realm, userId, "UPDATE_PASSWORD"); PasswordCredentialModel credential = FederatedStorageExportImportTest.getHashProvider(session, realm.getPasswordPolicy()).encodedCredential("password", realm. getPasswordPolicy().getHashIterations()); - session.userFederatedStorage().createCredential(realm, userId, credential); - session.userFederatedStorage().grantRole(realm, userId, role); - session.userFederatedStorage().joinGroup(realm, userId, group); + UserStorageUtil.userFederatedStorage(session).createCredential(realm, userId, credential); + UserStorageUtil.userFederatedStorage(session).grantRole(realm, userId, role); + UserStorageUtil.userFederatedStorage(session).joinGroup(realm, userId, group); }); final String realmId = testRealmResource().toRepresentation().getId(); @@ -145,18 +146,18 @@ public class FederatedStorageExportImportTest extends AbstractAuthTest { RoleModel role = realm.getRole("test-role"); GroupModel group = realm.getGroupById(groupId); - Assert.assertEquals(1, session.userFederatedStorage().getStoredUsersCount(realm)); - MultivaluedHashMap attributes = session.userFederatedStorage().getAttributes(realm, userId); + Assert.assertEquals(1, UserStorageUtil.userFederatedStorage(session).getStoredUsersCount(realm)); + MultivaluedHashMap attributes = UserStorageUtil.userFederatedStorage(session).getAttributes(realm, userId); Assert.assertEquals(3, attributes.size()); Assert.assertEquals("value1", attributes.getFirst("single1")); Assert.assertTrue(attributes.getList("list1").contains("1")); Assert.assertTrue(attributes.getList("list1").contains("2")); - Assert.assertTrue(session.userFederatedStorage().getRequiredActionsStream(realm, userId) + Assert.assertTrue(UserStorageUtil.userFederatedStorage(session).getRequiredActionsStream(realm, userId) .collect(Collectors.toSet()).contains("UPDATE_PASSWORD")); - Assert.assertTrue(session.userFederatedStorage().getRoleMappingsStream(realm, userId) + Assert.assertTrue(UserStorageUtil.userFederatedStorage(session).getRoleMappingsStream(realm, userId) .collect(Collectors.toSet()).contains(role)); - Assert.assertTrue(session.userFederatedStorage().getGroupsStream(realm, userId).collect(Collectors.toSet()).contains(group)); - List creds = session.userFederatedStorage().getStoredCredentialsStream(realm, userId).collect(Collectors.toList()); + Assert.assertTrue(UserStorageUtil.userFederatedStorage(session).getGroupsStream(realm, userId).collect(Collectors.toSet()).contains(group)); + List creds = UserStorageUtil.userFederatedStorage(session).getStoredCredentialsStream(realm, userId).collect(Collectors.toList()); Assert.assertEquals(1, creds.size()); Assert.assertTrue(FederatedStorageExportImportTest.getHashProvider(session, realm.getPasswordPolicy()) .verify("password", PasswordCredentialModel.createFromCredentialModel(creds.get(0)))); @@ -177,15 +178,15 @@ public class FederatedStorageExportImportTest extends AbstractAuthTest { List attrValues = new LinkedList<>(); attrValues.add("1"); attrValues.add("2"); - session.userFederatedStorage().setSingleAttribute(realm, userId, "single1", "value1"); - session.userFederatedStorage().setAttribute(realm, userId, "list1", attrValues); - session.userFederatedStorage().addRequiredAction(realm, userId, "UPDATE_PASSWORD"); + UserStorageUtil.userFederatedStorage(session).setSingleAttribute(realm, userId, "single1", "value1"); + UserStorageUtil.userFederatedStorage(session).setAttribute(realm, userId, "list1", attrValues); + UserStorageUtil.userFederatedStorage(session).addRequiredAction(realm, userId, "UPDATE_PASSWORD"); PasswordCredentialModel credential = FederatedStorageExportImportTest.getHashProvider(session, realm.getPasswordPolicy()).encodedCredential("password", realm. getPasswordPolicy().getHashIterations()); - session.userFederatedStorage().createCredential(realm, userId, credential); - session.userFederatedStorage().grantRole(realm, userId, role); - session.userFederatedStorage().joinGroup(realm, userId, group); - session.userFederatedStorage().setNotBeforeForUser(realm, userId, 50); + UserStorageUtil.userFederatedStorage(session).createCredential(realm, userId, credential); + UserStorageUtil.userFederatedStorage(session).grantRole(realm, userId, role); + UserStorageUtil.userFederatedStorage(session).joinGroup(realm, userId, group); + UserStorageUtil.userFederatedStorage(session).setNotBeforeForUser(realm, userId, 50); }); final String realmId = testRealmResource().toRepresentation().getId(); @@ -214,19 +215,19 @@ public class FederatedStorageExportImportTest extends AbstractAuthTest { RoleModel role = realm.getRole("test-role"); GroupModel group = realm.getGroupById(groupId); - Assert.assertEquals(1, session.userFederatedStorage().getStoredUsersCount(realm)); - MultivaluedHashMap attributes = session.userFederatedStorage().getAttributes(realm, userId); + Assert.assertEquals(1, UserStorageUtil.userFederatedStorage(session).getStoredUsersCount(realm)); + MultivaluedHashMap attributes = UserStorageUtil.userFederatedStorage(session).getAttributes(realm, userId); Assert.assertEquals(3, attributes.size()); Assert.assertEquals("value1", attributes.getFirst("single1")); Assert.assertTrue(attributes.getList("list1").contains("1")); Assert.assertTrue(attributes.getList("list1").contains("2")); - Assert.assertTrue(session.userFederatedStorage().getRequiredActionsStream(realm, userId) + Assert.assertTrue(UserStorageUtil.userFederatedStorage(session).getRequiredActionsStream(realm, userId) .collect(Collectors.toSet()).contains("UPDATE_PASSWORD")); - Assert.assertTrue(session.userFederatedStorage().getRoleMappingsStream(realm, userId) + Assert.assertTrue(UserStorageUtil.userFederatedStorage(session).getRoleMappingsStream(realm, userId) .collect(Collectors.toSet()).contains(role)); - Assert.assertTrue(session.userFederatedStorage().getGroupsStream(realm, userId).collect(Collectors.toSet()).contains(group)); - Assert.assertEquals(50, session.userFederatedStorage().getNotBeforeOfUser(realm, userId)); - List creds = session.userFederatedStorage().getStoredCredentialsStream(realm, userId).collect(Collectors.toList()); + Assert.assertTrue(UserStorageUtil.userFederatedStorage(session).getGroupsStream(realm, userId).collect(Collectors.toSet()).contains(group)); + Assert.assertEquals(50, UserStorageUtil.userFederatedStorage(session).getNotBeforeOfUser(realm, userId)); + List creds = UserStorageUtil.userFederatedStorage(session).getStoredCredentialsStream(realm, userId).collect(Collectors.toList()); Assert.assertEquals(1, creds.size()); Assert.assertTrue(FederatedStorageExportImportTest.getHashProvider(session, realm.getPasswordPolicy()) .verify("password", PasswordCredentialModel.createFromCredentialModel(creds.get(0)))); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/GroupStorageTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/GroupStorageTest.java index 49cce598ad..ef295c1886 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/GroupStorageTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/GroupStorageTest.java @@ -95,7 +95,7 @@ public class GroupStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST); - assertThat(session.groupStorageManager() + assertThat(session.groups() .searchForGroupByName(realm, "group", null, null).stream() .map(GroupModel::getName) .collect(Collectors.toList()), @@ -113,7 +113,7 @@ public class GroupStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST); // search for groups and check hardcoded-group is not present - assertThat(session.groupStorageManager() + assertThat(session.groups() .searchForGroupByName(realm, "group", null, null).stream() .map(GroupModel::getName) .collect(Collectors.toList()), diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/RoleStorageTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/RoleStorageTest.java index b583f76edd..20980a9ed2 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/RoleStorageTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/RoleStorageTest.java @@ -102,7 +102,7 @@ public class RoleStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST); - assertThat(session.roleStorageManager() + assertThat(session.roles() .searchForRolesStream(realm, "role", null, null) .map(RoleModel::getName) .collect(Collectors.toList()), @@ -120,7 +120,7 @@ public class RoleStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST); // search for roles and check hardcoded-role is not present - assertThat(session.roleStorageManager() + assertThat(session.roles() .searchForRolesStream(realm, "role", null, null) .map(RoleModel::getName) .collect(Collectors.toList()), diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/UserStorageFailureTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/UserStorageFailureTest.java index 2f25fe0efb..a7e3e081c4 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/UserStorageFailureTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/UserStorageFailureTest.java @@ -45,6 +45,7 @@ import org.keycloak.services.managers.RealmManager; import org.keycloak.storage.UserStoragePrivateUtil; import org.keycloak.storage.UserStorageProvider; import org.keycloak.storage.UserStorageProviderModel; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.testsuite.AbstractTestRealmKeycloakTest; import org.keycloak.testsuite.AssertEvents; import org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude; @@ -224,7 +225,7 @@ public class UserStorageFailureTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST); UserModel user = session.users().getUserByUsername(realm, username); - session.userCache().evict(realm, user); + UserStorageUtil.userCache(session).evict(realm, user); }); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/UserStorageTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/UserStorageTest.java index 9e5c225f9f..c784ea2e91 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/UserStorageTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/UserStorageTest.java @@ -36,6 +36,7 @@ import org.keycloak.storage.CacheableStorageProviderModel.CachePolicy; import org.keycloak.storage.StorageId; import org.keycloak.storage.UserStoragePrivateUtil; import org.keycloak.storage.UserStorageProvider; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.testsuite.AbstractAuthTest; import org.keycloak.testsuite.admin.ApiUtil; import org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude; @@ -169,7 +170,7 @@ public class UserStorageTest extends AbstractAuthTest { UserModel user = session.users().getUserByUsername(realm, "thor"); if (user != null) { UserStoragePrivateUtil.userLocalStorage(session).removeUser(realm, user); - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); } //we need to clear userPasswords and userGroups from UserMapStorageFactory @@ -528,7 +529,7 @@ public class UserStorageTest extends AbstractAuthTest { // let's clear cache testingClient.server().run(session -> { - session.userCache().clear(); + UserStorageUtil.userCache(session).clear(); }); diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserModelTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserModelTest.java index 8d106426c9..1e38b204e6 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserModelTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserModelTest.java @@ -28,6 +28,7 @@ import org.keycloak.models.UserProvider; import org.keycloak.storage.UserStorageProvider; import org.keycloak.storage.UserStorageProviderFactory; import org.keycloak.storage.UserStorageProviderModel; +import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.user.UserRegistrationProvider; import java.util.ArrayList; import java.util.HashSet; @@ -183,8 +184,8 @@ public class UserModelTest extends KeycloakModelTest { }); withRealm(realmId, (session, realm) -> { - if (session.userCache() != null) { - session.userCache().clear(); + if (UserStorageUtil.userCache(session) != null) { + UserStorageUtil.userCache(session).clear(); } final UserModel user = session.users().getUserByUsername(realm, "user-A"); assertThat("User should not be found in the main store", user, Matchers.nullValue()); @@ -234,8 +235,8 @@ public class UserModelTest extends KeycloakModelTest { // because they are not present in any storage. However, when we get users by id cache may still be hit // since it is not alerted in any way when users are removed from external provider. Hence we need to clear // the cache manually. - if (session.userCache() != null) { - session.userCache().clear(); + if (UserStorageUtil.userCache(session) != null) { + UserStorageUtil.userCache(session).clear(); } return null; });