Loading ...
Sorry, an error occurred while loading the content.

Re: Custom LDAP user mapping to existing CRX groups using com.day.crx.security.ldap.

Expand Messages
  • Maria Petzold
    For now, the workaround I found for this is accessing the repository via jndi, as per
    Message 1 of 3 , Feb 2, 2012
    View Source
    • 0 Attachment
      For now, the workaround I found for this is accessing the repository via jndi, as per
      http://dev.day.com/docs/en/crx/current/developing/accessing_the_crx.html#Accessing a Repository via JNDI

      code:

      public class LDAPCallbackHandlerImpl implements Callback{
      @Override
      public void onUserSync(User userToBeSynched, Map<String, Value[]>
      attributes,
      ValueFactory valueFactory) throws RepositoryException {
      //TODO: Find a way to not hardcode this
      String userName = "admin";
      String password = "admin";
      SimpleCredentials creds = new SimpleCredentials(userName,
      password.toCharArray());
      try {
      log.info("about to log in into repo via JNDI");
      Repository jackrabbitRepo = JcrUtils.getRepository("jndi://"
      + "crx"
      + "?org.apache.jackrabbit.repository.jndi.name=crx"
      + "&java.naming.factory.initial"
      + "=com.day.util.jndi.provider.MemoryInitialContextFactory"
      + "&java.naming.provider.url=http://jcr.day.com");
      JackrabbitSession jackrabbitSession = (JackrabbitSession)
      jackrabbitRepo.login(creds, "crx.default");
      org.apache.jackrabbit.api.security.user.UserManager um =
      jackrabbitSession.getUserManager();
      org.apache.jackrabbit.api.security.user.Authorizable authorizable
      = um.getAuthorizable("administrators");
      log.info("authorizable " + authorizable.getID());
      Group group = (Group) authorizable;
      log.info("group " + group.getID());
      group.addMember(userToBeSynched);
      jackrabbitSession.save();
      jackrabbitSession.logout();
      } catch (PathNotFoundException e) {
      log.error("", e);
      } catch (NoSuchWorkspaceException e) {
      log.info("no such workspace");
      } catch (RepositoryException e) {
      log.info("repo exception");
      } catch (Exception e) {
      log.info("couldn't get into repository " + e.getMessage());
      }
      }
      }}
    • sogalapalli
      Hi Maria, I do have similar requirement and used the same code provided by you. But I m getting following exception: sample.ldap.LdapSync Sample
      Message 2 of 3 , Apr 22 1:24 PM
      View Source
      • 0 Attachment
        Hi Maria, I do have similar requirement and used the same code provided by you. But I'm getting following exception:

        sample.ldap.LdapSync Sample LadapException:Unable to access a repository with the following settings:
        org.apache.jackrabbit.repository.uri: jndi://crx?org.apache.jackrabbit.repository.jndi.name=crx&java.naming.factory.initial=com.day.util.jndi.provider.MemoryInitialContextFactory&java.naming.provider.url=http://jcr.day.com
        The following RepositoryFactory classes were consulted:
        com.day.crx.core.CRXRepositoryFactory: declined
        org.apache.jackrabbit.core.RepositoryFactoryImpl: declined
        Perhaps the repository you are trying to access is not available at the moment.

        --- In jcr-crx@yahoogroups.com, "Maria Petzold" <maria.petzold@...> wrote:
        >
        >
        >
        >
        > For now, the workaround I found for this is accessing the repository via jndi, as per
        > http://dev.day.com/docs/en/crx/current/developing/accessing_the_crx.html#Accessing a Repository via JNDI
        >
        > code:
        >
        > public class LDAPCallbackHandlerImpl implements Callback{
        > @Override
        > public void onUserSync(User userToBeSynched, Map<String, Value[]>
        > attributes,
        > ValueFactory valueFactory) throws RepositoryException {
        > //TODO: Find a way to not hardcode this
        > String userName = "admin";
        > String password = "admin";
        > SimpleCredentials creds = new SimpleCredentials(userName,
        > password.toCharArray());
        > try {
        > log.info("about to log in into repo via JNDI");
        > Repository jackrabbitRepo = JcrUtils.getRepository("jndi://"
        > + "crx"
        > + "?org.apache.jackrabbit.repository.jndi.name=crx"
        > + "&java.naming.factory.initial"
        > + "=com.day.util.jndi.provider.MemoryInitialContextFactory"
        > + "&java.naming.provider.url=http://jcr.day.com");
        > JackrabbitSession jackrabbitSession = (JackrabbitSession)
        > jackrabbitRepo.login(creds, "crx.default");
        > org.apache.jackrabbit.api.security.user.UserManager um =
        > jackrabbitSession.getUserManager();
        > org.apache.jackrabbit.api.security.user.Authorizable authorizable
        > = um.getAuthorizable("administrators");
        > log.info("authorizable " + authorizable.getID());
        > Group group = (Group) authorizable;
        > log.info("group " + group.getID());
        > group.addMember(userToBeSynched);
        > jackrabbitSession.save();
        > jackrabbitSession.logout();
        > } catch (PathNotFoundException e) {
        > log.error("", e);
        > } catch (NoSuchWorkspaceException e) {
        > log.info("no such workspace");
        > } catch (RepositoryException e) {
        > log.info("repo exception");
        > } catch (Exception e) {
        > log.info("couldn't get into repository " + e.getMessage());
        > }
        > }
        > }}
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.