I was looking for a concise way to work with users and groups in Sling. Because, "everything is content," it's easy to use Sling's REST API to create a user like any other node, but things get a little dicey when you want a bit more flexibility. Enter the Jackrabbit API...

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
  } catch (RepositoryException e) {
      LOGGER.error("Could not get the session", e);

More Reading

Jackrabbit Wiki - User Management

Jackrabbit API - org.apache.jackrabbit.api.security.user


Trace AEM Bundle Issues

August, 28 2015

There comes a point where you need to triage why a bundle isn't behaving as you would expect. The simplest way I've found is to setup a logger. A logger has many advantages over tailing logs/error.log...

  • You can target a specific bundle. No need to grep.
  • You can leave the generic logger on something less frequent like 'Information'.
  • This is likely what you'll be sending if you end up talking to Adobe support.

On to setting up a logger for a specific bundle...

  1. Open Console: http://localhost:4502/system/console/configMgr
  2. Find the bundle PID you want to trace. In our case, we want to trace com.adobe.granite.auth.saml
  3. Add a new Logger entry at "Apache Sling Logging Logger"
    • Set the Log Level: Trace
    • Set the Log File Location: logs/saml-error.log
    • Specify your Bundle PID: com.adobe.granite.auth.saml
  4. Go tail it via terminal: tail -f logs/saml-error.log

Bundle Trace 1 Bundle Trace 3

Update to SVG Component

August, 24 2015

The SVG component has been updated with a contribution from Gabriel Walt. The HTML has been cleaned up and simplified.

Go get latest from here.


A Year Ago

August, 12 2015

It was a year ago today that I flew to San Francisco to learn AEM. 

I had never written a line of Java or JSP before and I was learning 5.6.1 in hopes to apply that knowledge to our 6.0 rollout. 

Here I am a year later having met some amazing people and learned some amazing things along the way. This very blog was dedicated to what I learned and it's now sitting on Sling itself. 

Needless to say, I'm looking forward to many more years working in AEM.