Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-4806

MgnlUserManager is missing method to delete user

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 4.5.6
    • core, security

      Users cannot be deleted anymore. MgnlUser.getUserNode() is deprecated in a harsh way (throwing an UnsupportedOperationException) and its JavaDoc links to wrong replacement methods. When looking at the user manager classes, no methods to delete users can be found and the methods that could help you get the job done are protected. The following ugly hack solves the problem, but... seriously?

      Ugly hack to delete a user
              UserManager userManager = SecuritySupport.Factory.getInstance().getUserManager(userManagerName);
              // get the existing user
              MgnlUser user = (MgnlUser) userManager.getUser("some_username");
              if (user != null) {
                  Method method = MgnlUserManager.class.getDeclaredMethod("getRepositoryName", new Class[0]);
                  method.setAccessible(true);
                  String repositoryName = (String) method.invoke(userManager, new Object[0]);
                  Session session = MgnlContext.getJCRSession(repositoryName);
                  method = MgnlUserManager.class.getDeclaredMethod("findPrincipalNode", String.class, Session.class);
                  method.setAccessible(true);
                  Node userNode = (Node) method.invoke(userManager, user.getName(), session);
                  if (activateUserAfterModification()) {
                      // Are we on the author instance?
                      if (ServerConfiguration.getInstance().isAdmin()) {
                          deactivateUser(user);
                      }
                  }
                  userNode.remove();
                  session.save();
              }
      

        Acceptance criteria

              Unassigned Unassigned
              will Will Scheidegger
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD

                    Estimated:
                    Original Estimate - 0.25d
                    0.25d
                    Remaining:
                    Remaining Estimate - 0.25d
                    0.25d
                    Logged:
                    Time Spent - Not Specified
                    Not Specified