0 Replies Latest reply on Jun 17, 2013 10:44 AM by sivaprasadreddys

    Is it possible to delete user in onUserSync callback method?

    sivaprasadreddys Level 1

      Hi,

       

        I've setup LADP and accessing the CQ using LADP authentication. I've been logging user info in 'onUserSync' callback method. But as per our requirement I don't want to create CQ user at some conditions. So I'm trying to remove user in 'onUserSync' callback method. But I'm getting exception while removing user at following statement.

       

      userManager.getAuthorizable(userId).remove();

       

       

      Here is my sample code:

       

      public void onUserSync(User user,

      Map<String, Value[]> attributes,

      ValueFactory vf)

      throws RepositoryException{

      log.debug("####### Begin: onUserSync #######");

       

       

              Bundle b = FrameworkUtil.getBundle(getClass());

              BundleContext bc  = b.getBundleContext();

              ServiceReference sr  = bc.getServiceReference(Repository.class.getName());

              try{

                  Repository repository = (Repository) bc.getService(sr);

                  Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()), "crx.default");

       

       

                  log.debug("============= Session created ===========");

                 final JackrabbitSession jackrabbitSession = (JackrabbitSession) session;

                 log.debug("============= jackrabbit Session created ===========");

                 UserManager userManager = jackrabbitSession.getUserManager();

       

       

                            log.debug("User Name:{}",user.getID());

                      String userId=user.getID();

                      log.debug("Ldap Sync User Name:{}",userId);

       

                      jackrabbitSession.save();

                     log.debug("Jackrabbit session is saved before removing the gruop..");

                    userManager.getAuthorizable(userId).remove();

                   log.debug("User has been removed..");

                            jackrabbitSession.save();

                 og.debug("Jackrabbit session is saved after removing the gruop..");

                  jackrabbitSession.logout();

       

              }catch(Exception e)

              {

                  e.printStackTrace();

                  log.debug("Exception:{}",e.getMessage());

              }

                    finally {

                  if(sr != null){

                      bc.ungetService(sr);

                  }

              }

       

       

       

       

      log.debug("####### End: onUserSync   #######");

       

       

      }

       

       

      Quick Responses would be more helpful..

       

       

      Thanks

       

      Siva