Created
October 14, 2015 16:03
-
-
Save auniverseaway/e84114315d5b26de607e to your computer and use it in GitHub Desktop.
Create a group and user then assign user to group using Jackrabbit API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void createAuthorGroupAndUser(ResourceResolver resolver) { | |
try { | |
Session session = resolver.adaptTo(Session.class); | |
if (session != null && session instanceof JackrabbitSession) { | |
// Get our User Manager | |
UserManager userManager = ((JackrabbitSession) session).getUserManager(); | |
ValueFactory valueFactory = session.getValueFactory(); | |
// Create the Authors group if it doesn't exist already. | |
Authorizable authors = userManager.getAuthorizable("authors"); | |
if (authors == null) { | |
authors = userManager.createGroup("authors"); | |
authors.setProperty("displayName", valueFactory.createValue("Authors")); | |
} | |
// Create the default author if it doesn't already exist. | |
Authorizable author = userManager.getAuthorizable("author"); | |
if(author == null) { | |
author = userManager.createUser("author", "letMeIn"); | |
author.setProperty("displayName", valueFactory.createValue("Default Author")); | |
} | |
// Add author member to authors group | |
((Group) authors).addMember(author); | |
// Save our session | |
session.save(); | |
} | |
} catch (RepositoryException e) { | |
LOGGER.error("Could not get the session", e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
API Docs: https://jackrabbit.apache.org/api/2.4/org/apache/jackrabbit/api/security/user/package-summary.html