javax.jcr.nodetype.ConstraintViolationException: OakConstraint0027 error when migrating users and groups in AEM

Issue

When migrating users and groups from one AEM instance to another via Package Manager, the error below is shown: 

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

Environment

CQ5.x, AEM 6.x

Resolution

When packaging users and groups, you should make sure to avoid packaging out of the box users including the admin and anonymous users.  In addition, you must use the merge package filter mode.

  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:

    /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:

    /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 I am creating the package
    /home/users/K/Kj1406Qo9IDODc_nk5Ib – anonymous user on the system where I am 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 "users"

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

    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:

       
       
       
       
       
       
       
       
       
     

    <?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.

 Adobe

Get help faster and easier

New user?