Search in sources :

Example 1 with ComponentFactory

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

the class MapRealmAdapter method importComponentModel.

@Override
public ComponentModel importComponentModel(ComponentModel model) {
    try {
        ComponentFactory componentFactory = ComponentUtil.getComponentFactory(session, model);
        if (componentFactory == null && System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) {
            throw new IllegalArgumentException("Invalid component type");
        }
        componentFactory.validateConfiguration(session, this, model);
    } catch (IllegalArgumentException | ComponentValidationException e) {
        if (System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) {
            throw e;
        }
    }
    if (entity.getComponent(model.getId()).isPresent()) {
        throw new ModelDuplicateException("A Component with given id already exists");
    }
    MapComponentEntity component = MapComponentEntity.fromModel(model);
    if (model.getParentId() == null) {
        component.setParentId(getId());
    }
    entity.addComponent(component);
    return MapComponentEntity.toModel(component);
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) MapComponentEntity(org.keycloak.models.map.realm.entity.MapComponentEntity) ComponentFactory(org.keycloak.component.ComponentFactory) ModelDuplicateException(org.keycloak.models.ModelDuplicateException)

Example 2 with ComponentFactory

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

the class ComponentUtil method getComponentConfigProperties.

public static Map<String, ProviderConfigProperty> getComponentConfigProperties(KeycloakSession session, String providerType, String providerId) {
    try {
        ComponentFactory componentFactory = getComponentFactory(session, providerType, providerId);
        List<ProviderConfigProperty> l = componentFactory.getConfigProperties();
        Map<String, ProviderConfigProperty> properties = new HashMap<>();
        for (ProviderConfigProperty p : l) {
            properties.put(p.getName(), p);
        }
        List<ProviderConfigProperty> common = componentFactory.getCommonProviderConfigProperties();
        for (ProviderConfigProperty p : common) {
            properties.put(p.getName(), p);
        }
        return properties;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) ComponentFactory(org.keycloak.component.ComponentFactory) ProviderConfigProperty(org.keycloak.provider.ProviderConfigProperty)

Example 3 with ComponentFactory

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

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

the class RealmAdapter method importComponentModel.

@Override
public ComponentModel importComponentModel(ComponentModel model) {
    ComponentFactory componentFactory = null;
    try {
        componentFactory = ComponentUtil.getComponentFactory(session, model);
        if (componentFactory == null && System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) {
            throw new IllegalArgumentException("Invalid component type");
        }
        componentFactory.validateConfiguration(session, this, model);
    } catch (Exception e) {
        if (System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) {
            throw e;
        }
    }
    ComponentEntity c = new ComponentEntity();
    if (model.getId() == null) {
        c.setId(KeycloakModelUtils.generateId());
    } else {
        c.setId(model.getId());
    }
    c.setName(model.getName());
    c.setParentId(model.getParentId());
    if (model.getParentId() == null) {
        c.setParentId(this.getId());
        model.setParentId(this.getId());
    }
    c.setProviderType(model.getProviderType());
    c.setProviderId(model.getProviderId());
    c.setSubType(model.getSubType());
    c.setRealm(realm);
    em.persist(c);
    realm.getComponents().add(c);
    setConfig(model, c);
    model.setId(c.getId());
    return model;
}
Also used : ComponentFactory(org.keycloak.component.ComponentFactory)

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