Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Creating groups programatically

Avatar

Level 2

I have tried creating new groups through programatically. Created folders and required files and filter.xml  using java API. Developed a maven script which uses vault plugin to create the package using the folders and filter.xml created above. When i try to build the package getting below error[ERROR] Request failed: com.day.jcr.vault.packaging.PackageException: org.apache.jackrabbit.vault.packaging.PackageException: javax.jcr.nodetype.ConstraintViolationException: OakConstraint0021: Invalid jcr:uuid for authorizable "test" (500).

jcr:uuid is generated as UUID.randomUUID().toString()

 

Below is the sample .content.xml of group which is created by java API:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
jcr:mixinTypes="[rep:AccessControllable]"
jcr:primaryType="rep:Group"
jcr:uuid="b0837b67-f66b-4c27-b3fe-bb298c327974"
rep:authorizableId="test"
rep:principalName="test">
<preferences
jcr:primaryType="nt:unstructured"
sling:resourceType="cq:Preferences"/>
<profile
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/security/components/profile"
givenName="test"/></jcr:root>

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi Hari,

Can u try the below one?

UUID.nameUUIDFromBytes(<emailId>.toLowerCase().getBytes(Charsets.UTF_8))

Here in emailId variable I think you have to set the group name (Here test).

Thanks,

Dinakar.

View solution in original post

5 Replies

Avatar

Level 7

Hi Hari,

I also got the same problem. My post is here http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage... . I think the source code (https://apache.googlesource.com/jackrabbit-oak/+/6385a232fe36f580ea23f99c04e24513565ea006/oak-core/s...) which is given here will help us. May I know exactly a what point u r getting this error? For me its coming at the time of installation of package.

Thanks,

Dinakar

Avatar

Level 2

Hi Dinakar,

 

Thanks for the reply. I got the error when installing the package. I have updated code to generate UUID as below, which works for me.

UUID.nameUUIDFromBytes(groupName.toLowerCase().getBytes())

 

Thanks,

Hari.

Avatar

Correct answer by
Level 7

Hi Hari,

Can u try the below one?

UUID.nameUUIDFromBytes(<emailId>.toLowerCase().getBytes(Charsets.UTF_8))

Here in emailId variable I think you have to set the group name (Here test).

Thanks,

Dinakar.

Avatar

Level 10

To work with users/groups in AEM - you use http://jackrabbit.apache.org/api/2.0/org/apache/jackrabbit/api/security/user/package-summary.html API.

Did you use that API?

What dependency did you use in your POM file? 

Avatar

Level 10

Here is a community article that shows you how to build an OSGi bundle that uses the Jackrabbit security API:

https://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html