4 Replies Latest reply on Aug 20, 2012 10:06 AM by Sastry Pola

    LDAP user synchronization using scheduler

    Sastry Pola

      hello,

       

      Is there any OOTB functionality available to synchronize users from LDAP into CQ5?

       

      If not, please help me to proceed in below scenario.

       

      I have written a scheduler, which will pull the user details from LDAP and create the user into CQ using UserManager. This process is not creating the user same as system creates when user logs in. I am finding difficulty in setting attribute rep:principalName and process is throwing below given exception.

       

      com.wem.ldap.ScheduledPeriodicJob RepositoryException while getting session javax.jcr.nodetype.ConstraintViolationException: Attempt to modify protected property rep:principalName of User 'xxxx'

              at org.apache.jackrabbit.core.security.user.AuthorizableImpl.checkProtectedProperty(Authoriz ableImpl.java:447)

              at org.apache.jackrabbit.core.security.user.AuthorizableImpl.setProperty(AuthorizableImpl.ja va:174)

              at org.apache.jackrabbit.core.security.user.UserImpl.setProperty(UserImpl.java:38)

              at com.wem.ldap.ScheduledPeriodicJob.run(ScheduledPeriodicJob.java:136)

              at org.apache.sling.commons.scheduler.impl.QuartzJobExecutor.execute(QuartzJobExecutor.java: 56)

              at org.quartz.core.JobRunShell.run(JobRunShell.java:213)

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

              at java.lang.Thread.run(Thread.java:662)

       

      here is the code I have written

       

      resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

      session = resourceResolver.adaptTo(Session.class);

       

      JackrabbitSession jackrabbitSession = (JackrabbitSession) session;

       

      UserManager manager = jackrabbitSession.getUserManager();

       

      user = manager.createUser("xxxx", "xxxxx");

       

      value = valueFactory.createValue("xxxx");

      user.setProperty("cq:first-name", value);

       

      value = valueFactory.createValue("xxxx");

      user.setProperty("cq:last-name", value);

       

      value = valueFactory.createValue("xxx@xxxx.com");

      user.setProperty("rep:e-mail", value);

       

      value = valueFactory.createValue("CN=xxxx,OU=Users,DC=company,DC=com");

      user.setProperty("rep:principalName", value);

       

      jackrabbitSession.save();

       

      can you please provide the code block to create user, which needs to get authenticated against ldap password.

       

      Thanks,

      Sastry