Creating groups programatically | Community
Skip to main content
HariSivvala
Level 2
October 16, 2015
Solved

Creating groups programatically

  • October 16, 2015
  • 5 replies
  • 1907 views

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>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Dinu_Arya

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.

5 replies

Dinu_Arya
Level 6
October 16, 2015
HariSivvala
Level 2
October 16, 2015

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.

Dinu_Arya
Dinu_AryaAccepted solution
Level 6
October 16, 2015

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.

smacdonald2008
Level 10
October 16, 2015

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? 

smacdonald2008
Level 10
October 16, 2015

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