String altWsp = getAlternativeWorkspaceName();
if (altWsp == null) {
throw new NotExecutableException();
}
UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
Session s = getHelper().getSuperuserSession(altWsp);
User u = null;
try {
// other users created in the default workspace...
u = uMgr.createUser("testUser", "testUser");
superuser.save();
String userPath = null;
if (u.getPrincipal() instanceof ItemBasedPrincipal) {
userPath = ((ItemBasedPrincipal) u.getPrincipal()).getPath();
assertTrue(superuser.nodeExists(userPath));
} else {
throw new NotExecutableException();
}
// ... must not be present in the alternate-workspace
UserManager umgr = ((JackrabbitSession) s).getUserManager();
assertNull(umgr.getAuthorizable("testUser"));
assertFalse(s.nodeExists(userPath));
String clonePath = userPath;
String parentPath = Text.getRelativeParent(clonePath, 1);
while (!s.nodeExists(parentPath)) {
clonePath = parentPath;
parentPath = Text.getRelativeParent(parentPath, 1);
}
// clone the user into the second workspace
s.getWorkspace().clone(superuser.getWorkspace().getName(), clonePath, clonePath, true);
// ... now the user must be visible
assertNotNull(umgr.getAuthorizable("testUser"));
if (userPath != null) {
assertTrue(s.nodeExists(userPath));
}
// ... and able to login to that workspace
Session us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()), altWsp);