Expand my Community achievements bar.

SOLVED

Problems with jcr:uuid property while creating an AEM User programmatically

Avatar

Level 7

Hi Team,

I'm creating an AEM user programmatically (i.e.) I'm creating the folder structure which looks exactly same as the package structure when we create a list of users (located under "/home/users") package using http://localhost:4502/crx/packmgr/index.jsp by selecting "/home/users" as filters. I tried to remove "jcr:uuid" property as it will be automatically created by AEM and tried to install the package but the package was not installed and got the below exception.

Could not Install Package

"org.apache.jackrabbit.vault.packaging.PackageException: javax.jcr.nodetype.ConstraintViolationException: OakConstraint0021: Invalid jcr:uuid for authorizable username@domain.com"

Caused by: org.apache.jackrabbit.vault.packaging.PackageException: javax.jcr.nodetype.ConstraintViolationException: OakConstraint0021: Invalid jcr:uuid for authorizable username@domain.com
Caused by: javax.jcr.nodetype.ConstraintViolationException: OakConstraint0021: Invalid jcr:uuid for authorizable 
username@domain.com

So, I have generated a random uuid using java.util.UUID.randomUUID().toString() and set it to the jcr:uuid property. When I tried to install the package, I got the below exception -

Error: org.apache.jackrabbit.vault.packaging.PackageException: javax.jcr.nodetype.ConstraintViolationException: OakConstraint0021:

Invalid jcr:uuid for authorizable username@domain.com

Please help in this. May I know how exactly AEM is generating jcr:uuid value to a particular user? So that I can try the same approach, hope the above issue will be resolved.

Thanks,

Dinakar.

1 Accepted Solution

Avatar

Correct answer by
Level 9

This error usually happens when either the key or value of jcr:uuid is invalid

Looking into UserValidator class in source code

https://apache.googlesource.com/jackrabbit-oak/+/6385a232fe36f580ea23f99c04e24513565ea006/oak-core/s...

Line 76-79 generates this error, it calls isValidUUID method which is defined on lines 175-178

somewhere id is null or did not generate in valid format.


 

View solution in original post

5 Replies

Avatar

Correct answer by
Level 9

This error usually happens when either the key or value of jcr:uuid is invalid

Looking into UserValidator class in source code

https://apache.googlesource.com/jackrabbit-oak/+/6385a232fe36f580ea23f99c04e24513565ea006/oak-core/s...

Line 76-79 generates this error, it calls isValidUUID method which is defined on lines 175-178

somewhere id is null or did not generate in valid format.


 

Avatar

Level 9

There is another user who tried to create group programmatically recently faced same issue. Please review following post

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

Avatar

Level 7

Hi Ahmed,

Thanks for the source code. I will go.through it and let u know. Currently I'm not setting any null value to jcr:uuid. I will check in which way AEM is taking it as valid or invalid.

Thanks,

Dinakar

Avatar

Level 7

Hi Ahmed,

Thanks for the reply. I have seen that post. Unfortunately, the suggested approach is not suitable for my requirement. I'm not using any "org.apache.jackrabbit.api.security.user" API to create an AEM user. Also I'm not writing any OSGi services to do this. I'm doing entirely reverse process. I have written an independent program that creates the users package as explained in the above post. But during the time of installation, I'm getting the above exceptions.

Your comments are welcome.

Thanks,

Dinakar

Avatar

Level 7

Hi,

I have gone through different APIs. At last found how AEM is generating UUID (i.e.) the value of "jcr:uuid" property. Here it is -

Class: org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager

@Nonnull
public static String generateUUID(String hint) {
    UUID uuid = UUID.nameUUIDFromBytes(hint.getBytes(Charsets.UTF_8));
    return uuid.toString();
}

Pass the user name in lower case as parameter to this method (generateUUID(emailId.toLowerCase())) then we will get the correct UUID for the user. Based on the user name it will generate UUID.

My problem got resolved, I'm, able to install the package successfully.

Thanks,

Dinakar.