Search in sources :

Example 1 with UserStorageProviderFactory

use of org.keycloak.storage.UserStorageProviderFactory in project keycloak by keycloak.

the class ComponentUtil method notifyCreated.

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);
    }
}
Also used : OnCreateComponent(org.keycloak.storage.OnCreateComponent) ComponentFactory(org.keycloak.component.ComponentFactory) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory)

Example 2 with UserStorageProviderFactory

use of org.keycloak.storage.UserStorageProviderFactory in project keycloak by keycloak.

the class UserStorageProvidersTestUtils method getStorageProvider.

public static UserStorageProvider getStorageProvider(KeycloakSession session, RealmModel realm, String componentId) {
    ComponentModel model = realm.getComponent(componentId);
    if (model == null)
        return null;
    UserStorageProviderModel storageModel = new UserStorageProviderModel(model);
    UserStorageProviderFactory factory = (UserStorageProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(UserStorageProvider.class, model.getProviderId());
    if (factory == null) {
        throw new ModelException("Could not find UserStorageProviderFactory for: " + model.getProviderId());
    }
    return getStorageProviderInstance(session, storageModel, factory);
}
Also used : UserStorageProvider(org.keycloak.storage.UserStorageProvider) ModelException(org.keycloak.models.ModelException) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory) ComponentModel(org.keycloak.component.ComponentModel) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 3 with UserStorageProviderFactory

use of org.keycloak.storage.UserStorageProviderFactory in project keycloak by keycloak.

the class UserModelTest method getUserFederationInstance.

private UserStorageProvider getUserFederationInstance(KeycloakSession session, final RealmModel realm) throws RuntimeException {
    UserStorageProvider instance = (UserStorageProvider) session.getAttribute(userFederationId);
    if (instance == null) {
        ComponentModel model = realm.getComponent(userFederationId);
        UserStorageProviderFactory factory = (UserStorageProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(UserStorageProvider.class, model.getProviderId());
        instance = factory.create(session, model);
        if (instance == null) {
            throw new RuntimeException("UserStorageProvideFactory (of type " + factory.getClass().getName() + ") produced a null instance");
        }
        session.enlistForClose(instance);
        session.setAttribute(userFederationId, instance);
    }
    return instance;
}
Also used : UserStorageProvider(org.keycloak.storage.UserStorageProvider) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory) ComponentModel(org.keycloak.component.ComponentModel)

Example 4 with UserStorageProviderFactory

use of org.keycloak.storage.UserStorageProviderFactory in project keycloak by keycloak.

the class UserSyncTest method createEnvironment.

@Override
public void createEnvironment(KeycloakSession s) {
    inComittedTransaction(session -> {
        RealmModel realm = session.realms().createRealm("realm");
        realm.setDefaultRole(session.roles().addRealmRole(realm, Constants.DEFAULT_ROLES_ROLE_PREFIX + "-" + realm.getName()));
        this.realmId = realm.getId();
    });
    getParameters(UserStorageProviderModel.class).forEach(fs -> inComittedTransaction(session -> {
        if (userFederationId != null || !fs.isImportEnabled())
            return;
        RealmModel realm = session.realms().getRealm(realmId);
        fs.setParentId(realmId);
        ComponentModel res = realm.addComponentModel(fs);
        // Check if the provider implements ImportSynchronization interface
        UserStorageProviderFactory userStorageProviderFactory = (UserStorageProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(UserStorageProvider.class, res.getProviderId());
        if (!ImportSynchronization.class.isAssignableFrom(userStorageProviderFactory.getClass())) {
            return;
        }
        userFederationId = res.getId();
        log.infof("Added %s user federation provider: %s", fs.getName(), res.getId());
    }));
    assumeThat("Cannot run UserSyncTest because there is no user federation provider that supports sync", userFederationId, notNullValue());
}
Also used : RealmModel(org.keycloak.models.RealmModel) IntStream(java.util.stream.IntStream) CoreMatchers.is(org.hamcrest.CoreMatchers.is) RealmModel(org.keycloak.models.RealmModel) Assume.assumeThat(org.junit.Assume.assumeThat) LDAPStorageProvider(org.keycloak.storage.ldap.LDAPStorageProvider) UserStorageProvider(org.keycloak.storage.UserStorageProvider) LDAPTestUtils(org.keycloak.testsuite.util.LDAPTestUtils) Constants(org.keycloak.models.Constants) Matchers(org.hamcrest.Matchers) KeycloakSession(org.keycloak.models.KeycloakSession) Test(org.junit.Test) LDAPStorageProviderFactory(org.keycloak.storage.ldap.LDAPStorageProviderFactory) UserStorageSyncManager(org.keycloak.services.managers.UserStorageSyncManager) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) ClusterProvider(org.keycloak.cluster.ClusterProvider) UserProvider(org.keycloak.models.UserProvider) ImportSynchronization(org.keycloak.storage.user.ImportSynchronization) RealmProvider(org.keycloak.models.RealmProvider) ComponentModel(org.keycloak.component.ComponentModel) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel) SynchronizationResult(org.keycloak.storage.user.SynchronizationResult) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory) ComponentModel(org.keycloak.component.ComponentModel) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 5 with UserStorageProviderFactory

use of org.keycloak.storage.UserStorageProviderFactory in project keycloak by keycloak.

the class UserStorageSyncManager method notifyToRefreshPeriodicSync.

// Ensure all cluster nodes are notified
public void notifyToRefreshPeriodicSync(KeycloakSession session, RealmModel realm, UserStorageProviderModel provider, boolean removed) {
    UserStorageProviderFactory factory = (UserStorageProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(UserStorageProvider.class, provider.getProviderId());
    if (!(factory instanceof ImportSynchronization) || !provider.isImportEnabled()) {
        return;
    }
    final ClusterProvider cp = session.getProvider(ClusterProvider.class);
    if (cp != null) {
        UserStorageProviderClusterEvent event = UserStorageProviderClusterEvent.createEvent(removed, realm.getId(), provider);
        cp.notify(USER_STORAGE_TASK_KEY, event, false, ClusterProvider.DCNotify.ALL_DCS);
    }
}
Also used : UserStorageProvider(org.keycloak.storage.UserStorageProvider) ClusterProvider(org.keycloak.cluster.ClusterProvider) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory) ImportSynchronization(org.keycloak.storage.user.ImportSynchronization)

Aggregations

UserStorageProviderFactory (org.keycloak.storage.UserStorageProviderFactory)8 UserStorageProvider (org.keycloak.storage.UserStorageProvider)6 ClusterProvider (org.keycloak.cluster.ClusterProvider)4 ImportSynchronization (org.keycloak.storage.user.ImportSynchronization)4 ComponentModel (org.keycloak.component.ComponentModel)3 KeycloakSession (org.keycloak.models.KeycloakSession)3 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)3 ComponentFactory (org.keycloak.component.ComponentFactory)2 KeycloakSessionTask (org.keycloak.models.KeycloakSessionTask)2 UserStorageProviderModel (org.keycloak.storage.UserStorageProviderModel)2 IntStream (java.util.stream.IntStream)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers (org.hamcrest.Matchers)1 Assume.assumeThat (org.junit.Assume.assumeThat)1 Test (org.junit.Test)1 Constants (org.keycloak.models.Constants)1 ModelException (org.keycloak.models.ModelException)1 RealmModel (org.keycloak.models.RealmModel)1