Hi @mailyn_tmo ,
When you create a new folder in AEM DAM, it inherits the permissions of its parent folder. If the parent is open to everyone, the new folder will also be visible to all users. AEM does not automatically apply custom permissions when new folders are created, so you need to implement a mechanism to handle this.
The most maintainable way is to use a workflow that triggers whenever a new folder is created under a specific path. For example, if you create a folder under /content/dam/promo, the workflow can apply the correct ACLs (Access Control Lists) and assign permissions to the right group. This is done by adding a Process Step in the workflow that calls a custom service or script to set the permissions. Alternatively, you can use an OSGi event listener that detects when a new folder is added and applies the ACLs programmatically using AEM’s AccessControlManager. Another option is to use folder templates with predefined permissions so that users create folders from these templates instead of manually.
Here’s a simple Java snippet for the event listener approach:
@Component(service = EventHandler.class,
immediate = true,
property = {
EventConstants.EVENT_TOPIC + "=" + "org/apache/sling/api/resource/Resource/ADDED",
EventConstants.EVENT_FILTER + "=(path=/content/dam/promo/*)"
})
public class FolderPermissionHandler implements EventHandler {
@Reference
private ResourceResolverFactory resolverFactory;
@Override
public void handleEvent(Event event) {
try (ResourceResolver resolver = resolverFactory.getServiceResourceResolver(null)) {
String path = (String) event.getProperty("path");
Session session = resolver.adaptTo(Session.class);
AccessControlManager acm = session.getAccessControlManager();
Principal group = session.getPrincipalManager().getPrincipal("promo-group");
Privilege[] privileges = new Privilege[] {
acm.privilegeFromName(Privilege.JCR_READ),
acm.privilegeFromName(Privilege.JCR_WRITE)
};
AccessControlList acl = (AccessControlList) acm.getApplicablePolicies(path).nextAccessControlPolicy();
acl.addAccessControlEntry(group, privileges);
acm.setPolicy(path, acl);
session.save();
} catch (Exception e) {
e.printStackTrace();
}
}
}This listener checks for new folders under /content/dam/promo and assigns read/write permissions to a group called promo-group. For workflows, you would do something similar in a custom process step.
Best practice: Use workflows if you want flexibility and easy configuration by authors. Use event listeners if you need real-time automation without manual triggers.
Thanks,
Vishal