Search in sources :

Example 1 with ProviderFactory

use of org.keycloak.provider.ProviderFactory in project keycloak by keycloak.

the class QuarkusKeycloakSessionFactory method init.

@Override
public void init() {
    // Component factory must be initialized first, so that postInit in other factories can use component factories
    updateComponentFactoryProviderFactory();
    if (componentFactoryPF != null) {
        componentFactoryPF.postInit(this);
    }
    for (Map<String, ProviderFactory> f : factoriesMap.values()) {
        for (ProviderFactory factory : f.values()) {
            if (factory != componentFactoryPF) {
                factory.postInit(this);
            }
        }
    }
    AdminPermissions.registerListener(this);
    // make the session factory ready for hot deployment
    ProviderManagerRegistry.SINGLETON.setDeployer(this);
}
Also used : ProviderFactory(org.keycloak.provider.ProviderFactory)

Example 2 with ProviderFactory

use of org.keycloak.provider.ProviderFactory in project keycloak by keycloak.

the class MigrateTo1_3_0 method migrateLDAPProviders.

private void migrateLDAPProviders(KeycloakSession session, RealmModel realm) {
    realm.getUserStorageProvidersStream().forEachOrdered(fedProvider -> {
        if (fedProvider.getProviderId().equals(LDAPConstants.LDAP_PROVIDER)) {
            // copy don't want to muck with cache
            fedProvider = new UserStorageProviderModel(fedProvider);
            MultivaluedHashMap<String, String> config = fedProvider.getConfig();
            // Update config properties for LDAP federation provider
            if (config.get(LDAPConstants.SEARCH_SCOPE) == null) {
                config.putSingle(LDAPConstants.SEARCH_SCOPE, String.valueOf(SearchControls.SUBTREE_SCOPE));
            }
            List<String> usersDn = config.remove("userDnSuffix");
            if (usersDn != null && !usersDn.isEmpty() && config.getFirst(LDAPConstants.USERS_DN) == null) {
                config.put(LDAPConstants.USERS_DN, usersDn);
            }
            String usernameLdapAttribute = config.getFirst(LDAPConstants.USERNAME_LDAP_ATTRIBUTE);
            if (usernameLdapAttribute != null && config.getFirst(LDAPConstants.RDN_LDAP_ATTRIBUTE) == null) {
                if (usernameLdapAttribute.equalsIgnoreCase(LDAPConstants.SAM_ACCOUNT_NAME)) {
                    config.putSingle(LDAPConstants.RDN_LDAP_ATTRIBUTE, LDAPConstants.CN);
                } else {
                    config.putSingle(LDAPConstants.RDN_LDAP_ATTRIBUTE, usernameLdapAttribute);
                }
            }
            if (config.getFirst(LDAPConstants.UUID_LDAP_ATTRIBUTE) == null) {
                String uuidAttrName = LDAPConstants.getUuidAttributeName(config.getFirst(LDAPConstants.VENDOR));
                config.putSingle(LDAPConstants.UUID_LDAP_ATTRIBUTE, uuidAttrName);
            }
            realm.updateComponent(fedProvider);
            // Create default mappers for LDAP
            if (realm.getComponentsStream(fedProvider.getId()).count() == 0) {
                ProviderFactory ldapFactory = session.getKeycloakSessionFactory().getProviderFactory(UserStorageProvider.class, LDAPConstants.LDAP_PROVIDER);
                if (ldapFactory != null) {
                    ((ComponentFactory) ldapFactory).onCreate(session, realm, fedProvider);
                }
            }
        }
    });
}
Also used : ProviderFactory(org.keycloak.provider.ProviderFactory) ComponentFactory(org.keycloak.component.ComponentFactory) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 3 with ProviderFactory

use of org.keycloak.provider.ProviderFactory in project keycloak by keycloak.

the class KeycloakModelTest method createKeycloakSessionFactory.

/**
 * Creates a fresh initialized {@link KeycloakSessionFactory}. The returned factory uses configuration
 * local to the thread that calls this method, allowing for per-thread customization. This in turn allows
 * testing of several parallel session factories which can be used to simulate several servers
 * running in parallel.
 * @return
 */
public static KeycloakSessionFactory createKeycloakSessionFactory() {
    int factoryIndex = FACTORY_COUNT.incrementAndGet();
    String threadName = Thread.currentThread().getName();
    CONFIG.reset();
    CONFIG.spi(ComponentFactorySpi.NAME).provider(DefaultComponentFactoryProviderFactory.PROVIDER_ID).config("cachingForced", "true");
    MODEL_PARAMETERS.forEach(m -> m.updateConfig(CONFIG));
    LOG.debugf("Creating factory %d in %s using the following configuration:\n    %s", factoryIndex, threadName, CONFIG);
    DefaultKeycloakSessionFactory res = new DefaultKeycloakSessionFactory() {

        @Override
        protected boolean isEnabled(ProviderFactory factory, Scope scope) {
            return super.isEnabled(factory, scope) && isFactoryAllowed(factory);
        }

        @Override
        protected Map<Class<? extends Provider>, Map<String, ProviderFactory>> loadFactories(ProviderManager pm) {
            spis.removeIf(s -> !isSpiAllowed(s));
            return super.loadFactories(pm);
        }

        private boolean isSpiAllowed(Spi s) {
            return MODEL_PARAMETERS.stream().anyMatch(p -> p.isSpiAllowed(s));
        }

        private boolean isFactoryAllowed(ProviderFactory factory) {
            return MODEL_PARAMETERS.stream().anyMatch(p -> p.isFactoryAllowed(factory));
        }

        @Override
        public String toString() {
            return "KeycloakSessionFactory " + factoryIndex + " (from " + threadName + " thread)";
        }
    };
    res.init();
    res.publish(new PostMigrationEvent());
    return res;
}
Also used : DefaultKeycloakSessionFactory(org.keycloak.services.DefaultKeycloakSessionFactory) Scope(org.keycloak.Config.Scope) DefaultExecutorsProviderFactory(org.keycloak.executors.DefaultExecutorsProviderFactory) ComponentFactoryProviderFactory(org.keycloak.component.ComponentFactoryProviderFactory) DefaultAuthorizationProviderFactory(org.keycloak.authorization.DefaultAuthorizationProviderFactory) DefaultComponentFactoryProviderFactory(org.keycloak.services.DefaultComponentFactoryProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) DeploymentStateProviderFactory(org.keycloak.models.DeploymentStateProviderFactory) ProviderManager(org.keycloak.provider.ProviderManager) BeforeClass(org.junit.BeforeClass) Map(java.util.Map) ComponentFactorySpi(org.keycloak.component.ComponentFactorySpi) ClientScopeSpi(org.keycloak.models.ClientScopeSpi) ExecutorsSpi(org.keycloak.executors.ExecutorsSpi) DBLockSpi(org.keycloak.models.dblock.DBLockSpi) ClusterSpi(org.keycloak.cluster.ClusterSpi) UserSpi(org.keycloak.models.UserSpi) Spi(org.keycloak.provider.Spi) UserLoginFailureSpi(org.keycloak.models.UserLoginFailureSpi) TimerSpi(org.keycloak.timer.TimerSpi) ClientSpi(org.keycloak.models.ClientSpi) StoreFactorySpi(org.keycloak.authorization.store.StoreFactorySpi) RealmSpi(org.keycloak.models.RealmSpi) GroupSpi(org.keycloak.models.GroupSpi) UserSessionSpi(org.keycloak.models.UserSessionSpi) DeploymentStateSpi(org.keycloak.models.DeploymentStateSpi) EventStoreSpi(org.keycloak.events.EventStoreSpi) AuthorizationSpi(org.keycloak.authorization.AuthorizationSpi) RoleSpi(org.keycloak.models.RoleSpi) Provider(org.keycloak.provider.Provider) PostMigrationEvent(org.keycloak.models.utils.PostMigrationEvent)

Example 4 with ProviderFactory

use of org.keycloak.provider.ProviderFactory in project keycloak by keycloak.

the class FeatureDeployerUtil method createDeploymentInfo.

private static KeycloakDeploymentInfo createDeploymentInfo(Map<ProviderFactory, Spi> factories) {
    KeycloakDeploymentInfo di = KeycloakDeploymentInfo.create();
    for (Map.Entry<ProviderFactory, Spi> factory : factories.entrySet()) {
        ProviderFactory pf = factory.getKey();
        Class<? extends Spi> spiClass = factory.getValue().getClass();
        di.addProvider(spiClass, pf);
    }
    return di;
}
Also used : KeycloakDeploymentInfo(org.keycloak.provider.KeycloakDeploymentInfo) EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) Spi(org.keycloak.provider.Spi)

Example 5 with ProviderFactory

use of org.keycloak.provider.ProviderFactory in project keycloak by keycloak.

the class FeatureDeployerUtil method deployFactoriesAfterFeatureEnabled.

public static void deployFactoriesAfterFeatureEnabled(Profile.Feature feature) {
    ProviderManager manager = deployersCache.get(feature);
    if (manager == null) {
        // Need to figure which provider factories were enabled after feature was enabled. Create deployer based on it and save it to the cache
        Map<ProviderFactory, Spi> factoriesBeforeEnable = initializer.remove(feature);
        Map<ProviderFactory, Spi> factoriesAfterEnable = loadEnabledEnvironmentFactories();
        Map<ProviderFactory, Spi> factories = getFactoriesDependentOnFeature(factoriesBeforeEnable, factoriesAfterEnable);
        logger.infof("New factories when enabling feature '%s': %s", feature, factories.keySet());
        KeycloakDeploymentInfo di = createDeploymentInfo(factories);
        manager = new ProviderManager(di, FeatureDeployerUtil.class.getClassLoader());
        deployersCache.put(feature, manager);
    }
    ProviderManagerRegistry.SINGLETON.deploy(manager);
}
Also used : KeycloakDeploymentInfo(org.keycloak.provider.KeycloakDeploymentInfo) ProviderManager(org.keycloak.provider.ProviderManager) EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) Spi(org.keycloak.provider.Spi)

Aggregations

ProviderFactory (org.keycloak.provider.ProviderFactory)21 EnvironmentDependentProviderFactory (org.keycloak.provider.EnvironmentDependentProviderFactory)13 Spi (org.keycloak.provider.Spi)10 HashMap (java.util.HashMap)9 Map (java.util.Map)8 ComponentFactoryProviderFactory (org.keycloak.component.ComponentFactoryProviderFactory)8 Provider (org.keycloak.provider.Provider)7 KeycloakDeploymentInfo (org.keycloak.provider.KeycloakDeploymentInfo)6 ProviderManager (org.keycloak.provider.ProviderManager)6 List (java.util.List)4 Logger (org.jboss.logging.Logger)4 Config (org.keycloak.Config)4 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)4 ComponentFactoryProvider (org.keycloak.component.ComponentFactoryProvider)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3