code: @Nonnull
      public static JcrPackageManager getPackageManager(@Nonnull Packaging packaging, @Nonnull SlingHttpServletRequest request) throws RepositoryException {
          ResourceResolver resolver = request.getResourceResolver();
          Session session = resolver.adaptTo(Session.class);
          if (session != null) {
              return packaging.getPackageManager(session);
          } else {
              throw new RepositoryException("can't adapt resolver to session"); // should be impossible
          }
      }
docs: Retrieves a package manager for the JCR session.