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);
}
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);
}
}
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);
}
}
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);
}
}
}
});
}
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;
}
Aggregations