Search in sources :

Example 6 with ComponentFactory

use of org.keycloak.component.ComponentFactory 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 7 with ComponentFactory

use of org.keycloak.component.ComponentFactory in project keycloak by keycloak.

the class ComponentResource method toComponentTypeRepresentation.

private ComponentTypeRepresentation toComponentTypeRepresentation(ProviderFactory factory, ComponentModel parent) {
    ComponentTypeRepresentation rep = new ComponentTypeRepresentation();
    rep.setId(factory.getId());
    ComponentFactory componentFactory = (ComponentFactory) factory;
    rep.setHelpText(componentFactory.getHelpText());
    List<ProviderConfigProperty> props;
    Map<String, Object> metadata;
    if (factory instanceof SubComponentFactory) {
        props = ((SubComponentFactory) factory).getConfigProperties(realm, parent);
        metadata = ((SubComponentFactory) factory).getTypeMetadata(realm, parent);
    } else {
        props = componentFactory.getConfigProperties();
        metadata = componentFactory.getTypeMetadata();
    }
    List<ConfigPropertyRepresentation> propReps = ModelToRepresentation.toRepresentation(props);
    rep.setProperties(propReps);
    rep.setMetadata(metadata);
    return rep;
}
Also used : ComponentTypeRepresentation(org.keycloak.representations.idm.ComponentTypeRepresentation) SubComponentFactory(org.keycloak.component.SubComponentFactory) SubComponentFactory(org.keycloak.component.SubComponentFactory) ComponentFactory(org.keycloak.component.ComponentFactory) ProviderConfigProperty(org.keycloak.provider.ProviderConfigProperty) ConfigPropertyRepresentation(org.keycloak.representations.idm.ConfigPropertyRepresentation)

Example 8 with ComponentFactory

use of org.keycloak.component.ComponentFactory in project keycloak by keycloak.

the class UserStorageManager method onCreate.

@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);
}
Also used : UserStorageSyncManager(org.keycloak.services.managers.UserStorageSyncManager) ComponentFactory(org.keycloak.component.ComponentFactory)

Example 9 with ComponentFactory

use of org.keycloak.component.ComponentFactory in project keycloak by keycloak.

the class UserStorageManager method onUpdate.

@Override
public void onUpdate(KeycloakSession session, RealmModel realm, ComponentModel oldModel, ComponentModel newModel) {
    ComponentFactory factory = ComponentUtil.getComponentFactory(session, newModel);
    if (!(factory instanceof UserStorageProviderFactory))
        return;
    UserStorageProviderModel old = new UserStorageProviderModel(oldModel);
    UserStorageProviderModel newP = new UserStorageProviderModel(newModel);
    if (old.getChangedSyncPeriod() != newP.getChangedSyncPeriod() || old.getFullSyncPeriod() != newP.getFullSyncPeriod() || old.isImportEnabled() != newP.isImportEnabled()) {
        new UserStorageSyncManager().notifyToRefreshPeriodicSync(session, realm, new UserStorageProviderModel(newModel), false);
    }
}
Also used : UserStorageSyncManager(org.keycloak.services.managers.UserStorageSyncManager) ComponentFactory(org.keycloak.component.ComponentFactory)

Example 10 with ComponentFactory

use of org.keycloak.component.ComponentFactory in project keycloak by keycloak.

the class ComponentUtil method notifyUpdated.

public static void notifyUpdated(KeycloakSession session, RealmModel realm, ComponentModel oldModel, ComponentModel newModel) {
    ComponentFactory factory = getComponentFactory(session, newModel);
    factory.onUpdate(session, realm, oldModel, newModel);
    if (factory instanceof UserStorageProviderFactory) {
        ((OnUpdateComponent) session.userStorageManager()).onUpdate(session, realm, oldModel, newModel);
    }
}
Also used : OnUpdateComponent(org.keycloak.storage.OnUpdateComponent) ComponentFactory(org.keycloak.component.ComponentFactory) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory)

Aggregations

ComponentFactory (org.keycloak.component.ComponentFactory)12 ProviderConfigProperty (org.keycloak.provider.ProviderConfigProperty)3 HashMap (java.util.HashMap)2 ComponentTypeRepresentation (org.keycloak.representations.idm.ComponentTypeRepresentation)2 UserStorageSyncManager (org.keycloak.services.managers.UserStorageSyncManager)2 UserStorageProviderFactory (org.keycloak.storage.UserStorageProviderFactory)2 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 ComponentValidationException (org.keycloak.component.ComponentValidationException)1 SubComponentFactory (org.keycloak.component.SubComponentFactory)1 ModelDuplicateException (org.keycloak.models.ModelDuplicateException)1 MapComponentEntity (org.keycloak.models.map.realm.entity.MapComponentEntity)1 ConfiguredProvider (org.keycloak.provider.ConfiguredProvider)1 ProviderFactory (org.keycloak.provider.ProviderFactory)1 Spi (org.keycloak.provider.Spi)1 ConfigPropertyRepresentation (org.keycloak.representations.idm.ConfigPropertyRepresentation)1 ProviderRepresentation (org.keycloak.representations.info.ProviderRepresentation)1 SpiInfoRepresentation (org.keycloak.representations.info.SpiInfoRepresentation)1 OnCreateComponent (org.keycloak.storage.OnCreateComponent)1 OnUpdateComponent (org.keycloak.storage.OnUpdateComponent)1