You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2013/05/07 14:17:03 UTC
svn commit: r1479877 [2/2] - in /jackrabbit/oak/trunk:
oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak-jcr/
oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/
Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportTest.java?rev=1479877&r1=1479876&r2=1479877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportTest.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportTest.java Tue May 7 12:17:02 2013
@@ -16,13 +16,11 @@
*/
package org.apache.jackrabbit.oak.jcr.security.user;
-import java.io.IOException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.UUID;
import javax.jcr.ImportUUIDBehavior;
import javax.jcr.ItemExistsException;
import javax.jcr.Node;
@@ -38,44 +36,20 @@ import org.apache.jackrabbit.api.securit
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.Impersonation;
import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
-import org.apache.jackrabbit.oak.spi.xml.ImportBehavior;
import org.apache.jackrabbit.test.NotExecutableException;
-import org.junit.Ignore;
import org.junit.Test;
-import org.xml.sax.SAXException;
/**
- * UserImportTest...
+ * Testing user/group import with default {@link org.apache.jackrabbit.oak.spi.xml.ImportBehavior}
+ *
+ * TODO: add tests specifying 'rep:authorizableID' and nodeName != userId
*/
public class UserImportTest extends AbstractImportTest {
- private JackrabbitSession jrSession;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- // avoid collision with testing a-folders that may have been created
- // with another test (but not removed as user/groups got removed)
- String path = USERPATH + "/t";
- if (superuser.nodeExists(path)) {
- superuser.getNode(path).remove();
- }
- path = GROUPPATH + "/g";
- if (superuser.nodeExists(path)) {
- superuser.getNode(path).remove();
- }
- superuser.save();
- jrSession = (JackrabbitSession) superuser;
- }
-
@Override
- protected void tearDown() throws Exception {
- //TODO
- try {
- super.tearDown();
- } catch (Exception ignore) {}
+ protected String getImportBehavior() {
+ return null;
}
@Test
@@ -168,6 +142,10 @@ public class UserImportTest extends Abst
}
}
+ /**
+ * @since OAK 1.0 : constraintviolation is no longer detected during import
+ * but only upon save.
+ */
@Test
public void testImportGroupIntoUsersTree() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -193,12 +171,12 @@ public class UserImportTest extends Abst
assertTrue(superuser.hasPendingChanges());
Authorizable newGroup = userMgr.getAuthorizable("g");
- assertNull(newGroup);
+ //assertNull(newGroup); TODO: adjust test to oak requirements
assertTrue(target.hasNode("g"));
- assertFalse(target.hasProperty("g/rep:principalName"));
+ //assertFalse(target.hasProperty("g/rep:principalName")); TODO: adjust test to oak requirements
- // saving changes of the import -> must fail as mandatory prop is missing
+ // saving changes of the import -> must fail
try {
superuser.save();
fail("Import must be incomplete. Saving changes must fail.");
@@ -256,7 +234,7 @@ public class UserImportTest extends Abst
@Test
public void testExistingPrincipal() throws Exception {
Principal existing = null;
- PrincipalIterator principalIterator = jrSession.getPrincipalManager().getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
+ PrincipalIterator principalIterator = ((JackrabbitSession) superuser).getPrincipalManager().getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
while (principalIterator.hasNext()) {
Principal p = principalIterator.nextPrincipal();
if (userMgr.getAuthorizable(p) != null) {
@@ -276,14 +254,15 @@ public class UserImportTest extends Abst
" <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>" + existing.getName() +"</sv:value></sv:property>" +
"</sv:node>";
- Node target = superuser.getNode(USERPATH);
try {
doImport(USERPATH, xml);
+ superuser.save();
+
fail("Import must detect conflicting principals.");
- } catch (SAXException e) {
+ } catch (RepositoryException e) {
// success
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
}
}
@@ -308,11 +287,13 @@ public class UserImportTest extends Abst
try {
doImport(GROUPPATH, xml);
+ superuser.save();
+
fail("Import must detect conflicting principals.");
- } catch (SAXException e) {
+ } catch (RepositoryException e) {
// success
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
}
}
@@ -336,7 +317,7 @@ public class UserImportTest extends Abst
doImport(GROUPPATH, xml);
assertTrue(target.isModified());
- assertTrue(jrSession.hasPendingChanges());
+ assertTrue(superuser.hasPendingChanges());
Authorizable newGroup = userMgr.getAuthorizable("g");
assertNotNull(newGroup);
@@ -347,17 +328,17 @@ public class UserImportTest extends Abst
// saving changes of the import -> must fail as mandatory prop is missing
try {
- jrSession.save();
+ superuser.save();
fail("Import must be incomplete. Saving changes must fail.");
} catch (ConstraintViolationException e) {
// success
}
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("g")) {
target.getNode("g").remove();
- jrSession.save();
+ superuser.save();
}
}
}
@@ -378,7 +359,7 @@ public class UserImportTest extends Abst
doImport(USERPATH, xml);
assertTrue(target.isModified());
- assertTrue(jrSession.hasPendingChanges());
+ assertTrue(superuser.hasPendingChanges());
Authorizable newUser = userMgr.getAuthorizable("t");
Node n = superuser.getNode(newUser.getPath());
@@ -388,10 +369,15 @@ public class UserImportTest extends Abst
assertTrue(pwValue.toLowerCase().startsWith("{sha"));
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
}
}
+ /**
+ * @since OAK 1.0 : password property is not longer mandatory -> multivalued
+ * property will just be ignored (instead of throwing ConstraintViolationException
+ * upon save).
+ */
@Test
public void testMultiValuedPassword() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -405,15 +391,13 @@ public class UserImportTest extends Abst
importing a user with a multi-valued rep:password property
- nonProtected node rep:User must be created.
- property rep:password must be created regularly without being protected
- - saving changes must fail with ConstraintViolationEx. as the protected
- mandatory property rep:password is missing
*/
Node target = superuser.getNode(USERPATH);
try {
doImport(USERPATH, xml);
assertTrue(target.isModified());
- assertTrue(jrSession.hasPendingChanges());
+ assertTrue(superuser.hasPendingChanges());
Authorizable newUser = userMgr.getAuthorizable("t");
assertNotNull(newUser);
@@ -421,20 +405,11 @@ public class UserImportTest extends Abst
assertTrue(target.hasNode("t"));
assertTrue(target.hasProperty("t/rep:password"));
assertFalse(target.getProperty("t/rep:password").getDefinition().isProtected());
-
- // saving changes of the import -> must fail as mandatory prop is missing
- try {
- jrSession.save();
- fail("Import must be incomplete. Saving changes must fail.");
- } catch (ConstraintViolationException e) {
- // success
- }
-
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("t")) {
target.getNode("t").remove();
- jrSession.save();
+ superuser.save();
}
}
}
@@ -451,7 +426,6 @@ public class UserImportTest extends Abst
incompleteXml.add("<?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\">" +
" <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:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" +
"</sv:node>");
@@ -461,21 +435,50 @@ public class UserImportTest extends Abst
doImport(USERPATH, xml);
// saving changes of the import -> must fail as mandatory prop is missing
try {
- jrSession.save();
+ superuser.save();
fail("Import must be incomplete. Saving changes must fail.");
} catch (ConstraintViolationException e) {
// success
}
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("t")) {
target.getNode("t").remove();
- jrSession.save();
+ superuser.save();
}
}
}
}
+ /**
+ * @since OAK 1.0 : importing User without password must succeed.
+ */
+ @Test
+ public void testUserWithoutPassword() throws Exception {
+ 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\">" +
+ " <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:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" +
+ "</sv:node>";
+
+ Node target = superuser.getNode(USERPATH);
+ try {
+ doImport(USERPATH, xml);
+
+ Authorizable user = userMgr.getAuthorizable("t");
+ assertNotNull(user);
+ assertFalse(user.isGroup());
+ assertFalse(superuser.propertyExists(user.getPath()+"/rep:password"));
+ } finally {
+ superuser.refresh(false);
+ if (target.hasNode("t")) {
+ target.getNode("t").remove();
+ superuser.save();
+ }
+ }
+ }
+
@Test
public void testIncompleteGroup() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
@@ -493,17 +496,17 @@ public class UserImportTest extends Abst
doImport(GROUPPATH, xml);
// saving changes of the import -> must fail as mandatory prop is missing
try {
- jrSession.save();
+ superuser.save();
fail("Import must be incomplete. Saving changes must fail.");
} catch (ConstraintViolationException e) {
// success
}
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("g")) {
target.getNode("g").remove();
- jrSession.save();
+ superuser.save();
}
}
}
@@ -535,7 +538,7 @@ public class UserImportTest extends Abst
doImport(USERPATH, xml);
assertTrue(target.isModified());
- assertTrue(jrSession.hasPendingChanges());
+ assertTrue(superuser.hasPendingChanges());
Authorizable newUser = userMgr.getAuthorizable("t3");
assertNotNull(newUser);
@@ -555,7 +558,7 @@ public class UserImportTest extends Abst
assertTrue(target.hasNode("some/intermediate/path"));
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
}
}
@@ -588,20 +591,20 @@ public class UserImportTest extends Abst
Group g1 = (Group) userMgr.getAuthorizable("g1");
assertNotNull(g1);
- Node n = jrSession.getNode(g1.getPath());
+ Node n = superuser.getNode(g1.getPath());
assertTrue(n.hasProperty(UserConstants.REP_MEMBERS) || n.hasNode(UserConstants.NT_REP_MEMBERS));
// getWeakReferences only works upon save.
- jrSession.save();
+ superuser.save();
assertTrue(g1.isMember(g));
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("gFolder")) {
target.getNode("gFolder").remove();
}
- jrSession.save();
+ superuser.save();
}
}
@@ -633,20 +636,20 @@ public class UserImportTest extends Abst
Group g1 = (Group) userMgr.getAuthorizable("g1");
assertNotNull(g1);
- Node n = jrSession.getNode(g1.getPath());
+ Node n = superuser.getNode(g1.getPath());
assertTrue(n.hasProperty(UserConstants.REP_MEMBERS) || n.hasNode(UserConstants.NT_REP_MEMBERS));
// getWeakReferences only works upon save.
- jrSession.save();
+ superuser.save();
assertTrue(g1.isMember(g));
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("gFolder")) {
target.getNode("gFolder").remove();
}
- jrSession.save();
+ superuser.save();
}
}
@@ -677,7 +680,7 @@ public class UserImportTest extends Abst
assertNotNull(g1);
// getWeakReferences only works upon save.
- jrSession.save();
+ superuser.save();
assertTrue(g1.isMember(admin));
@@ -688,126 +691,9 @@ public class UserImportTest extends Abst
assertTrue(found);
} finally {
- jrSession.refresh(false);
- target.getNode("gFolder").remove();
- jrSession.save();
- }
- }
-
- @Test
- public void testImportNonExistingMemberIgnore() throws Exception {
- Node n = testRootNode.addNode(nodeName1, ntUnstructured);
- n.addMixin(mixReferenceable);
-
- List<String> invalid = new ArrayList<String>();
- invalid.add(UUID.randomUUID().toString()); // random uuid
- invalid.add(n.getUUID()); // uuid of non-authorizable node
-
- 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\">" +
- " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" +
- "<sv:node sv:name=\"g1\"><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>0120a4f9-196a-3f9e-b9f5-23f31f914da7</sv:value></sv:property>" +
- " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g1</sv:value></sv:property>" +
- " <sv:property sv:name=\"rep:members\" sv:type=\"WeakReference\"><sv:value>" +id+ "</sv:value></sv:property>" +
- "</sv:node>" +
- "</sv:node>";
- try {
- doImport(GROUPPATH, xml, ImportBehavior.IGNORE);
- // there should be no exception during import,
- // but invalid members must be ignored.
- Authorizable a = userMgr.getAuthorizable("g1");
- if (a.isGroup()) {
- assertNotDeclaredMember((Group) a, id, superuser);
- } else {
- fail("'g1' was not imported as Group.");
- }
- } finally {
- jrSession.refresh(false);
- }
- }
- }
-
- @Ignore("OAK-414")
- @Test
- public void testImportNonExistingMemberAbort() throws Exception {
- Node n = testRootNode.addNode(nodeName1, ntUnstructured);
- n.addMixin(mixReferenceable);
-
- List<String> invalid = new ArrayList<String>();
- invalid.add(UUID.randomUUID().toString()); // random uuid
- invalid.add(n.getUUID()); // uuid of non-authorizable node
-
- 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\">" +
- " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" +
- "<sv:node sv:name=\"g1\"><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>0120a4f9-196a-3f9e-b9f5-23f31f914da7</sv:value></sv:property>" +
- " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g1</sv:value></sv:property>" +
- " <sv:property sv:name=\"rep:members\" sv:type=\"WeakReference\"><sv:value>" +id+ "</sv:value></sv:property>" +
- "</sv:node>" +
- "</sv:node>";
- try {
- doImport(GROUPPATH, xml, ImportBehavior.ABORT);
- // import behavior ABORT -> should throw.
- fail("importing invalid members -> must throw.");
- } catch (SAXException e) {
- // success as well
- } finally {
- superuser.refresh(false);
- }
- }
- }
-
- @Test
- public void testImportSelfAsGroupIgnore() throws Exception {
- String invalidId = "0120a4f9-196a-3f9e-b9f5-23f31f914da7"; // uuid of the group itself
- 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>" +
- "<sv:node sv:name=\"g1\"><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>"+invalidId+"</sv:value></sv:property>" +
- " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g1</sv:value></sv:property>" +
- " <sv:property sv:name=\"rep:members\" sv:type=\"WeakReference\"><sv:value>" +invalidId+ "</sv:value></sv:property>" +
- "</sv:node>" +
- "</sv:node>";
- try {
- doImport(GROUPPATH, xml);
- // no exception during import -> member must have been ignored though.
- Authorizable a = userMgr.getAuthorizable("g1");
- if (a.isGroup()) {
- assertNotDeclaredMember((Group) a, invalidId, superuser);
- } else {
- fail("'g1' was not imported as Group.");
- }
- } finally {
- jrSession.refresh(false);
- }
- }
-
- @Ignore("OAK-414")
- @Test
- public void testImportSelfAsGroupAbort() throws Exception {
-
- String invalidId = "0120a4f9-196a-3f9e-b9f5-23f31f914da7"; // uuid of the group itself
- 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>" +
- "<sv:node sv:name=\"g1\"><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>"+invalidId+"</sv:value></sv:property>" +
- " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g1</sv:value></sv:property>" +
- " <sv:property sv:name=\"rep:members\" sv:type=\"WeakReference\"><sv:value>" +invalidId+ "</sv:value></sv:property>" +
- "</sv:node>" +
- "</sv:node>";
- try {
- doImport(GROUPPATH, xml, ImportBehavior.ABORT);
- fail("Importing self as group with ImportBehavior.ABORT must fail.");
- } catch (SAXException e) {
- // success.
- }finally {
superuser.refresh(false);
+ target.getNode("gFolder").remove();
+ superuser.save();
}
}
@@ -844,78 +730,7 @@ public class UserImportTest extends Abst
assertTrue(imp.allows(subj));
} finally {
- jrSession.refresh(false);
- }
- }
-
- @Test
- public void testImportInvalidImpersonationIgnore() throws Exception {
- List<String> invalid = new ArrayList<String>();
- invalid.add("anybody"); // an non-existing princ-name
- invalid.add("administrators"); // a group
- invalid.add("t"); // principal of the user itself.
-
- for (String principalName : invalid) {
- 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\">" +
- " <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:impersonators\" sv:type=\"String\"><sv:value>" +principalName+ "</sv:value></sv:property>" +
- "</sv:node>";
- Subject subj = new Subject();
- subj.getPrincipals().add(new PrincipalImpl(principalName));
-
- Node target = superuser.getNode(USERPATH);
- try {
- doImport(USERPATH, xml);
- // no exception during import: no impersonation must be granted
- // for the invalid principal name
- Authorizable a = userMgr.getAuthorizable("t");
- if (!a.isGroup()) {
- Impersonation imp = ((User)a).getImpersonation();
- Subject s = new Subject();
- s.getPrincipals().add(new PrincipalImpl(principalName));
- assertFalse(imp.allows(s));
- for (PrincipalIterator it = imp.getImpersonators(); it.hasNext();) {
- assertFalse(principalName.equals(it.nextPrincipal().getName()));
- }
- } else {
- fail("Importing 't' didn't create a User.");
- }
- } finally {
- jrSession.refresh(false);
- }
- }
- }
-
- @Ignore("OAK-414")
- @Test
- public void testImportInvalidImpersonationAbort() throws Exception {
- List<String> invalid = new ArrayList<String>();
- invalid.add("anybody"); // an non-existing princ-name
- invalid.add("administrators"); // a group
- invalid.add("t"); // principal of the user itself.
-
- for (String principalName : invalid) {
- 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\">" +
- " <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:impersonators\" sv:type=\"String\"><sv:value>" +principalName+ "</sv:value></sv:property>" +
- "</sv:node>";
- Subject subj = new Subject();
- subj.getPrincipals().add(new PrincipalImpl(principalName));
-
- try {
- doImport(USERPATH, xml, ImportBehavior.ABORT);
- fail("UserImporter.ImportBehavior.ABORT -> importing invalid impersonators must throw.");
- } catch (SAXException e) {
- // success
- } finally {
- superuser.refresh(false);
- }
+ superuser.refresh(false);
}
}
@@ -939,13 +754,13 @@ public class UserImportTest extends Abst
// saving changes of the import -> must succeed. add mandatory
// props should have been created.
- jrSession.save();
+ superuser.save();
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("t")) {
target.getNode("t").remove();
- jrSession.save();
+ superuser.save();
}
}
}
@@ -954,9 +769,7 @@ public class UserImportTest extends Abst
* Same as {@link #testImportUuidCollisionRemoveExisting} with the single
* difference that the inital import is saved before being overwritten.
*
- * @throws RepositoryException
- * @throws IOException
- * @throws SAXException
+ * @throws Exception
*/
@Test
public void testImportUuidCollisionRemoveExisting2() throws Exception {
@@ -971,7 +784,7 @@ public class UserImportTest extends Abst
Node target = superuser.getNode(USERPATH);
try {
doImport(USERPATH, xml);
- jrSession.save();
+ superuser.save();
//TODO different IgnoreBehavior needed?
// re-import should succeed if UUID-behavior is set accordingly
@@ -979,13 +792,13 @@ public class UserImportTest extends Abst
// saving changes of the import -> must succeed. add mandatory
// props should have been created.
- jrSession.save();
+ superuser.save();
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("t")) {
target.getNode("t").remove();
- jrSession.save();
+ superuser.save();
}
}
}
@@ -1007,74 +820,12 @@ public class UserImportTest extends Abst
doImport(USERPATH, xml, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
fail("UUID collision must be handled according to the uuid behavior.");
- } catch (SAXException e) {
- assertTrue(e.getException() instanceof ItemExistsException);
- // success.
} catch (ItemExistsException e) {
// success.
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
if (target.hasNode("t")) {
target.getNode("t").remove();
- jrSession.save();
- }
- }
- }
-
- @Ignore("OAK-414")
- @Test
- public void testImportGroupMembersFromNodesBestEffort() throws Exception {
- String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><sv:node sv:name=\"s\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:sling=\"http://sling.apache.org/jcr/sling/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:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property><sv:property sv:name=\"jcr:created\" sv:type=\"Date\"><sv:value>2010-08-17T18:22:20.086+02:00</sv:value></sv:property><sv:property sv:name=\"jcr:createdBy\" sv:type=\"String\"><sv:value>admin</sv:value></sv:property><sv:node sv:name=\"sh\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property><sv:property sv:name=\"jcr
:created\" sv:type=\"Date\"><sv:value>2010-08-17T18:22:20.086+02:00</sv:value></sv:property><sv:property sv:name=\"jcr:createdBy\" sv:type=\"String\"><sv:value>admin</sv:value></sv:property><sv:node sv:name=\"shrimps\"><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>08429aec-6f09-30db-8c83-1a2a57fc760c</sv:value></sv:property><sv:property sv:name=\"jcr:created\" sv:type=\"Date\">" +
- "<sv:value>2010-08-17T18:22:20.086+02:00</sv:value></sv:property><sv:property sv:name=\"jcr:createdBy\" sv:type=\"String\"><sv:value>admin</sv:value></sv:property><sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>shrimps</sv:value></sv:property><sv:node sv:name=\"rep:members\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:node sv:name=\"adi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:node sv:name=\"adi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"adi\" sv:type=\"WeakReference\"><sv:value>c46335eb-267e-3e1c-9e5b-017acb4cd799</sv:value></sv:property><sv:property sv:name=\"admin\" sv:type=\"WeakReference\"><sv:value>21232f29-7a57-35a7-8389-4a0e4a801fc3</sv:value></sv:property></sv:node><sv:node sv:name=\"angi\"><sv:property sv:name=
\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"angi\" sv:type=\"WeakReference\"><sv:value>a468b64f-b1df-377c-b325-20d97aaa1ad9</sv:value></sv:property><sv:property sv:name=\"anonymous\" sv:type=\"WeakReference\"><sv:value>294de355-7d9d-30b3-92d8-a1e6aab028cf</sv:value></sv:property><sv:property sv:name=\"cati\" sv:type=\"WeakReference\"><sv:value>f08910b6-41c8-3cb9-a648-1dddd14b132d</sv:value></sv:property></sv:node></sv:node><sv:n" +
- "ode sv:name=\"debbi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:node sv:name=\"debbi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"debbi\" sv:type=\"WeakReference\"><sv:value>d53bedf9-ebb8-3117-a8b8-162d32b4bee2</sv:value></sv:property><sv:property sv:name=\"eddi\" sv:type=\"WeakReference\"><sv:value>1795fa1a-3d20-3a64-996e-eaaeb520a01e</sv:value></sv:property><sv:property sv:name=\"gabi\" sv:type=\"WeakReference\"><sv:value>a0d499c7-5105-3663-8611-a32779a57104</sv:value></sv:property><sv:property sv:name=\"hansi\" sv:type=\"WeakReference\"><sv:value>9ea4d671-8ed1-399a-8401-59487a14d00a</sv:value></sv:property></sv:node><sv:node sv:name=\"hari\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"hari\" sv:type=\"WeakReference\"><sv:value
>a9bcf1e4-d7b9-3a22-a297-5c812d938889</sv:value></sv:property><sv:property sv:name=\"lisi\" sv:type=\"WeakReference\"><sv:value>dc3a8f16-70d6-3bea-a9b7-b65048a0ac40</sv:value></sv:property></sv:node><sv:node sv:name=\"luzi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"luzi\" sv:type=\"WeakReference\"><sv:value>9ec299fd-3461-3f1a-9749-92a76f2516eb</sv:value></sv:property><sv:property sv:name=\"pipi\" sv:type=" +
- "\"WeakReference\"><sv:value>16d5d24f-5b09-3199-9bd4-e5f57bf11237</sv:value></sv:property><sv:property sv:name=\"susi\" sv:type=\"WeakReference\"><sv:value>536931d8-0dec-318c-b3db-9612bdd004d4</sv:value></sv:property></sv:node></sv:node></sv:node></sv:node></sv:node></sv:node>";
-
- List<String> createdUsers = new LinkedList<String>();
- Node groupsNode = superuser.getNode(GROUPPATH);
- try {
- String[] users = {"angi", "adi", "hansi", "lisi", "luzi", "susi", "pipi", "hari", "gabi", "eddi",
- "debbi", "cati", "admin", "anonymous"};
-
- doImport(groupsNode.getPath(), xml, ImportBehavior.BESTEFFORT);
- if (!userMgr.isAutoSave()) {
- superuser.save();
- }
-
- for (String user : users) {
- if (userMgr.getAuthorizable(user) == null) {
- userMgr.createUser(user, user);
- createdUsers.add(user);
- }
- }
- if (!userMgr.isAutoSave()) {
- superuser.save();
- }
-
- Authorizable aShrimps = userMgr.getAuthorizable("shrimps");
- assertNotNull(aShrimps);
- assertTrue(aShrimps.isGroup());
-
- Group gShrimps = (Group) aShrimps;
- for (String user : users) {
- assertTrue(user + " should be member of " + gShrimps, gShrimps.isMember(userMgr.getAuthorizable(user)));
- }
-
-
- } finally {
- superuser.refresh(false);
- for (String user : createdUsers) {
- Authorizable a = userMgr.getAuthorizable(user);
- if (a != null && !a.isGroup()) {
- a.remove();
- }
- }
- if (!userMgr.isAutoSave()) {
- superuser.save();
- }
- for (NodeIterator it = groupsNode.getNodes(); it.hasNext(); ) {
- it.nextNode().remove();
- }
- if (!userMgr.isAutoSave()) {
superuser.save();
}
}
@@ -1100,12 +851,12 @@ public class UserImportTest extends Abst
}
}
if (!userMgr.isAutoSave()) {
- jrSession.save();
+ superuser.save();
}
doImport(GROUPPATH, xml);
if (!userMgr.isAutoSave()) {
- jrSession.save();
+ superuser.save();
}
Authorizable aShrimps = userMgr.getAuthorizable("shrimps");
@@ -1119,7 +870,7 @@ public class UserImportTest extends Abst
} finally {
- jrSession.refresh(false);
+ superuser.refresh(false);
for (String user : createdUsers) {
Authorizable a = userMgr.getAuthorizable(user);
if (a != null && !a.isGroup()) {
@@ -1127,13 +878,13 @@ public class UserImportTest extends Abst
}
}
if (!userMgr.isAutoSave()) {
- jrSession.save();
+ superuser.save();
}
for (NodeIterator it = target.getNodes(); it.hasNext(); ) {
it.nextNode().remove();
}
if (!userMgr.isAutoSave()) {
- jrSession.save();
+ superuser.save();
}
}
}