Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportTest.java	(revision )
@@ -23,13 +23,14 @@
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.nodetype.ConstraintViolationException;
 
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -67,15 +68,17 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
 
-        Authorizable newGroup = userMgr.getAuthorizable("g");
+        Session s = getImportSession();
+        assertTrue(s.hasPendingChanges());
+
+        Authorizable newGroup = getUserManager().getAuthorizable("g");
         assertNotNull(newGroup);
         assertTrue(newGroup.isGroup());
         assertEquals("g", newGroup.getPrincipal().getName());
         assertEquals("g", newGroup.getID());
 
-        Node n = adminSession.getNode(newGroup.getPath());
+        Node n = s.getNode(newGroup.getPath());
         assertTrue(n.isNew());
         assertTrue(n.getParent().isSame(target));
 
@@ -84,7 +87,7 @@
 
         // saving changes of the import -> must succeed. add mandatory
         // props should have been created.
-        adminSession.save();
+        s.save();
     }
 
     @Test
@@ -108,7 +111,7 @@
 
         try {
             doImport(getTargetPath(), xml);
-            adminSession.save();
+            getImportSession().save();
 
             fail("Import must detect conflicting principals.");
         } catch (RepositoryException e) {
@@ -124,6 +127,7 @@
                 "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>b2f5ff47-4366-31b6-a533-d8dc3614845d</sv:value></sv:property>" +
                 "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g</sv:value><sv:value>g2</sv:value><sv:value>g</sv:value></sv:property></sv:node>";
 
+        Session s = getImportSession();
         /*
          importing a group with a multi-valued rep:principalName property
          - nonProtected node rep:Group must be created.
@@ -135,9 +139,9 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(s.hasPendingChanges());
 
-        Authorizable newGroup = userMgr.getAuthorizable("g");
+        Authorizable newGroup = getUserManager().getAuthorizable("g");
         assertNotNull(newGroup);
 
         assertTrue(target.hasNode("g"));
@@ -146,7 +150,7 @@
 
         // saving changes of the import -> must fail as mandatory prop is missing
         try {
-            adminSession.save();
+            s.save();
             fail("Import must be incomplete. Saving changes must fail.");
         } catch (ConstraintViolationException e) {
             // success
@@ -168,7 +172,7 @@
         doImport(getTargetPath(), xml);
         // saving changes of the import -> must fail as mandatory prop is missing
         try {
-            adminSession.save();
+            getImportSession().save();
             fail("Import must be incomplete. Saving changes must fail.");
         } catch (ConstraintViolationException e) {
             // success
@@ -197,16 +201,17 @@
 
         doImport(getTargetPath(), xml);
 
-        Group g = (Group) userMgr.getAuthorizable("g");
+        Group g = (Group) getUserManager().getAuthorizable("g");
         assertNotNull(g);
-        Group g1 = (Group) userMgr.getAuthorizable("g1");
+        Group g1 = (Group) getUserManager().getAuthorizable("g1");
         assertNotNull(g1);
 
-        Node n = adminSession.getNode(g1.getPath());
+        Session s = getImportSession();
+        Node n = s.getNode(g1.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_MEMBERS) || n.hasNode(UserConstants.NT_REP_MEMBERS));
 
         // getWeakReferences only works upon save.
-        adminSession.save();
+        s.save();
 
         assertTrue(g1.isMember(g));
     }
@@ -232,24 +237,26 @@
 
         doImport(getTargetPath(), xml);
 
-        Group g = (Group) userMgr.getAuthorizable("g");
+        Group g = (Group) getUserManager().getAuthorizable("g");
         assertNotNull(g);
-        Group g1 = (Group) userMgr.getAuthorizable("g1");
+        Group g1 = (Group) getUserManager().getAuthorizable("g1");
         assertNotNull(g1);
 
-        Node n = adminSession.getNode(g1.getPath());
+        Session s = getImportSession();
+        Node n = s.getNode(g1.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_MEMBERS) || n.hasNode(UserConstants.NT_REP_MEMBERS));
 
         // getWeakReferences only works upon save.
-        adminSession.save();
+        s.save();
 
         assertTrue(g1.isMember(g));
     }
 
     @Test
     public void testImportMembers() throws Exception {
-        Authorizable admin = checkNotNull(userMgr.getAuthorizable(UserConstants.DEFAULT_ADMIN_ID));
-        String uuid = adminSession.getNode(admin.getPath()).getUUID();
+        Session s = getImportSession();
+        Authorizable admin = checkNotNull(getUserManager().getAuthorizable(UserConstants.DEFAULT_ADMIN_ID));
+        String uuid = s.getNode(admin.getPath()).getUUID();
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                 "<sv:node sv:name=\"gFolder\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +
                 "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" +
@@ -263,11 +270,11 @@
 
         doImport(getTargetPath(), xml);
 
-        Group g1 = (Group) userMgr.getAuthorizable("g1");
+        Group g1 = (Group) getUserManager().getAuthorizable("g1");
         assertNotNull(g1);
 
         // getWeakReferences only works upon save.
-        adminSession.save();
+        s.save();
 
         assertTrue(g1.isMember(admin));
 
@@ -280,8 +287,9 @@
 
     @Test
     public void testImportMembersWithIdDifferentFromNodeName() throws Exception {
-        Authorizable admin = checkNotNull(userMgr.getAuthorizable(UserConstants.DEFAULT_ADMIN_ID));
-        String uuid = adminSession.getNode(admin.getPath()).getUUID();
+        Session s = getImportSession();
+        Authorizable admin = checkNotNull(getUserManager().getAuthorizable(UserConstants.DEFAULT_ADMIN_ID));
+        String uuid = s.getNode(admin.getPath()).getUUID();
         // deliberately put the 'rep:members' before the 'rep:authorizableId' to cover OAK-2367
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                 "<sv:node sv:name=\"gFolder\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +
@@ -297,11 +305,11 @@
 
         doImport(getTargetPath(), xml);
 
-        Group g1 = (Group) userMgr.getAuthorizable("g1");
+        Group g1 = (Group) getUserManager().getAuthorizable("g1");
         assertNotNull(g1);
 
         // getWeakReferences only works upon save.
-        adminSession.save();
+        s.save();
 
         assertTrue(g1.isMember(admin));
 
@@ -315,50 +323,55 @@
     @Test
     public void testImportGroupMembersFromNodes() throws Exception {
         List<String> createdUsers = new LinkedList<String>();
-        Node target = getTargetNode();
+
+        Session s = getImportSession();
+        UserManager uMgr = getUserManager();
+
         try {
             String[] users = {"angi", "adi", "hansi", "lisi", "luzi", "susi", "pipi", "hari", "gabi", "eddi",
                     "debbi", "cati", "admin", "anonymous"};
 
             for (String user : users) {
-                if (userMgr.getAuthorizable(user) == null) {
-                    userMgr.createUser(user, user);
+                if (uMgr.getAuthorizable(user) == null) {
+                    uMgr.createUser(user, user);
                     createdUsers.add(user);
                 }
             }
-            if (!userMgr.isAutoSave()) {
-                adminSession.save();
+            if (!uMgr.isAutoSave()) {
+                s.save();
             }
 
-            doImport(getTargetPath(), getClass().getSimpleName() + "-testImportGroupMembersFromNodes.xml");
-            if (!userMgr.isAutoSave()) {
-                adminSession.save();
+            doImport(getTargetPath(), "GroupImportTest-testImportGroupMembersFromNodes.xml");
+            if (!uMgr.isAutoSave()) {
+                s.save();
             }
 
-            Authorizable aShrimps = userMgr.getAuthorizable("shrimps");
+            Authorizable aShrimps = uMgr.getAuthorizable("shrimps");
             assertNotNull("Shrimps authorizable must exist", aShrimps);
             assertTrue("Shrimps authorizable must be a group", aShrimps.isGroup());
 
             Group gShrimps = (Group) aShrimps;
             for (String user : users) {
-                assertTrue(user + " should be member of " + gShrimps, gShrimps.isMember(userMgr.getAuthorizable(user)));
+                assertTrue(user + " should be member of " + gShrimps, gShrimps.isMember(uMgr.getAuthorizable(user)));
             }
 
 
         } finally {
-            adminSession.refresh(false);
             for (String user : createdUsers) {
-                Authorizable a = userMgr.getAuthorizable(user);
+                Authorizable a = uMgr.getAuthorizable(user);
                 if (a != null && !a.isGroup()) {
                     a.remove();
                 }
             }
-            for (NodeIterator it = target.getNodes(); it.hasNext(); ) {
-                it.nextNode().remove();
+            for (NodeIterator it = s.getNode(getTargetPath()).getNodes(); it.hasNext(); ) {
+                Node n = it.nextNode();
+                if (!n.getDefinition().isProtected()) {
+                    n.remove();
-            }
+                }
-            adminSession.save();
-        }
+            }
+            s.save();
-    }
+        }
+    }
 
     /**
      * @since OAK 1.0 : Importing new rep:MembershipReferences structure
@@ -366,57 +379,62 @@
     @Test
     public void testImportGroupMembersFromOakNodes() throws Exception {
         List<String> createdUsers = new LinkedList<String>();
-        Node target = getTargetNode();
+
+        Session s = getImportSession();
+        UserManager uMgr = getUserManager();
+
         try {
             for (int i=0; i<32; i++) {
                 String user = "testUser" + i;
-                if (userMgr.getAuthorizable(user) == null) {
-                    userMgr.createUser(user, user);
+                if (uMgr.getAuthorizable(user) == null) {
+                    uMgr.createUser(user, user);
                     createdUsers.add(user);
                 }
             }
-            if (!userMgr.isAutoSave()) {
-                adminSession.save();
+            if (!uMgr.isAutoSave()) {
+                s.save();
             }
 
-            doImport(getTargetPath(), getClass().getSimpleName() + "-testImportGroupMembersFromOakNodes.xml");
-            if (!userMgr.isAutoSave()) {
-                adminSession.save();
+            doImport(getTargetPath(), "GroupImportTest-testImportGroupMembersFromOakNodes.xml");
+            if (!uMgr.isAutoSave()) {
+                s.save();
             }
 
-            Authorizable authorizable = userMgr.getAuthorizable("testGroup");
+            Authorizable authorizable = uMgr.getAuthorizable("testGroup");
             assertNotNull("testGroup authorizable must exist", authorizable);
             assertTrue("testGroup authorizable must be a group", authorizable.isGroup());
             Group testGroup = (Group) authorizable;
             for (int i=0; i<32; i++) {
                 String user = "testUser" + i;
-                assertTrue(user + " should be member of " + testGroup, testGroup.isMember(userMgr.getAuthorizable(user)));
+                assertTrue(user + " should be member of " + testGroup, testGroup.isMember(uMgr.getAuthorizable(user)));
             }
 
-            authorizable = userMgr.getAuthorizable("shrimps");
+            authorizable = uMgr.getAuthorizable("shrimps");
             assertNotNull("shrimps authorizable must exist", authorizable);
             assertTrue("shrimps authorizable must be a group", authorizable.isGroup());
             testGroup = (Group) authorizable;
             for (int i=0; i<32; i++) {
                 String user = "testUser" + i;
-                assertTrue(user + " should be member of " + testGroup, testGroup.isMember(userMgr.getAuthorizable(user)));
+                assertTrue(user + " should be member of " + testGroup, testGroup.isMember(uMgr.getAuthorizable(user)));
             }
 
 
         } finally {
-            adminSession.refresh(false);
             for (String user : createdUsers) {
-                Authorizable a = userMgr.getAuthorizable(user);
+                Authorizable a = uMgr.getAuthorizable(user);
                 if (a != null && !a.isGroup()) {
                     a.remove();
                 }
             }
-            for (NodeIterator it = target.getNodes(); it.hasNext(); ) {
-                it.nextNode().remove();
+            for (NodeIterator it = s.getNode(getTargetPath()).getNodes(); it.hasNext(); ) {
+                Node n = it.nextNode();
+                if (!n.getDefinition().isProtected()) {
+                    n.remove();
-            }
+                }
-            adminSession.save();
-        }
+            }
+            s.save();
-    }
+        }
+    }
 
     /**
      * @since OAK 1.0 : Importing rep:authorizableId
@@ -433,14 +451,15 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable newGroup = userMgr.getAuthorizable("g");
+        Session s = getImportSession();
+        Authorizable newGroup = getUserManager().getAuthorizable("g");
         assertNotNull(newGroup);
         assertTrue(newGroup.isGroup());
         assertEquals("g", newGroup.getID());
-        assertTrue(adminSession.propertyExists(newGroup.getPath() + "/rep:authorizableId"));
-        assertEquals("g", adminSession.getProperty(newGroup.getPath() + "/rep:authorizableId").getString());
+        assertTrue(s.propertyExists(newGroup.getPath() + "/rep:authorizableId"));
+        assertEquals("g", s.getProperty(newGroup.getPath() + "/rep:authorizableId").getString());
 
-        adminSession.save();
+        s.save();
     }
 
     @Test
@@ -459,10 +478,11 @@
                 "</sv:node>";
 
         doImport(getTargetPath(), xml);
-        User user = userMgr.createUser("angi", "pw");
-        adminSession.save();
 
-        Group g1 = (Group) userMgr.getAuthorizable("g1");
+        User user = getUserManager().createUser("angi", "pw");
+        getImportSession().save();
+
+        Group g1 = (Group) getUserManager().getAuthorizable("g1");
 
         // not BEST_EFFORT -> member is not resolved
         assertFalse(g1.isMember(user));
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportFromJackrabbit.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportFromJackrabbit.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportFromJackrabbit.java	(revision )
@@ -18,6 +18,7 @@
 
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.Node;
+import javax.jcr.Session;
 import javax.jcr.nodetype.ConstraintViolationException;
 
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -45,7 +46,17 @@
     private String randomNodeName = "f5aj6fp7q9834jof";
     private String intermediatePath = "foo/bar/test";
 
+    private Session importSession;
+
     @Override
+    public void before() throws Exception {
+        super.before();
+
+        importSession = getImportSession();
+
+    }
+
+    @Override
     protected String getTargetPath() {
         return USERPATH;
     }
@@ -71,15 +82,15 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
         assertEquals(uid, newUser.getID());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(uid, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
 
         // saving changes of the import -> must succeed
-        adminSession.save();
+        importSession.save();
     }
 
     /**
@@ -88,9 +99,9 @@
     @Test
     public void testUUIDBehaviorReplace() throws Exception {
         // create authorizable
-        User u = userMgr.createUser(uid, null, new PrincipalImpl("t"), getTargetPath() + "/foo/bar/test");
+        User u = getUserManager().createUser(uid, null, new PrincipalImpl("t"), getTargetPath() + "/foo/bar/test");
         String initialPath = u.getPath();
-        adminSession.save();
+        importSession.save();
 
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                 "<sv:node sv:name=\""+uid+"\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +
@@ -103,18 +114,18 @@
 
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
 
         // replace should retain path
         assertEquals(initialPath, newUser.getPath());
         assertFalse(getTargetPath().equals(Text.getRelativeParent(newUser.getPath(), 1)));
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(uid, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
 
         // saving changes of the import -> must succeed
-        adminSession.save();
+        importSession.save();
     }
 
     /**
@@ -123,9 +134,9 @@
     @Test
     public void testUUIDBehaviorRemove() throws Exception {
         // create authorizable
-        User u = userMgr.createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
+        User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
         String initialPath = u.getPath();
-        adminSession.save();
+        importSession.save();
 
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                 "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +
@@ -138,19 +149,19 @@
 
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
 
         // IMPORT_UUID_COLLISION_REMOVE_EXISTING should result in the user to
         // be imported a the new path
         assertEquals(getTargetPath(), Text.getRelativeParent(newUser.getPath(), 1));
         assertFalse(initialPath.equals(newUser.getPath()));
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(uid, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
 
         // saving changes of the import -> must succeed
-        adminSession.save();
+        importSession.save();
     }
 
     /**
@@ -159,11 +170,11 @@
     @Test
     public void testUUIDBehaviorReplaceFromRenamed() throws Exception {
         // create authorizable
-        User u = userMgr.createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
+        User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
         String initialPath = u.getPath();
         String movedPath = Text.getRelativeParent(initialPath, 1) + '/' + randomNodeName;
-        adminSession.move(initialPath, movedPath);
-        adminSession.save();
+        importSession.move(initialPath, movedPath);
+        importSession.save();
 
         // import 'correct' jr2 package which contains the encoded ID in the node name
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -177,18 +188,18 @@
 
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
 
         // replace should update the path
         assertEquals("user path", Text.getRelativeParent(initialPath, 1) + '/' + uid, newUser.getPath());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(UserConstants.REP_AUTHORIZABLE_ID, uid, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
         assertEquals(UserConstants.REP_AUTHORIZABLE_ID, uid, newUser.getID());
 
         // saving changes of the import must succeed.
-        adminSession.save();
+        importSession.save();
     }
 
     /**
@@ -197,11 +208,11 @@
     @Test
     public void testUUIDBehaviorReplaceFromRenamed2() throws Exception {
         // create authorizable
-        User u = userMgr.createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
+        User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
         String initialPath = u.getPath();
         String movedPath = Text.getRelativeParent(initialPath, 1) + '/' + randomNodeName;
-        adminSession.move(initialPath, movedPath);
-        adminSession.save();
+        importSession.move(initialPath, movedPath);
+        importSession.save();
 
         // we need to include the new node name in the sysview import, so that the importer uses the correct name.
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -215,12 +226,12 @@
 
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
 
         // replace should retain path
         assertEquals("user path", movedPath, newUser.getPath());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(UserConstants.REP_AUTHORIZABLE_ID, randomNodeName, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
 
@@ -230,7 +241,7 @@
         // correct ID as hashed in the jcr:uuid, the CommitHook will detect
         // the mismatch, which for the diff looks like a modified ID.
         try {
-            adminSession.save();
+            importSession.save();
             fail("Importing an authorizable with mismatch between authorizableId and uuid must fail.");
         } catch (ConstraintViolationException e) {
             // success
@@ -244,9 +255,9 @@
     @Test
     public void testUUIDBehaviorReplaceFromRenamed3() throws Exception {
         // create authorizable
-        User u = userMgr.createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
+        User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
         String originalPath = u.getPath();
-        adminSession.save();
+        importSession.save();
 
         // we need to include the new node name in the sysview import, so that the importer uses the correct name.
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -260,13 +271,13 @@
 
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
 
         // replace should change the original path
         String expectedPath = Text.getRelativeParent(originalPath, 1) + '/' + randomNodeName;
         assertEquals("user path", expectedPath, newUser.getPath());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(UserConstants.REP_AUTHORIZABLE_ID, randomNodeName, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
 
@@ -275,7 +286,7 @@
         // modified node name in combination with the fact that in JR 2.x
         // the node name MUST contain the id as there is no rep:authorizableId.
         try {
-            adminSession.save();
+            importSession.save();
             fail("Importing an authorizable with mismatch between authorizableId and uuid must fail.");
         } catch (ConstraintViolationException e) {
             // success
@@ -289,11 +300,11 @@
     @Test
     public void testUUIDBehaviorRemoveFromRenamed() throws Exception {
         // create authorizable
-        User u = userMgr.createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
+        User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
         String initialPath = u.getPath();
         String movedPath = Text.getRelativeParent(initialPath, 1) + '/' + randomNodeName;
-        adminSession.move(initialPath, movedPath);
-        adminSession.save();
+        importSession.move(initialPath, movedPath);
+        importSession.save();
 
         // import 'correct' jr2 package which contains the encoded ID in the node name
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -307,18 +318,18 @@
 
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
 
         // IMPORT_UUID_COLLISION_REMOVE_EXISTING should import the user at the new path
         assertEquals("user path", getTargetPath() + '/' + uid, newUser.getPath());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(UserConstants.REP_AUTHORIZABLE_ID, uid, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
         assertEquals(UserConstants.REP_AUTHORIZABLE_ID, uid, newUser.getID());
 
         // saving changes of the import must succeed.
-        adminSession.save();
+        importSession.save();
     }
 
     /**
@@ -327,11 +338,11 @@
     @Test
     public void testUUIDBehaviorRemoveFromRenamed2() throws Exception {
         // create authorizable
-        User u = userMgr.createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
+        User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
         String initialPath = u.getPath();
         String movedPath = Text.getRelativeParent(initialPath, 1) + '/' + randomNodeName;
-        adminSession.move(initialPath, movedPath);
-        adminSession.save();
+        importSession.move(initialPath, movedPath);
+        importSession.save();
 
         // we need to include the new node name in the sysview import, so that the importer uses the correct name.
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -345,12 +356,12 @@
 
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
 
         // IMPORT_UUID_COLLISION_REMOVE_EXISTING should import the user at the new path
         assertEquals("user path", getTargetPath() + '/' + randomNodeName, newUser.getPath());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(UserConstants.REP_AUTHORIZABLE_ID, randomNodeName, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
 
@@ -358,7 +369,7 @@
         // removed and the JR 2.x the node name doesn't contain the correct id,
         // which is detected during save as it looks like the id had been modified.
         try {
-            adminSession.save();
+            importSession.save();
             fail("Importing an authorizable with mismatch between authorizableId and uuid must fail.");
         } catch (ConstraintViolationException e) {
             // success
@@ -372,9 +383,9 @@
     @Test
     public void testUUIDBehaviorRemoveFromRenamed3() throws Exception {
         // create authorizable
-        User u = userMgr.createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
+        User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
         String originalPath = u.getPath();
-        adminSession.save();
+        importSession.save();
 
         // we need to include the new node name in the sysview import, so that the importer uses the correct name.
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -388,14 +399,14 @@
 
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
 
-        Authorizable newUser = userMgr.getAuthorizable(uid);
+        Authorizable newUser = getUserManager().getAuthorizable(uid);
 
         // replace should change the original path
         String expectedPath = getTargetPath() + '/' + randomNodeName;
         assertEquals("user path", expectedPath, newUser.getPath());
         assertFalse((Text.getRelativeParent(originalPath,1) + '/' + randomNodeName).equals(newUser.getPath()));
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = importSession.getNode(newUser.getPath());
         assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
         assertEquals(UserConstants.REP_AUTHORIZABLE_ID, randomNodeName, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
 
@@ -403,7 +414,7 @@
         // has been modified (it no longer represents the correct ID due to the
         // fact that in JR 2.x the node name MUST contain the id.
         try {
-            adminSession.save();
+            importSession.save();
             fail("Importing an authorizable with mismatch between authorizableId and uuid must fail.");
         } catch (ConstraintViolationException e) {
             // success
\ No newline at end of file
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportBestEffortTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportBestEffortTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportBestEffortTest.java	(revision )
@@ -65,7 +65,7 @@
 
         // saving changes of the import -> must succeed. add mandatory
         // props should have been created.
-        adminSession.save();
+        getImportSession().save();
     }
 
     /**
@@ -83,14 +83,14 @@
                 "</sv:node>";
 
         doImport(getTargetPath(), xml);
-        adminSession.save();
+        getImportSession().save();
 
         // re-import should succeed if UUID-behavior is set accordingly
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
 
         // saving changes of the import -> must succeed. add mandatory
         // props should have been created.
-        adminSession.save();
+        getImportSession().save();
     }
 
     @Test
@@ -132,10 +132,10 @@
                 "</sv:node>";
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
 
-        Authorizable u2 = userMgr.getAuthorizable("g");
+        Authorizable u2 = getUserManager().getAuthorizable("g");
         assertNotNull(u2);
 
         Subject subj = new Subject();
@@ -158,7 +158,7 @@
                 "</sv:node>";
         doImport(getTargetPath(), xml);
 
-        Authorizable a = userMgr.getAuthorizable("t");
+        Authorizable a = getUserManager().getAuthorizable("t");
         assertFalse(a.isGroup());
 
         boolean found = false;
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithPoliciesTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithPoliciesTest.java	(revision )
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithPoliciesTest.java	(revision )
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.security.user;
+
+import java.util.UUID;
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.security.AccessControlEntry;
+import javax.jcr.security.AccessControlList;
+import javax.jcr.security.Privilege;
+
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
+import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.test.api.util.Text;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class GroupImportWithPoliciesTest extends AbstractImportTest {
+
+    private String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+            "<sv:node sv:name=\"g\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +
+            "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Group</sv:value></sv:property>" +
+            "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>b2f5ff47-4366-31b6-a533-d8dc3614845d</sv:value></sv:property>" +
+            "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g</sv:value></sv:property>" +
+            "   <sv:property sv:name=\"jcr:mixinTypes\" sv:type=\"Name\" sv:multiple=\"true\"><sv:value>rep:AccessControllable</sv:value></sv:property>" +
+            "   <sv:node sv:name=\"rep:policy\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:ACL</sv:value></sv:property><sv:node sv:name=\"allow\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:GrantACE</sv:value></sv:property><sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>administrators</sv:value></sv:property><sv:property sv:name=\"rep:privileges\" sv:type=\"Name\" sv:multiple=\"true\"><sv:value>jcr:read</sv:value></sv:property></sv:node></sv:node>" +
+            "</sv:node>";
+
+    private String testUserID = "testUser" + UUID.randomUUID();
+    private Session testSession;
+
+    @Override
+    public void before() throws Exception {
+        super.before();
+
+        User testUser = userMgr.createUser(testUserID, testUserID);
+        AccessControlUtils.addAccessControlEntry(adminSession, Text.getRelativeParent(GROUPPATH, 1), testUser.getPrincipal(), new String[]{
+                Privilege.JCR_READ,
+                Privilege.JCR_WRITE,
+                Privilege.JCR_READ_ACCESS_CONTROL,
+                Privilege.JCR_MODIFY_ACCESS_CONTROL,
+                Privilege.JCR_NODE_TYPE_MANAGEMENT,
+                PrivilegeConstants.REP_USER_MANAGEMENT}, true);
+        // registering new namespaces curing import requires jcr:namespaceManagement privilege on the repo level (null path)
+        AccessControlUtils.addAccessControlEntry(adminSession, null, testUser.getPrincipal(), new String[] {PrivilegeConstants.JCR_NAMESPACE_MANAGEMENT}, true);
+        adminSession.save();
+
+        testSession = adminSession.getRepository().login(new SimpleCredentials(testUserID, testUserID.toCharArray()));
+    }
+
+    @Override
+    public void after() throws Exception {
+        try {
+            testSession.logout();
+
+            adminSession.refresh(false);
+            userMgr.getAuthorizable(testUserID).remove();
+            Authorizable g = userMgr.getAuthorizable("g");
+            if (g != null) {
+                g.remove();
+            }
+            adminSession.save();
+        } finally {
+            super.after();
+        }
+    }
+
+    @Override
+    protected String getTargetPath() {
+        return GROUPPATH;
+    }
+
+    @Override
+    protected Session getImportSession() {
+        return testSession;
+    }
+
+    @Override
+    protected String getImportBehavior() {
+        return null;
+    }
+
+    @Test
+    public void testImportGroupWithPolicies() throws Exception {
+        Node target = getTargetNode();
+        doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
+
+        assertTrue(getImportSession().hasPendingChanges());
+
+        Authorizable newGroup = getUserManager().getAuthorizable("g");
+        assertNotNull(newGroup);
+        assertTrue(newGroup.isGroup());
+        assertEquals("g", newGroup.getPrincipal().getName());
+        assertEquals("g", newGroup.getID());
+
+        Node n = getImportSession().getNode(newGroup.getPath());
+        assertTrue(n.isNew());
+        assertTrue(n.getParent().isSame(target));
+
+        assertEquals("g", n.getName());
+        assertEquals("g", n.getProperty(UserConstants.REP_PRINCIPAL_NAME).getString());
+
+        AccessControlList acl = AccessControlUtils.getAccessControlList(getImportSession(), newGroup.getPath());
+        assertNotNull(acl);
+
+        AccessControlEntry[] aces = acl.getAccessControlEntries();
+        assertEquals(1, aces.length);
+        assertEquals("administrators", aces[0].getPrincipal().getName());
+        assertEquals(PrivilegeConstants.JCR_READ, aces[0].getPrivileges()[0].getName());
+
+        // saving changes of the import -> must succeed. add mandatory
+        // props should have been created.
+        getImportSession().save();
+    }
+
+}
\ No newline at end of file
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/SystemUserImportTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/SystemUserImportTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/SystemUserImportTest.java	(revision )
@@ -23,6 +23,7 @@
 import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.security.auth.Subject;
 
@@ -90,10 +91,11 @@
         Node target = getTargetNode();
         doImport(getTargetPath(), xml);
 
+        Session s = getImportSession();
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(s.hasPendingChanges());
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertTrue(((User) newUser).isSystemUser());
@@ -103,7 +105,7 @@
         assertTrue(((User) newUser).isDisabled());
         assertEquals("disabledUser", ((User) newUser).getDisabledReason());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = s.getNode(newUser.getPath());
         assertTrue(n.isNew());
         assertTrue(n.getParent().isSame(target));
 
@@ -114,7 +116,7 @@
         assertFalse(n.hasProperty(UserConstants.REP_PASSWORD));
 
         // saving changes of the import -> must succeed. all mandatory props should have been created.
-        adminSession.save();
+        s.save();
     }
 
     /**
@@ -134,25 +136,26 @@
          importing a system user below the regular users-path:
          - saving changes must fail with ConstraintViolationEx.
          */
-        Node target = adminSession.getNode(USERPATH);
+        Session s = getImportSession();
+        Node target = s.getNode(USERPATH);
         doImport(USERPATH, xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(s.hasPendingChanges());
 
-        Authorizable user = userMgr.getAuthorizable("t");
+        Authorizable user = getUserManager().getAuthorizable("t");
         assertNotNull(user);
         assertTrue(target.hasNode("t"));
         assertTrue(target.hasProperty("t/rep:principalName"));
 
         // saving changes of the import -> must fail
         try {
-            adminSession.save();
+            s.save();
             fail("Import must be incomplete. Saving changes must fail.");
         } catch (ConstraintViolationException e) {
             // success
         } finally {
-            adminSession.refresh(false);
+            s.refresh(false);
             if (target.hasNode("t")) {
                 target.getNode("t").remove();
                 target.save();
@@ -177,7 +180,7 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(getImportSession().hasPendingChanges());
 
         // node must be present:
         assertTrue(target.hasNode("t"));
@@ -186,17 +189,19 @@
 
         // but UserManager.getAuthorizable(String) will not find the
         // authorizable
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNull(newUser);
     }
 
     @Test
     public void testExistingPrincipal() throws Exception {
         Principal existing = null;
-        PrincipalIterator principalIterator = ((JackrabbitSession) adminSession).getPrincipalManager().getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
+
+        Session s = getImportSession();
+        PrincipalIterator principalIterator = ((JackrabbitSession) s).getPrincipalManager().getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
         while (principalIterator.hasNext()) {
             Principal p = principalIterator.nextPrincipal();
-            if (userMgr.getAuthorizable(p) != null) {
+            if (getUserManager().getAuthorizable(p) != null) {
                 existing = p;
                 break;
             }
@@ -214,7 +219,7 @@
 
         try {
             doImport(getTargetPath(), xml);
-            adminSession.save();
+            s.save();
 
             fail("Import must detect conflicting principals.");
         } catch (RepositoryException e) {
@@ -237,12 +242,12 @@
         Node target = getTargetNode();
         assertFalse(target.hasProperty(UserConstants.REP_PASSWORD));
 
-        Authorizable user = userMgr.getAuthorizable("t");
+        Authorizable user = getUserManager().getAuthorizable("t");
         assertNotNull(user);
         assertFalse(user.isGroup());
         assertTrue(((User)user).isSystemUser());
 
-        adminSession.save();
+        getImportSession().save();
     }
 
     /**
@@ -268,9 +273,9 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(getImportSession().hasPendingChanges());
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
 
         assertTrue(target.hasNode("t"));
@@ -293,22 +298,23 @@
                 "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" +
                 "</sv:node>");
 
+        Session s = getImportSession();
         for (String xml : incompleteXml) {
-            Node target = adminSession.getNode(getTargetPath());
+            Node target = s.getNode(getTargetPath());
             try {
                 doImport(getTargetPath(), xml);
                 // saving changes of the import -> must fail as mandatory prop is missing
                 try {
-                    adminSession.save();
+                    s.save();
                     fail("Import must be incomplete. Saving changes must fail.");
                 } catch (ConstraintViolationException e) {
                     // success
                 }
             } finally {
-                adminSession.refresh(false);
+                s.refresh(false);
                 if (target.hasNode("t")) {
                     target.getNode("t").remove();
-                    adminSession.save();
+                    s.save();
                 }
             }
         }
@@ -328,10 +334,10 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable user = userMgr.getAuthorizable("t");
+        Authorizable user = getUserManager().getAuthorizable("t");
         assertNotNull(user);
         assertFalse(user.isGroup());
-        assertFalse(adminSession.propertyExists(user.getPath() + "/rep:password"));
+        assertFalse(getImportSession().propertyExists(user.getPath() + "/rep:password"));
     }
 
     @Test
@@ -360,15 +366,15 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(getImportSession().hasPendingChanges());
 
-        Authorizable newUser = userMgr.getAuthorizable("t3");
+        Authorizable newUser = getUserManager().getAuthorizable("t3");
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t3", newUser.getPrincipal().getName());
         assertEquals("t3", newUser.getID());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = getImportSession().getNode(newUser.getPath());
         assertTrue(n.isNew());
 
         Node parent = n.getParent();
@@ -400,10 +406,10 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
 
-        Authorizable u2 = userMgr.getAuthorizable("g");
+        Authorizable u2 = getUserManager().getAuthorizable("g");
         assertNotNull(u2);
 
         Subject subj = new Subject();
@@ -429,7 +435,7 @@
 
         // saving changes of the import -> must succeed. add mandatory
         // props should have been created.
-        adminSession.save();
+        getImportSession().save();
     }
 
     /**
@@ -447,14 +453,14 @@
                 "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" +
                 "</sv:node>";
         doImport(getTargetPath(), xml);
-        adminSession.save();
+        getImportSession().save();
 
         // re-import should succeed if UUID-behavior is set accordingly
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
 
         // saving changes of the import -> must succeed. add mandatory
         // props should have been created.
-        adminSession.save();
+        getImportSession().save();
     }
 
     @Test
@@ -491,13 +497,14 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Session s = getImportSession();
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t", newUser.getID());
-        assertTrue(adminSession.propertyExists(newUser.getPath() + "/rep:authorizableId"));
-        assertEquals("t", adminSession.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
-        adminSession.save();
+        assertTrue(s.propertyExists(newUser.getPath() + "/rep:authorizableId"));
+        assertEquals("t", s.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
+        s.save();
     }
 
     /**
@@ -516,14 +523,15 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Session s = getImportSession();
+        Authorizable newUser = getUserManager().getAuthorizable("t");
 
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t", newUser.getID());
-        assertTrue(adminSession.propertyExists(newUser.getPath() + "/rep:authorizableId"));
-        assertEquals("t", adminSession.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
-        adminSession.save();
+        assertTrue(s.propertyExists(newUser.getPath() + "/rep:authorizableId"));
+        assertEquals("t", s.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
+        s.save();
     }
 
     /**
@@ -543,14 +551,15 @@
                 "</sv:node>";
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
 
+        Session s = getImportSession();
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t", newUser.getID());
-        assertTrue(adminSession.propertyExists(newUser.getPath() + "/rep:authorizableId"));
-        assertEquals("t", adminSession.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
-        adminSession.save();
+        assertTrue(s.propertyExists(newUser.getPath() + "/rep:authorizableId"));
+        assertEquals("t", s.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
+        s.save();
     }
 
     /**
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportIgnoreTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportIgnoreTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportIgnoreTest.java	(revision )
@@ -56,9 +56,9 @@
                 "</sv:node>";
         doImport(getTargetPath(), xml);
         // no exception during import -> member must have been ignored though.
-        Authorizable a = userMgr.getAuthorizable("g1");
+        Authorizable a = getUserManager().getAuthorizable("g1");
         if (a.isGroup()) {
-            assertNotDeclaredMember((Group) a, invalidId, adminSession);
+            assertNotDeclaredMember((Group) a, invalidId, getImportSession());
         } else {
             fail("'g1' was not imported as Group.");
         }
@@ -84,14 +84,14 @@
                 // there should be no exception during import,
                 // but invalid members must be ignored.
                 doImport(getTargetPath(), xml);
-                Authorizable a = userMgr.getAuthorizable("g1");
+                Authorizable a = getUserManager().getAuthorizable("g1");
                 if (a.isGroup()) {
-                    assertNotDeclaredMember((Group) a, id, adminSession);
+                    assertNotDeclaredMember((Group) a, id, getImportSession());
                 } else {
                     fail("'g1' was not imported as Group.");
                 }
             } finally {
-                adminSession.refresh(false);
+                getImportSession().refresh(false);
             }
         }
     }
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportBestEffortTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportBestEffortTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportBestEffortTest.java	(revision )
@@ -21,6 +21,7 @@
 import java.util.UUID;
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
+import javax.jcr.Session;
 import javax.jcr.Value;
 
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -57,6 +58,7 @@
         invalid.add(UUID.randomUUID().toString()); // random uuid
         invalid.add(getExistingUUID()); // uuid of non-authorizable node
 
+        Session s = getImportSession();
         for (String id : invalid) {
             String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                     "<sv:node sv:name=\"gFolder\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +
@@ -70,11 +72,11 @@
             try {
                 // BESTEFFORT behavior -> must import non-existing members.
                 doImport(getTargetPath(), xml);
-                Authorizable a = userMgr.getAuthorizable("g1");
+                Authorizable a = getUserManager().getAuthorizable("g1");
                 if (a.isGroup()) {
                     // the rep:members property must contain the invalid value
                     boolean found = false;
-                    Node grNode = adminSession.getNode(a.getPath());
+                    Node grNode = s.getNode(a.getPath());
                     for (Value memberValue : grNode.getProperty(UserConstants.REP_MEMBERS).getValues()) {
                         assertEquals(PropertyType.WEAKREFERENCE, memberValue.getType());
                         if (id.equals(memberValue.getString())) {
@@ -85,12 +87,12 @@
                     assertTrue("ImportBehavior.BESTEFFORT must import non-existing members.",found);
 
                     // declared members must not list the invalid entry.
-                    assertNotDeclaredMember((Group) a, id, adminSession);
+                    assertNotDeclaredMember((Group) a, id, s);
                 } else {
                     fail("'g1' was not imported as Group.");
                 }
             } finally {
-                adminSession.refresh(false);
+                s.refresh(false);
             }
         }
     }
@@ -100,7 +102,7 @@
 
         String g1Id = "0120a4f9-196a-3f9e-b9f5-23f31f914da7";
         String nonExistingId = "b2f5ff47-4366-31b6-a533-d8dc3614845d"; // groupId of 'g' group.
-        if (userMgr.getAuthorizable("g") != null) {
+        if (getUserManager().getAuthorizable("g") != null) {
             throw new NotExecutableException();
         }
         String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
@@ -115,11 +117,11 @@
 
         // BESTEFFORT behavior -> must import non-existing members.
         doImport(getTargetPath(), xml);
-        Authorizable g1 = userMgr.getAuthorizable("g1");
+        Authorizable g1 = getUserManager().getAuthorizable("g1");
         if (g1.isGroup()) {
             // the rep:members property must contain the invalid value
             boolean found = false;
-            Node grNode = adminSession.getNode(g1.getPath());
+            Node grNode = getImportSession().getNode(g1.getPath());
             for (Value memberValue : grNode.getProperty(UserConstants.REP_MEMBERS).getValues()) {
                 assertEquals(PropertyType.WEAKREFERENCE, memberValue.getType());
                 if (nonExistingId.equals(memberValue.getString())) {
@@ -138,7 +140,7 @@
 
         String g1Id = "0120a4f9-196a-3f9e-b9f5-23f31f914da7";
         String nonExistingId = "b2f5ff47-4366-31b6-a533-d8dc3614845d"; // groupId of 'g' group.
-        if (userMgr.getAuthorizable("g") != null) {
+        if (getUserManager().getAuthorizable("g") != null) {
             throw new NotExecutableException();
         }
 
@@ -174,10 +176,10 @@
         */
         doImport(getTargetPath() + "/gFolder", xml2);
 
-        Authorizable g = userMgr.getAuthorizable("g");
+        Authorizable g = getUserManager().getAuthorizable("g");
         assertNotNull(g);
         if (g.isGroup()) {
-            assertNotDeclaredMember((Group) g, g1Id, adminSession);
+            assertNotDeclaredMember((Group) g, g1Id, getImportSession());
         } else {
             fail("'g' was not imported as Group.");
         }
@@ -199,10 +201,10 @@
                 "</sv:node>";
 
         doImport(getTargetPath(), xml);
-        User user = userMgr.createUser("angi", "pw");
-        adminSession.save();
+        User user = getUserManager().createUser("angi", "pw");
+        getImportSession().save();
 
-        Group g1 = (Group) userMgr.getAuthorizable("g1");
+        Group g1 = (Group) getUserManager().getAuthorizable("g1");
         assertTrue(g1.isMember(user));
     }
 
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportWithActionsTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportWithActionsTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportWithActionsTest.java	(revision )
@@ -128,11 +128,11 @@
 
         doImport(USERPATH, xml);
 
-        Authorizable a = userMgr.getAuthorizable("t");
+        Authorizable a = getUserManager().getAuthorizable("t");
         assertNotNull(a);
         assertFalse(a.isGroup());
 
-        AccessControlManager acMgr = adminSession.getAccessControlManager();
+        AccessControlManager acMgr = getImportSession().getAccessControlManager();
         AccessControlPolicy[] policies = acMgr.getPolicies(a.getPath());
         assertNotNull(policies);
         assertEquals(1, policies.length);
@@ -159,11 +159,11 @@
 
         doImport(USERPATH, xml);
 
-        Authorizable a = userMgr.getAuthorizable("t");
+        Authorizable a = getUserManager().getAuthorizable("t");
         assertNotNull(a);
         assertFalse(a.isGroup());
 
-        AccessControlManager acMgr = adminSession.getAccessControlManager();
+        AccessControlManager acMgr = getImportSession().getAccessControlManager();
         AccessControlPolicy[] policies = acMgr.getPolicies(a.getPath());
         assertNotNull(policies);
         assertEquals(1, policies.length);
@@ -189,11 +189,11 @@
 
         doImport(GROUPPATH, xml);
 
-        Authorizable a = userMgr.getAuthorizable("g");
+        Authorizable a = getUserManager().getAuthorizable("g");
         assertNotNull(a);
         assertTrue(a.isGroup());
 
-        AccessControlManager acMgr = adminSession.getAccessControlManager();
+        AccessControlManager acMgr = getImportSession().getAccessControlManager();
         AccessControlPolicy[] policies = acMgr.getPolicies(a.getPath());
         assertNotNull(policies);
         assertEquals(1, policies.length);
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithoutAdminTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithoutAdminTest.java	(revision )
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithoutAdminTest.java	(revision )
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.security.user;
+
+import java.util.UUID;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.security.Privilege;
+
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
+import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
+import org.apache.jackrabbit.test.api.util.Text;
+
+/**
+ * Testing group import with default {@link org.apache.jackrabbit.oak.spi.xml.ImportBehavior}
+ */
+public class GroupImportWithoutAdminTest extends GroupImportTest {
+
+    private String uid = "testUser" + UUID.randomUUID();
+    private Session testSession;
+
+    @Override
+    public void before() throws Exception {
+        super.before();
+
+        User u = userMgr.createUser(uid, "pw");
+        adminSession.save();
+
+        AccessControlUtils.addAccessControlEntry(adminSession, Text.getRelativeParent(getTargetPath(), 1), u.getPrincipal(), new String[] {Privilege.JCR_ALL}, true);
+        AccessControlUtils.addAccessControlEntry(adminSession, null, u.getPrincipal(), new String[] {PrivilegeConstants.JCR_NAMESPACE_MANAGEMENT}, true);
+        adminSession.save();
+
+        testSession = adminSession.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
+    }
+
+    @Override
+    public void after() throws Exception {
+        try {
+            testSession.logout();
+
+            Authorizable testUser = userMgr.getAuthorizable(uid);
+            testUser.remove();
+            adminSession.save();
+        } finally {
+            super.after();
+        }
+    }
+
+    @Override
+    protected Session getImportSession() {
+        return testSession;
+    }
+}
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AbstractImportTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AbstractImportTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AbstractImportTest.java	(revision )
@@ -18,7 +18,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -48,7 +47,6 @@
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Test;
 
 import static org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest.dispose;
 import static org.junit.Assert.assertFalse;
@@ -155,8 +153,16 @@
 
     protected abstract String getTargetPath();
 
+    protected Session getImportSession() {
+        return adminSession;
+    }
+
+    protected UserManager getUserManager() throws RepositoryException {
+        return ((JackrabbitSession) getImportSession()).getUserManager();
+    }
+
     protected Node getTargetNode() throws RepositoryException {
-        return adminSession.getNode(getTargetPath());
+        return getImportSession().getNode(getTargetPath());
     }
 
     protected String getExistingUUID() throws RepositoryException {
@@ -171,6 +177,10 @@
     }
 
     protected void doImport(String parentPath, String xml, int importUUIDBehavior) throws Exception {
+        doImport(getImportSession(), parentPath, xml, importUUIDBehavior);
+    }
+
+    protected void doImport(Session importSession, String parentPath, String xml, int importUUIDBehavior) throws Exception {
         InputStream in;
         if (xml.charAt(0) == '<') {
             in = new ByteArrayInputStream(xml.getBytes());
@@ -182,7 +192,7 @@
             in = getClass().getResourceAsStream(xml);
         }
         try {
-            adminSession.importXML(parentPath, in, importUUIDBehavior);
+            importSession.importXML(parentPath, in, importUUIDBehavior);
         } finally {
             in.close();
         }
@@ -195,25 +205,5 @@
             Authorizable member = it.next();
             assertFalse(potentialID.equals(session.getNode(member.getPath()).getIdentifier()));
         }
-    }
-
-    private String getTestXml() {
-        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
-        for (StackTraceElement element : stackTraceElements) {
-            try {
-                Class<?> clazz = Class.forName(element.getClassName());
-                for (Method method : clazz.getMethods()){
-                    if(method.getName().equals(element.getMethodName())){
-                        if (method.getAnnotation(Test.class) != null) {
-                            return clazz.getSimpleName() + "-" + method.getName() + ".xml";
-                        }
-                    }
-
-                }
-            } catch (Exception e) {
-                //  oops do something here
-            }
-        }
-        throw new IllegalArgumentException("no import xml given.");
     }
 }
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportAbortTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportAbortTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportAbortTest.java	(revision )
@@ -61,7 +61,7 @@
             } catch (RepositoryException e) {
                 // success
             } finally {
-                adminSession.refresh(false);
+                getImportSession().refresh(false);
             }
         }
     }
@@ -83,7 +83,7 @@
         } catch (RepositoryException e) {
             // success
         } finally {
-            adminSession.refresh(false);
+            getImportSession().refresh(false);
         }
     }
 }
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportPwExpiryTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportPwExpiryTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportPwExpiryTest.java	(revision )
@@ -20,6 +20,7 @@
 import javax.annotation.CheckForNull;
 import javax.jcr.Node;
 import javax.jcr.Property;
+import javax.jcr.Session;
 
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.User;
@@ -87,8 +88,8 @@
 
         doImport(USERPATH, xml);
 
-        Authorizable authorizable = userMgr.getAuthorizable("x");
-        Node userNode = adminSession.getNode(authorizable.getPath());
+        Authorizable authorizable = getUserManager().getAuthorizable("x");
+        Node userNode = getImportSession().getNode(authorizable.getPath());
         assertTrue(userNode.hasNode(UserConstants.REP_PWD));
         Node pwdNode = userNode.getNode(UserConstants.REP_PWD);
         assertTrue(pwdNode.getDefinition().isProtected());
@@ -121,8 +122,8 @@
         doImport(USERPATH, xml);
 
         // verify that the pwd node has still been created
-        Authorizable authorizable = userMgr.getAuthorizable("x");
-        Node userNode = adminSession.getNode(authorizable.getPath());
+        Authorizable authorizable = getUserManager().getAuthorizable("x");
+        Node userNode = getImportSession().getNode(authorizable.getPath());
         assertTrue(userNode.hasNode(UserConstants.REP_PWD));
         Node pwdNode = userNode.getNode(UserConstants.REP_PWD);
         assertTrue(pwdNode.getDefinition().isProtected());
@@ -165,8 +166,8 @@
 
         doImport(USERPATH, xml);
 
-        Authorizable authorizable = userMgr.getAuthorizable("y");
-        Node userNode = adminSession.getNode(authorizable.getPath());
+        Authorizable authorizable = getUserManager().getAuthorizable("y");
+        Node userNode = getImportSession().getNode(authorizable.getPath());
         assertTrue(userNode.hasNode(UserConstants.REP_PWD));
 
         Node pwdNode = userNode.getNode(UserConstants.REP_PWD);
@@ -186,13 +187,14 @@
     public void testImportExistingUserWithoutExpiryProperty() throws Exception {
 
         String uid = "existing";
-        User user = userMgr.createUser(uid, uid);
+        User user = getUserManager().createUser(uid, uid);
 
+        Session s = getImportSession();
         // change password to force existence of password last modified property
         user.changePassword(uid);
-        adminSession.save();
+        s.save();
 
-        Node userNode = adminSession.getNode(user.getPath());
+        Node userNode = s.getNode(user.getPath());
         assertTrue(userNode.hasNode(UserConstants.REP_PWD));
         Node pwdNode = userNode.getNode(UserConstants.REP_PWD);
         assertTrue(pwdNode.hasProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED));
@@ -213,8 +215,8 @@
 
         doImport(USERPATH, xml);
 
-        Authorizable authorizable = userMgr.getAuthorizable(uid);
-        userNode = adminSession.getNode(authorizable.getPath());
+        Authorizable authorizable = getUserManager().getAuthorizable(uid);
+        userNode = s.getNode(authorizable.getPath());
         assertTrue(userNode.hasNode(UserConstants.REP_PWD));
 
         pwdNode = userNode.getNode(UserConstants.REP_PWD);
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportIgnoreTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportIgnoreTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportIgnoreTest.java	(revision )
@@ -69,7 +69,7 @@
                 doImport(getTargetPath(), xml);
                 // no exception during import: no impersonation must be granted
                 // for the invalid principal name
-                Authorizable a = userMgr.getAuthorizable("t");
+                Authorizable a = getUserManager().getAuthorizable("t");
                 if (!a.isGroup()) {
                     Impersonation imp = ((User)a).getImpersonation();
                     Subject s = new Subject();
@@ -82,7 +82,7 @@
                     fail("Importing 't' didn't create a User.");
                 }
             } finally {
-                adminSession.refresh(false);
+                getImportSession().refresh(false);
             }
         }
     }
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportTest.java	(revision )
@@ -23,6 +23,7 @@
 import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.security.auth.Subject;
 
@@ -74,9 +75,9 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(getImportSession().hasPendingChanges());
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t", newUser.getPrincipal().getName());
@@ -84,7 +85,7 @@
         assertTrue(((User) newUser).isDisabled());
         assertEquals("disabledUser", ((User) newUser).getDisabledReason());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = getImportSession().getNode(newUser.getPath());
         assertTrue(n.isNew());
         assertTrue(n.getParent().isSame(target));
 
@@ -95,7 +96,7 @@
 
         // saving changes of the import -> must succeed. add mandatory
         // props should have been created.
-        adminSession.save();
+        getImportSession().save();
     }
 
     /**
@@ -123,16 +124,16 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(getImportSession().hasPendingChanges());
 
-        Authorizable newGroup = userMgr.getAuthorizable("g");
+        Authorizable newGroup = getUserManager().getAuthorizable("g");
         assertNotNull(newGroup);
         assertTrue(target.hasNode("g"));
         assertTrue(target.hasProperty("g/rep:principalName"));
 
         // saving changes of the import -> must fail
         try {
-            adminSession.save();
+            getImportSession().save();
             fail("Import must be incomplete. Saving changes must fail.");
         } catch (ConstraintViolationException e) {
             // success
@@ -157,7 +158,7 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(getImportSession().hasPendingChanges());
 
         // node must be present:
         assertTrue(target.hasNode("t"));
@@ -166,17 +167,17 @@
 
         // but UserManager.getAuthorizable(String) will not find the
         // authorizable
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNull(newUser);
     }
 
     @Test
     public void testExistingPrincipal() throws Exception {
         Principal existing = null;
-        PrincipalIterator principalIterator = ((JackrabbitSession) adminSession).getPrincipalManager().getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
+        PrincipalIterator principalIterator = ((JackrabbitSession) getImportSession()).getPrincipalManager().getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
         while (principalIterator.hasNext()) {
             Principal p = principalIterator.nextPrincipal();
-            if (userMgr.getAuthorizable(p) != null) {
+            if (getUserManager().getAuthorizable(p) != null) {
                 existing = p;
                 break;
             }
@@ -195,7 +196,7 @@
 
         try {
             doImport(getTargetPath(), xml);
-            adminSession.save();
+            getImportSession().save();
 
             fail("Import must detect conflicting principals.");
         } catch (RepositoryException e) {
@@ -218,10 +219,10 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(getImportSession().hasPendingChanges());
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
-        Node n = adminSession.getNode(newUser.getPath());
+        Authorizable newUser = getUserManager().getAuthorizable("t");
+        Node n = getImportSession().getNode(newUser.getPath());
 
         String pwValue = n.getProperty(UserConstants.REP_PASSWORD).getString();
         assertFalse(plainPw.equals(pwValue));
@@ -251,9 +252,9 @@
         doImport(getTargetPath(), xml);
 
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(getImportSession().hasPendingChanges());
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
 
         assertTrue(target.hasNode("t"));
@@ -276,22 +277,23 @@
                 "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" +
                 "</sv:node>");
 
+        Session s = getImportSession();
         for (String xml : incompleteXml) {
-            Node target = adminSession.getNode(getTargetPath());
+            Node target = s.getNode(getTargetPath());
             try {
                 doImport(getTargetPath(), xml);
                 // saving changes of the import -> must fail as mandatory prop is missing
                 try {
-                    adminSession.save();
+                    s.save();
                     fail("Import must be incomplete. Saving changes must fail.");
                 } catch (ConstraintViolationException e) {
                     // success
                 }
             } finally {
-                adminSession.refresh(false);
+                s.refresh(false);
                 if (target.hasNode("t")) {
                     target.getNode("t").remove();
-                    adminSession.save();
+                    s.save();
                 }
             }
         }
@@ -311,10 +313,10 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable user = userMgr.getAuthorizable("t");
+        Authorizable user = getUserManager().getAuthorizable("t");
         assertNotNull(user);
         assertFalse(user.isGroup());
-        assertFalse(adminSession.propertyExists(user.getPath() + "/rep:password"));
+        assertFalse(getImportSession().propertyExists(user.getPath() + "/rep:password"));
     }
 
     @Test
@@ -342,16 +344,17 @@
         Node target = getTargetNode();
         doImport(getTargetPath(), xml);
 
+        Session s = getImportSession();
         assertTrue(target.isModified());
-        assertTrue(adminSession.hasPendingChanges());
+        assertTrue(s.hasPendingChanges());
 
-        Authorizable newUser = userMgr.getAuthorizable("t3");
+        Authorizable newUser = getUserManager().getAuthorizable("t3");
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t3", newUser.getPrincipal().getName());
         assertEquals("t3", newUser.getID());
 
-        Node n = adminSession.getNode(newUser.getPath());
+        Node n = s.getNode(newUser.getPath());
         assertTrue(n.isNew());
 
         Node parent = n.getParent();
@@ -383,10 +386,10 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
 
-        Authorizable u2 = userMgr.getAuthorizable("g");
+        Authorizable u2 = getUserManager().getAuthorizable("g");
         assertNotNull(u2);
 
         Subject subj = new Subject();
@@ -413,7 +416,7 @@
 
         // saving changes of the import -> must succeed. add mandatory
         // props should have been created.
-        adminSession.save();
+        getImportSession().save();
     }
 
     /**
@@ -432,14 +435,16 @@
                 "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" +
                 "</sv:node>";
         doImport(getTargetPath(), xml);
-        adminSession.save();
 
+        Session s = getImportSession();
+        s.save();
+
         // re-import should succeed if UUID-behavior is set accordingly
         doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
 
         // saving changes of the import -> must succeed. add mandatory
         // props should have been created.
-        adminSession.save();
+        s.save();
     }
 
     @Test
@@ -478,13 +483,14 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Session s = getImportSession();
+        Authorizable newUser = getUserManager().getAuthorizable("t");
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t", newUser.getID());
-        assertTrue(adminSession.propertyExists(newUser.getPath() + "/rep:authorizableId"));
-        assertEquals("t", adminSession.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
-        adminSession.save();
+        assertTrue(s.propertyExists(newUser.getPath() + "/rep:authorizableId"));
+        assertEquals("t", s.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
+        s.save();
     }
 
     /**
@@ -503,14 +509,15 @@
 
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
 
+        Session s = getImportSession();
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t", newUser.getID());
-        assertTrue(adminSession.propertyExists(newUser.getPath() + "/rep:authorizableId"));
-        assertEquals("t", adminSession.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
-        adminSession.save();
+        assertTrue(s.propertyExists(newUser.getPath() + "/rep:authorizableId"));
+        assertEquals("t", s.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
+        s.save();
     }
 
     /**
@@ -531,14 +538,15 @@
                 "</sv:node>";
         doImport(getTargetPath(), xml);
 
-        Authorizable newUser = userMgr.getAuthorizable("t");
+        Authorizable newUser = getUserManager().getAuthorizable("t");
 
+        Session s = getImportSession();
         assertNotNull(newUser);
         assertFalse(newUser.isGroup());
         assertEquals("t", newUser.getID());
-        assertTrue(adminSession.propertyExists(newUser.getPath() + "/rep:authorizableId"));
-        assertEquals("t", adminSession.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
-        adminSession.save();
+        assertTrue(s.propertyExists(newUser.getPath() + "/rep:authorizableId"));
+        assertEquals("t", s.getProperty(newUser.getPath() + "/rep:authorizableId").getString());
+        s.save();
     }
 
     /**
Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportAbortTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportAbortTest.java	(revision 1672257)
+++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportAbortTest.java	(revision )
@@ -64,7 +64,7 @@
             } catch (RepositoryException e) {
                 // success as well
             } finally {
-                adminSession.refresh(false);
+                getImportSession().refresh(false);
             }
         }
     }
