Skip to content

Instantly share code, notes, and snippets.

@fjunior87
Created April 25, 2016 01:15
Show Gist options
  • Save fjunior87/1366b08f60983026b4bb4957962f45d2 to your computer and use it in GitHub Desktop.
Save fjunior87/1366b08f60983026b4bb4957962f45d2 to your computer and use it in GitHub Desktop.
Example of Sling/JackRabbit SystemUser Creation
public void createSystemUser(BundleContext bundleContext) {
ServiceReference SlingRepositoryFactoryReference = bundleContext.getServiceReference(SlingRepository.class.getName());
SlingRepository repository = (SlingRepository)bundleContext.getService(SlingRepositoryFactoryReference);
Session session = null;
try {
session = repository.loginAdministrative(null);
UserManager usrMgr = ((JackrabbitSession)session).getUserManager();
usrMgr.createSystemUser("usersSystemUser", null);
} catch (RepositoryException e) {
LOGGER.error("Error while creating user", e);
} finally {
if(session != null && session.isLive()) {
session.logout();
session = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment