javax.jcr.nodetype.ConstraintViolationException: OakConstraint0027 error when migrating users and groups in AEM
When packaging users and groups, make sure to avoid packaging out-of-the-box users including the admin and anonymous users. You must use the merge package filter mode.
Description description
Environments
Adobe Experience Manager 6.x (AEM 6.x)
Adobe Communique 5.x (Adobe CQ5.x)
Issue
When migrating users and groups from one AEM instance to another via Package Manager, you get an error similar to the following:
26.01.2017 16:03:20.024 *ERROR* [ qtp2078058939-7783] org.apache.jackrabbit.vault.fs.io.Importer Error while committing : javax.jcr.nodetype.ConstraintViolationException: OakConstraint0027: The admin user cannot be removed.
javax.jcr.nodetype.ConstraintViolationException: OakConstraint0027: The admin user cannot be removed.
Caused by: org.apache.jackrabbit.oak.api.CommitFailedException: OakConstraint0027: The admin user cannot be removed
Resolution resolution
When packaging users and groups, you should make sure to avoid packaging out-of-the-box users including the admin and anonymous users.
You must use the merge package filter mode.
Follow these steps to resolve the issue:
-
Go to CRXDE lite app
/crx/de/index.jspand log in as admin user (on the old system). -
Go to Tools
>Query. -
In the bottom Query box, enter this query to find the admin user:
code language-none /jcr:root/home/users//element(*,rep:User)[ @rep:principalName="admin"] -
Click Execute, and copy the path of the admin user node in the results to a text file.
-
Repeat Step 3 with a query for anonymous user:
code language-none /jcr:root/home/users//element(*,rep:User)[ @rep:principalName="anonymous"] -
Click Execute, and copy the path of the anonymous user node in the results to a text file (so now you should have two paths, one for “admin” and one for “anonymous”).
For example:
/home/users/Q/QY5FIMXeQIbGpwZtQ3Dv– admin user on the system where you’re creating the package/home/users/K/Kj1406Qo9IDODc_nk5Ib– anonymous user on the system where you’re creating the package -
Go to the AEM package manager,
http://host:port/crx/packmgr/index.jsp, and log in as admin. -
Create a package called users.
-
Add a filter to the package config for
/home/userswith these exclude rules (on the/home/usersfilter):code language-none exclude /home/users/.*/.tokens exclude /home/users/Q/QY5FIMXeQIbGpwZtQ3Dv exclude /home/users/K/Kj1406Qo9IDODc_nk5Ib exclude /home/users/a/admin exclude /home/users/a/anonymous exclude /home/users/system exclude /home/users/geometrixx exclude /home/users/media exclude /home/users/projects exclude /home/users/mac -
Build the package.
-
Download the package.
-
Unzip the
package.zipfile on your computer. -
Open the file
META-INF/vault/filter.xmlin a text editor. -
Add
mode="merge"to the tag.For example:
code language-none <?xml version="1.0" encoding="UTF-8"?> <workspaceFilter version="1.0"> <filter root="/home/users" mode="merge"> <exclude pattern="/home/users/.*/.tokens"/> <exclude pattern="/home/users/Q/QY5FIMXeQIbGpwZtQ3Dv"/> <exclude pattern="/home/users/K/Kj1406Qo9IDODc_nk5Ib"/> <exclude pattern="/home/users/a/admin"/> <exclude pattern="/home/users/a/anonymous"/> <exclude pattern="/home/users/system"/> <exclude pattern="/home/users/geometrixx"/> <exclude pattern="/home/users/media"/> <exclude pattern="/home/users/projects"/> <exclude pattern="/home/users/mac"/> </filter> </workspaceFilter> -
Re-zip the modified package contents so it includes the change.
-
Create a groups package that contains a filter rule
/home/groups. -
Repeat Steps 10-15 for the groups package.
-
(Upgrade only): If performing migration to newer AEM version, then install a fresh local AEM instance (with
nosamplecontent), and install the users package and the groups package there. Then perform an in-place upgrade on that instance. After upgrading, then repackage the users again, then the groups again, and download the newer version of the packages. -
Install the users package on the new system.
-
Install the groups package on the new system.