title: How to configure LDAP in Keycloak dynamically
body: <p>I am using Keycloak as UAA for my project, and I am able to create a new realm in keycloak dynamically via java code. Now i would like to add LDAP support for the relam which is created in keycloak.Is there any option to do it dynamically using java ?</p>
  <p>I able to drill down and identified the attributes that i need to set. basically i created ComponentRepresentation object with all ldap values and added into the realm,</p>
  <pre><code>ComponentRepresentation ldapComponentRep = new ComponentRepresentation();
  
  String componentId = UUID.randomUUID().toString();
  
  ldapComponentRep.setId(componentId);
  ldapComponentRep.setName(&quot;testldap&quot;);
  ldapComponentRep.setProviderId(&quot;testldap&quot;);
  ldapComponentRep.setParentId(&quot;realmname&quot;);
  ldapComponentRep.setProviderType(&quot;org.keycloak.storage.UserStorageProvider&quot;);
  
  MultivaluedHashMap config = new MultivaluedHashMap&lt;&gt;();
  
  config.putSingle(&quot;fullSyncPeriod&quot;, &quot;-1&quot;);
  config.putSingle(&quot;pagination&quot;, &quot;true&quot;);
  config.putSingle(&quot;connectionPooling&quot;, &quot;true&quot;);
  config.putSingle(&quot;usersDn&quot;, &quot;o=758ldifojencdjks,dc=test,dc=com&quot;);
  config.putSingle(&quot;cachePolicy&quot;, &quot;DEFAULT&quot;);
  config.putSingle(&quot;useKerberosForPasswordAuthentication&quot;,&quot;false&quot;);
  config.putSingle(&quot;importEnabled&quot;,&quot;true&quot;);
  config.putSingle(&quot;enabled&quot;,&quot;true&quot;);
  config.putSingle(&quot;bindCredential&quot;,&quot;*********&quot;);
  config.putSingle(&quot;usernameLDAPAttribute&quot;,&quot;uid&quot;);
  config.putSingle(&quot;bindDn&quot;,&quot;uid=ldap.connector,ou=Users,o=758ldifojencdjks,dc=test,dc=com&quot;);
  config.putSingle(&quot;changedSyncPeriod&quot;,&quot;-1&quot;);
  config.putSingle(&quot;vendor&quot;,&quot;other&quot;);
  config.putSingle(&quot;uuidLDAPAttribute&quot;,&quot;entryUUID&quot;);
  config.putSingle(&quot;allowKerberosAuthentication&quot;,&quot;false&quot;);
  config.putSingle(&quot;connectionUrl&quot;,&quot;ldap://ldap.test.com:389&quot;);
  config.putSingle(&quot;syncRegistrations&quot;,&quot;false&quot;);
  config.putSingle(&quot;authType&quot;,&quot;simple&quot;);
  config.putSingle(&quot;debug&quot;,&quot;false&quot;);
  config.putSingle(&quot;searchScope&quot;,&quot;2&quot;);
  config.putSingle(&quot;useTruststoreSpi&quot;,&quot;ldapsOnly&quot;);
  config.putSingle(&quot;priority&quot;,&quot;1&quot;);
  config.putSingle(&quot;trustEmail&quot;,&quot;false&quot;);
  config.putSingle(&quot;userObjectClasses&quot;,&quot;inetOrgPerson, organizationalPerson&quot;);
  config.putSingle(&quot;rdnLDAPAttribute&quot;,&quot;uid&quot;);
  config.putSingle(&quot;editMode&quot;,&quot;READ_ONLY&quot;);
  config.putSingle(&quot;validatePasswordPolicy&quot;,&quot;false&quot;);
  config.putSingle(&quot;batchSizeForSync&quot;,&quot;1000&quot;);
  
  ldapComponentRep.setConfig(config);
  
  keycloak.realms().realm(&quot;realmname&quot;).components().add(ldapComponentRep).getStatus();
  
  </code></pre>
  <p>The output of the last line 201 but there is no exception and the configuration are not saved either.</p>
  <p>Please help me to resolve this issue.</p>
  <p>Thanks in Advance,</p>