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:

  1. Go to CRXDE lite app /crx/de/index.jsp and log in as admin user (on the old system).

  2. Go to Tools > Query.

  3. 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"]
    
  4. Click Execute, and copy the path of the admin user node in the results to a text file.

  5. Repeat Step 3 with a query for anonymous user:

    code language-none
    /jcr:root/home/users//element(*,rep:User)[ @rep:principalName="anonymous"]
    
  6. 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

  7. Go to the AEM package manager, http://host:port/crx/packmgr/index.jsp, and log in as admin.

  8. Create a package called  users.

  9. Add a filter to the package config for /home/users with these exclude rules (on the /home/users filter):

    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
    
  10. Build the package.

  11. Download the package.

  12. Unzip the package.zip file on your computer.

  13. Open the file META-INF/vault/filter.xml in a text editor.

  14. 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>
    
  15. Re-zip the modified package contents so it includes the change.

  16. Create a groups  package that contains a filter rule /home/groups.

  17. Repeat Steps 10-15 for the groups package.

  18. (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.

  19. Install the users package on the new system.

  20. Install the groups package on the new system.

recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f