Q:

Getting a JackrabbitSession object from a JCR session object

My goal is to get a JackrabbitSession from a JCR session in a standalone java application. I spent hours on it but can't find a working example.
A few post like this one for example are implying it is possible to cast from a JCR session to a JackrabbitSession as follows but it actually does not work and throws a ClassCastException.
Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()), "crx.default");

JackrabbitSession js = (JackrabbitSession) session;
final UserManager userManager = session.getUserManager();
final User user = userManager.createUser(userName, userName);
session.save();

The reason I want the native JackrabbitSession is because as in the above code I want to access the UserManager object. In my use case the JCR repository resides in an AEM instance on which I would like to create/delete users.
Thx in advance

A:

You can get UserManager by adapting resourceResolver :
userManager = resolver.adaptTo(UserManager.class); 

