KEYCLOAK-4220

This commit is contained in:
Bill Burke 2017-01-13 11:45:48 -05:00
parent 1e51ade620
commit 6aee6b0c46
5 changed files with 52 additions and 2 deletions

View file

@ -25,6 +25,8 @@ import org.keycloak.provider.Provider;
import org.keycloak.provider.ProviderConfigProperty;
import org.keycloak.provider.ProviderFactory;
import org.keycloak.representations.idm.ComponentRepresentation;
import org.keycloak.storage.OnCreateComponent;
import org.keycloak.storage.UserStorageProviderFactory;
import java.util.HashMap;
import java.util.List;
@ -88,6 +90,9 @@ public class ComponentUtil {
public static void notifyCreated(KeycloakSession session, RealmModel realm, ComponentModel model) {
ComponentFactory factory = getComponentFactory(session, model);
factory.onCreate(session, realm, model);
if (factory instanceof UserStorageProviderFactory) {
((OnCreateComponent)session.userStorageManager()).onCreate(session, realm, model);
}
}
public static void notifyUpdated(KeycloakSession session, RealmModel realm, ComponentModel model) {
ComponentFactory factory = getComponentFactory(session, model);

View file

@ -0,0 +1,32 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other 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.storage;
import org.keycloak.component.ComponentModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
/**
* Callback for component creation. Only hardcoded classes like UserStorageManager implement it. In future we
* may allow anybody to implement this interface.
*
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface OnCreateComponent {
void onCreate(KeycloakSession session, RealmModel realm, ComponentModel model);
}

View file

@ -50,6 +50,7 @@ public interface ComponentFactory<CreatedType, ProviderType extends Provider> ex
}
default
void onUpdate(KeycloakSession session, RealmModel realm, ComponentModel model) {

View file

@ -75,7 +75,6 @@ public class UserStorageSyncManager {
});
}
private class Holder {
ExecutionResult<SynchronizationResult> result;
}

View file

@ -19,6 +19,7 @@ package org.keycloak.storage;
import org.jboss.logging.Logger;
import org.keycloak.common.util.reflections.Types;
import org.keycloak.component.ComponentFactory;
import org.keycloak.component.ComponentModel;
import org.keycloak.models.ClientModel;
import org.keycloak.models.FederatedIdentityModel;
@ -36,6 +37,8 @@ import org.keycloak.models.UserProvider;
import org.keycloak.models.cache.CachedUserModel;
import org.keycloak.models.cache.OnUserCache;
import org.keycloak.models.cache.UserCache;
import org.keycloak.models.utils.ComponentUtil;
import org.keycloak.services.managers.UserStorageSyncManager;
import org.keycloak.storage.federated.UserFederatedStorageProvider;
import org.keycloak.storage.user.ImportedUserValidation;
import org.keycloak.storage.user.UserBulkUpdateProvider;
@ -57,7 +60,7 @@ import static org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class UserStorageManager implements UserProvider, OnUserCache {
public class UserStorageManager implements UserProvider, OnUserCache, OnCreateComponent {
private static final Logger logger = Logger.getLogger(UserStorageManager.class);
@ -606,6 +609,7 @@ public class UserStorageManager implements UserProvider, OnUserCache {
if (!component.getProviderType().equals(UserStorageProvider.class.getName())) return;
localStorage().preRemove(realm, component);
if (getFederatedStorage() != null) getFederatedStorage().preRemove(realm, component);
new UserStorageSyncManager().notifyToRefreshPeriodicSync(session, realm, new UserStorageProviderModel(component), true);
}
@ -627,5 +631,14 @@ public class UserStorageManager implements UserProvider, OnUserCache {
public void close() {
}
@Override
public void onCreate(KeycloakSession session, RealmModel realm, ComponentModel model) {
ComponentFactory factory = ComponentUtil.getComponentFactory(session, model);
if (!(factory instanceof UserStorageProviderFactory)) return;
new UserStorageSyncManager().notifyToRefreshPeriodicSync(session, realm, new UserStorageProviderModel(model), false);
}
}