use of org.apache.jackrabbit.core.security.principal.PrincipalImpl in project jackrabbit-oak by apache.
the class UserImportFromJackrabbit method testUUIDBehaviorReplaceFromRenamed3.
/**
* @since Oak 1.2
*/
@Test
public void testUUIDBehaviorReplaceFromRenamed3() throws Exception {
// create authorizable
User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
String originalPath = u.getPath();
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" + "<sv:node sv:name=\"" + randomNodeName + "\" 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:User</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + " <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + " <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
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 = importSession.getNode(newUser.getPath());
assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
assertEquals(UserConstants.REP_AUTHORIZABLE_ID, randomNodeName, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
// the node name MUST contain the id as there is no rep:authorizableId.
try {
importSession.save();
fail("Importing an authorizable with mismatch between authorizableId and uuid must fail.");
} catch (ConstraintViolationException e) {
// success
assertTrue(e.getMessage().contains("OakConstraint0021"));
}
}
use of org.apache.jackrabbit.core.security.principal.PrincipalImpl in project jackrabbit-oak by apache.
the class UserImportFromJackrabbit method testUUIDBehaviorRemoveFromRenamed2.
/**
* @since Oak 1.2
*/
@Test
public void testUUIDBehaviorRemoveFromRenamed2() throws Exception {
// create authorizable
User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
String initialPath = u.getPath();
String movedPath = Text.getRelativeParent(initialPath, 1) + '/' + randomNodeName;
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" + "<sv:node sv:name=\"" + randomNodeName + "\" 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:User</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + " <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + " <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
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 = importSession.getNode(newUser.getPath());
assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
assertEquals(UserConstants.REP_AUTHORIZABLE_ID, randomNodeName, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
// which is detected during save as it looks like the id had been modified.
try {
importSession.save();
fail("Importing an authorizable with mismatch between authorizableId and uuid must fail.");
} catch (ConstraintViolationException e) {
// success
assertTrue(e.getMessage().contains("OakConstraint0021"));
}
}
use of org.apache.jackrabbit.core.security.principal.PrincipalImpl in project jackrabbit-oak by apache.
the class UserImportFromJackrabbit method testUUIDBehaviorRemoveFromRenamed.
/**
* @since Oak 1.2
*/
@Test
public void testUUIDBehaviorRemoveFromRenamed() throws Exception {
// create authorizable
User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
String initialPath = u.getPath();
String movedPath = Text.getRelativeParent(initialPath, 1) + '/' + randomNodeName;
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" + "<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\">" + " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + " <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + " <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
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 = 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.
importSession.save();
}
use of org.apache.jackrabbit.core.security.principal.PrincipalImpl in project jackrabbit-oak by apache.
the class UserImportFromJackrabbit method testUUIDBehaviorRemoveFromRenamed3.
/**
* @since Oak 1.2
*/
@Test
public void testUUIDBehaviorRemoveFromRenamed3() throws Exception {
// create authorizable
User u = getUserManager().createUser(uid, null, new PrincipalImpl(uid), intermediatePath);
String originalPath = u.getPath();
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" + "<sv:node sv:name=\"" + randomNodeName + "\" 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:User</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + " <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + " <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
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 = importSession.getNode(newUser.getPath());
assertTrue(n.hasProperty(UserConstants.REP_AUTHORIZABLE_ID));
assertEquals(UserConstants.REP_AUTHORIZABLE_ID, randomNodeName, n.getProperty(UserConstants.REP_AUTHORIZABLE_ID).getString());
// fact that in JR 2.x the node name MUST contain the id.
try {
importSession.save();
fail("Importing an authorizable with mismatch between authorizableId and uuid must fail.");
} catch (ConstraintViolationException e) {
// success
assertTrue(e.getMessage().contains("OakConstraint0021"));
}
}
use of org.apache.jackrabbit.core.security.principal.PrincipalImpl in project jackrabbit-oak by apache.
the class UserImportFromJackrabbit method testUUIDBehaviorReplace.
/**
* @since Oak 1.2
*/
@Test
public void testUUIDBehaviorReplace() throws Exception {
// create authorizable
User u = getUserManager().createUser(uid, null, new PrincipalImpl("t"), getTargetPath() + "/foo/bar/test");
String initialPath = u.getPath();
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\">" + " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + " <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + " <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
doImport(getTargetPath(), xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
Authorizable newUser = getUserManager().getAuthorizable(uid);
// replace should retain path
assertEquals(initialPath, newUser.getPath());
assertFalse(getTargetPath().equals(Text.getRelativeParent(newUser.getPath(), 1)));
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
importSession.save();
}
Aggregations