> invalidationMap = new HashMap<>();
private DatastoreProvider datastoreProvider;
- private UserStorageManager userStorageManager;
private UserCredentialStoreManager userCredentialStorageManager;
private UserSessionProvider sessionProvider;
private UserLoginFailureProvider userLoginFailureProvider;
@@ -217,21 +215,14 @@ public class DefaultKeycloakSession implements KeycloakSession {
return groups();
}
-
@Override
public UserProvider userStorageManager() {
- if (userStorageManager == null) userStorageManager = new UserStorageManager(this);
- return userStorageManager;
+ return users();
}
@Override
public UserProvider users() {
- UserCache cache = getProvider(UserCache.class);
- if (cache != null) {
- return cache;
- } else {
- return userStorageManager();
- }
+ return getDatastoreProvider().users();
}
@Override
diff --git a/services/src/main/java/org/keycloak/services/managers/RealmManager.java b/services/src/main/java/org/keycloak/services/managers/RealmManager.java
index 472b701023..306eb04ca8 100755
--- a/services/src/main/java/org/keycloak/services/managers/RealmManager.java
+++ b/services/src/main/java/org/keycloak/services/managers/RealmManager.java
@@ -52,6 +52,7 @@ import org.keycloak.representations.idm.RealmEventsConfigRepresentation;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.idm.RoleRepresentation;
import org.keycloak.sessions.AuthenticationSessionProvider;
+import org.keycloak.storage.LegacyStoreSyncEvent;
import org.keycloak.services.clientregistration.policy.DefaultClientRegistrationPolicies;
import java.util.Collections;
@@ -271,10 +272,7 @@ public class RealmManager {
}
// Refresh periodic sync tasks for configured storageProviders
- UserStorageSyncManager storageSync = new UserStorageSyncManager();
- realm.getUserStorageProvidersStream()
- .forEachOrdered(provider -> storageSync.notifyToRefreshPeriodicSync(session, realm, provider, true));
-
+ LegacyStoreSyncEvent.fire(session, realm, true);
}
return removed;
}
@@ -588,9 +586,7 @@ public class RealmManager {
}
// Refresh periodic sync tasks for configured storageProviders
- UserStorageSyncManager storageSync = new UserStorageSyncManager();
- realm.getUserStorageProvidersStream()
- .forEachOrdered(provider -> storageSync.notifyToRefreshPeriodicSync(session, realm, provider, false));
+ LegacyStoreSyncEvent.fire(session, realm, false);
setupAuthorizationServices(realm);
setupClientRegistrations(realm);
diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
index 81cff07d05..7cb6993819 100644
--- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
+++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
@@ -45,15 +45,8 @@ import org.keycloak.services.error.KcUnrecognizedPropertyExceptionHandler;
import org.keycloak.services.filters.KeycloakSecurityHeadersFilter;
import org.keycloak.services.managers.ApplianceBootstrap;
import org.keycloak.services.managers.RealmManager;
-import org.keycloak.services.managers.UserStorageSyncManager;
import org.keycloak.services.resources.admin.AdminRoot;
-import org.keycloak.services.scheduled.ClearExpiredClientInitialAccessTokens;
-import org.keycloak.services.scheduled.ClearExpiredEvents;
-import org.keycloak.services.scheduled.ClearExpiredUserSessions;
-import org.keycloak.services.scheduled.ClusterAwareScheduledTaskRunner;
-import org.keycloak.services.scheduled.ScheduledTaskRunner;
import org.keycloak.services.util.ObjectMapperResolver;
-import org.keycloak.timer.TimerProvider;
import org.keycloak.transaction.JtaTransactionManagerLookup;
import org.keycloak.util.JsonSerialization;
@@ -156,9 +149,7 @@ public class KeycloakApplication extends Application {
});
- sessionFactory.publish(new PostMigrationEvent());
-
- setupScheduledTasks(sessionFactory);
+ sessionFactory.publish(new PostMigrationEvent(sessionFactory));
}
protected void shutdown() {
@@ -236,21 +227,6 @@ public class KeycloakApplication extends Application {
return factory;
}
- public static void setupScheduledTasks(final KeycloakSessionFactory sessionFactory) {
- long interval = Config.scope("scheduled").getLong("interval", 900L) * 1000;
-
- KeycloakSession session = sessionFactory.create();
- try {
- TimerProvider timer = session.getProvider(TimerProvider.class);
- timer.schedule(new ClusterAwareScheduledTaskRunner(sessionFactory, new ClearExpiredEvents(), interval), interval, "ClearExpiredEvents");
- timer.schedule(new ClusterAwareScheduledTaskRunner(sessionFactory, new ClearExpiredClientInitialAccessTokens(), interval), interval, "ClearExpiredClientInitialAccessTokens");
- timer.schedule(new ScheduledTaskRunner(sessionFactory, new ClearExpiredUserSessions()), interval, ClearExpiredUserSessions.TASK_NAME);
- new UserStorageSyncManager().bootstrapPeriodic(sessionFactory, timer);
- } finally {
- session.close();
- }
- }
-
public static KeycloakSessionFactory getSessionFactory() {
return sessionFactory;
}
diff --git a/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java b/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java
index 5559092f86..b65284a614 100644
--- a/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java
+++ b/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java
@@ -112,10 +112,11 @@ import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.managers.LDAPServerCapabilitiesManager;
import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.managers.ResourceAdminManager;
-import org.keycloak.services.managers.UserStorageSyncManager;
+import org.keycloak.services.resources.admin.ext.AdminRealmResourceProvider;
import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator;
import org.keycloak.services.resources.admin.permissions.AdminPermissionManagement;
import org.keycloak.services.resources.admin.permissions.AdminPermissions;
+import org.keycloak.storage.LegacyStoreSyncEvent;
import org.keycloak.utils.ProfileHelper;
import org.keycloak.utils.ReservedCharValidator;
@@ -436,9 +437,7 @@ public class RealmAdminResource {
RepresentationToModel.updateRealm(rep, realm, session);
// Refresh periodic sync tasks for configured federationProviders
- UserStorageSyncManager usersSyncManager = new UserStorageSyncManager();
- realm.getUserStorageProvidersStream().forEachOrdered(fedProvider ->
- usersSyncManager.notifyToRefreshPeriodicSync(session, realm, fedProvider, false));
+ LegacyStoreSyncEvent.fire(session, realm, false);
// This populates the map in DefaultKeycloakContext to be used when treating the event
session.getContext().getUri();
@@ -531,12 +530,18 @@ public class RealmAdminResource {
}
- @Path("user-storage")
- public UserStorageProviderResource userStorage() {
- UserStorageProviderResource fed = new UserStorageProviderResource(realm, auth, adminEvent);
- ResteasyProviderFactory.getInstance().injectProperties(fed);
- //resourceContext.initResource(fed);
- return fed;
+ @Path("{extension}")
+ public Object extension(@PathParam("extension") String extension) {
+ AdminRealmResourceProvider provider = session.getProvider(AdminRealmResourceProvider.class, extension);
+ if (provider != null) {
+ Object resource = provider.getResource(session, realm, auth, adminEvent);
+ if (resource != null) {
+ ResteasyProviderFactory.getInstance().injectProperties(resource);
+ return resource;
+ }
+ }
+
+ throw new NotFoundException();
}
@Path("authentication")
diff --git a/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceProvider.java b/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceProvider.java
new file mode 100644
index 0000000000..8ca009acec
--- /dev/null
+++ b/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceProvider.java
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2022 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.keycloak.services.resources.admin.ext;
+
+import org.keycloak.models.KeycloakSession;
+import org.keycloak.models.RealmModel;
+import org.keycloak.provider.Provider;
+import org.keycloak.services.resources.admin.AdminEventBuilder;
+import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator;
+
+/**
+ * A {@link AdminRealmResourceProvider} creates JAX-RS sub-resource instances for paths relative
+ * to Realm's RESTful Admin API that could not be resolved by the server.
+ */
+public interface AdminRealmResourceProvider extends Provider {
+
+ /**
+ *
Returns a JAX-RS resource instance.
+ *
+ * @return a JAX-RS sub-resource instance
+ */
+ Object getResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth,
+ AdminEventBuilder adminEvent);
+
+}
diff --git a/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceProviderFactory.java b/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceProviderFactory.java
new file mode 100644
index 0000000000..7e89d92d3d
--- /dev/null
+++ b/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceProviderFactory.java
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2022 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.keycloak.services.resources.admin.ext;
+
+import org.keycloak.provider.ProviderFactory;
+
+/**
+ *
A factory that creates {@link AdminRealmResourceProvider} instances.
+ */
+public interface AdminRealmResourceProviderFactory extends ProviderFactory {
+
+}
\ No newline at end of file
diff --git a/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceSpi.java b/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceSpi.java
new file mode 100644
index 0000000000..93c2ca21a3
--- /dev/null
+++ b/services/src/main/java/org/keycloak/services/resources/admin/ext/AdminRealmResourceSpi.java
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2022 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.keycloak.services.resources.admin.ext;
+
+import org.keycloak.provider.Provider;
+import org.keycloak.provider.ProviderFactory;
+import org.keycloak.provider.Spi;
+
+/**
+ * A {@link Spi} to plug additional sub-resources to Realms' RESTful Admin API.
+ *
+ *
Implementors can use this {@link Spi} to provide additional services to the mentioned API and extend Keycloak capabilities by
+ * creating JAX-RS sub-resources for paths not known by the server.
+ */
+public class AdminRealmResourceSpi implements Spi {
+
+ @Override
+ public boolean isInternal() {
+ return true;
+ }
+
+ @Override
+ public String getName() {
+ return "admin-realm-restapi-extension";
+ }
+
+ @Override
+ public Class extends Provider> getProviderClass() {
+ return AdminRealmResourceProvider.class;
+ }
+
+ @Override
+ public Class extends ProviderFactory>> getProviderFactoryClass() {
+ return AdminRealmResourceProviderFactory.class;
+ }
+}
diff --git a/services/src/main/resources/META-INF/services/org.keycloak.provider.Spi b/services/src/main/resources/META-INF/services/org.keycloak.provider.Spi
index 703057b3e9..f1dbb02f44 100755
--- a/services/src/main/resources/META-INF/services/org.keycloak.provider.Spi
+++ b/services/src/main/resources/META-INF/services/org.keycloak.provider.Spi
@@ -26,4 +26,5 @@ org.keycloak.protocol.saml.preprocessor.SamlAuthenticationPreprocessorSpi
org.keycloak.encoding.ResourceEncodingSpi
org.keycloak.protocol.oidc.grants.ciba.channel.AuthenticationChannelSpi
org.keycloak.protocol.oidc.grants.ciba.resolvers.CIBALoginUserResolverSpi
-org.keycloak.protocol.oidc.rar.AuthorizationRequestParserSpi
\ No newline at end of file
+org.keycloak.protocol.oidc.rar.AuthorizationRequestParserSpi
+org.keycloak.services.resources.admin.ext.AdminRealmResourceSpi
diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPRoleMappingsTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPRoleMappingsTest.java
index bd884688b3..edfdc67db5 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPRoleMappingsTest.java
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPRoleMappingsTest.java
@@ -32,7 +32,8 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserModel;
import org.keycloak.representations.idm.ComponentRepresentation;
-import org.keycloak.services.managers.UserStorageSyncManager;
+import org.keycloak.storage.managers.UserStorageSyncManager;
+import org.keycloak.storage.UserStoragePrivateUtil;
import org.keycloak.storage.UserStorageProviderModel;
import org.keycloak.storage.ldap.LDAPStorageProvider;
import org.keycloak.storage.ldap.idm.model.LDAPObject;
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 b46f75fe72..882cf8e8ed 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
@@ -40,7 +40,9 @@ import org.keycloak.models.cache.UserCache;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.representations.idm.ComponentRepresentation;
import org.keycloak.representations.idm.SynchronizationResultRepresentation;
-import org.keycloak.services.managers.UserStorageSyncManager;
+import org.keycloak.storage.managers.UserStorageSyncManager;
+import org.keycloak.storage.UserStoragePrivateUtil;
+import org.keycloak.storage.UserStorageUtil;
import org.keycloak.storage.ldap.LDAPStorageProvider;
import org.keycloak.storage.ldap.LDAPStorageProviderFactory;
import org.keycloak.storage.ldap.LDAPUtils;
diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/KeycloakModelTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/KeycloakModelTest.java
index d049319140..24c674d468 100644
--- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/KeycloakModelTest.java
+++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/KeycloakModelTest.java
@@ -51,6 +51,8 @@ import org.keycloak.provider.ProviderManager;
import org.keycloak.provider.Spi;
import org.keycloak.services.DefaultComponentFactoryProviderFactory;
import org.keycloak.services.DefaultKeycloakSessionFactory;
+import org.keycloak.storage.DatastoreProviderFactory;
+import org.keycloak.storage.DatastoreSpi;
import org.keycloak.timer.TimerSpi;
import com.google.common.collect.ImmutableSet;
@@ -227,6 +229,7 @@ public abstract class KeycloakModelTest {
.add(UserLoginFailureSpi.class)
.add(UserSessionSpi.class)
.add(UserSpi.class)
+ .add(DatastoreSpi.class)
.build();
private static final Set> ALLOWED_FACTORIES = ImmutableSet.>builder()
@@ -234,6 +237,7 @@ public abstract class KeycloakModelTest {
.add(DefaultAuthorizationProviderFactory.class)
.add(DefaultExecutorsProviderFactory.class)
.add(DeploymentStateProviderFactory.class)
+ .add(DatastoreProviderFactory.class)
.build();
protected static final List MODEL_PARAMETERS;
@@ -312,7 +316,7 @@ public abstract class KeycloakModelTest {
}
};
res.init();
- res.publish(new PostMigrationEvent());
+ res.publish(new PostMigrationEvent(res));
return res;
}
diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserSyncTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserSyncTest.java
index 336791dc55..b6b5d2b0c3 100644
--- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserSyncTest.java
+++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserSyncTest.java
@@ -9,7 +9,8 @@ import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmProvider;
import org.keycloak.models.UserProvider;
-import org.keycloak.services.managers.UserStorageSyncManager;
+import org.keycloak.storage.managers.UserStorageSyncManager;
+import org.keycloak.storage.UserStoragePrivateUtil;
import org.keycloak.storage.UserStorageProvider;
import org.keycloak.storage.UserStorageProviderFactory;
import org.keycloak.storage.UserStorageProviderModel;