use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserImporterTest method testImportGroup.
public void testImportGroup() throws RepositoryException, IOException, SAXException, NotExecutableException {
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:node>";
NodeImpl target = (NodeImpl) sImpl.getNode(umgr.getGroupsPath());
try {
doImport(target, xml);
assertTrue(target.isModified());
assertTrue(sImpl.hasPendingChanges());
Authorizable newGroup = umgr.getAuthorizable("g");
assertNotNull(newGroup);
assertTrue(newGroup.isGroup());
assertEquals("g", newGroup.getPrincipal().getName());
assertEquals("g", newGroup.getID());
NodeImpl n = ((GroupImpl) newGroup).getNode();
assertTrue(n.isNew());
assertTrue(n.getParent().isSame(target));
assertEquals("g", n.getName());
assertEquals("g", n.getProperty(UserConstants.P_PRINCIPAL_NAME).getString());
// saving changes of the import -> must succeed. add mandatory
// props should have been created.
sImpl.save();
} finally {
sImpl.refresh(false);
if (target.hasNode("g")) {
target.getNode("g").remove();
sImpl.save();
}
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class AccessControlImporterTest method testImportPolicyExists.
/**
* Imports a resource-based ACL containing a single entry for a policy that
* already exists.
*
* @throws Exception
*/
public void testImportPolicyExists() throws Exception {
// all ACEs for an import. maybe control this behavior via uuid-flag.
if (true) {
return;
}
NodeImpl target = (NodeImpl) testRootNode;
target = (NodeImpl) target.addNode("test", "test:sameNameSibsFalseChildNodeDefinition");
AccessControlManager acMgr = sImpl.getAccessControlManager();
for (AccessControlPolicyIterator it = acMgr.getApplicablePolicies(target.getPath()); it.hasNext(); ) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
if (policy instanceof AccessControlList) {
Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_LOCK_MANAGEMENT) };
((AccessControlList) policy).addAccessControlEntry(sImpl.getPrincipalManager().getEveryone(), privs);
acMgr.setPolicy(target.getPath(), policy);
}
}
try {
InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_2.getBytes("UTF-8"));
SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, new PseudoConfig());
ImportHandler ih = new ImportHandler(importer, sImpl);
new ParsingContentHandler(ih).parse(in);
AccessControlPolicy[] policies = acMgr.getPolicies(target.getPath());
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof JackrabbitAccessControlList);
AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
assertEquals(1, entries.length);
AccessControlEntry entry = entries[0];
assertEquals("everyone", entry.getPrincipal().getName());
List<Privilege> privs = Arrays.asList(entry.getPrivileges());
assertEquals(2, privs.size());
assertTrue(privs.contains(acMgr.privilegeFromName(Privilege.JCR_WRITE)) && privs.contains(acMgr.privilegeFromName(Privilege.JCR_LOCK_MANAGEMENT)));
assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
if (entry instanceof JackrabbitAccessControlEntry) {
assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
}
} finally {
superuser.refresh(false);
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class AccessControlImporterTest method testImportACLUnknownFail.
/**
* Imports a resource-based ACL containing a single entry.
*
* @throws Exception
*/
public void testImportACLUnknownFail() throws Exception {
try {
NodeImpl target = (NodeImpl) testRootNode.addNode(nodeName1);
target.addMixin("rep:AccessControllable");
InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_4.getBytes("UTF-8"));
PseudoConfig config = new PseudoConfig();
((AccessControlImporter) config.getProtectedItemImporters().get(0)).setImportBehavior("default");
SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, config);
ImportHandler ih = new ImportHandler(importer, sImpl);
try {
new ParsingContentHandler(ih).parse(in);
fail("importing unknown principal should fail based on configuration.");
} catch (Exception e) {
// ok
}
} finally {
superuser.refresh(false);
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class NodeIteratorImpl method nextNode.
/**
* Returns the next <code>Node</code> in the result set.
* @return the next <code>Node</code> in the result set.
* @throws NoSuchElementException if iteration has no more
* <code>Node</code>s.
*/
public Node nextNode() throws NoSuchElementException {
initialize();
if (next == null) {
throw new NoSuchElementException();
}
NodeImpl n = next;
fetchNext();
return n;
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class EntryTest method testRestrictions.
public void testRestrictions() throws RepositoryException, NotExecutableException {
// test if restrictions with expanded name are properly resolved
Map<String, Value> restrictions = new HashMap<String, Value>();
restrictions.put(ACLTemplate.P_GLOB.toString(), superuser.getValueFactory().createValue("*/test"));
acl = getPolicy(acMgr, testPath, testUser.getPrincipal());
acl.addEntry(testUser.getPrincipal(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) }, true, restrictions);
acMgr.setPolicy(testPath, acl);
superuser.save();
Map<String, Boolean> toMatch = new HashMap<String, Boolean>();
toMatch.put(acl.getPath(), false);
toMatch.put(acl.getPath() + "test", false);
toMatch.put(acl.getPath() + "/test", true);
toMatch.put(acl.getPath() + "/something/test", true);
toMatch.put(acl.getPath() + "de/test", true);
NodeImpl aclNode = (NodeImpl) superuser.getNode(acl.getPath() + "/rep:policy");
List<Entry> entries = Entry.readEntries(aclNode, testRootNode.getPath());
assertTrue(!entries.isEmpty());
assertEquals(1, entries.size());
Entry entry = entries.iterator().next();
for (String str : toMatch.keySet()) {
assertEquals("Path to match : " + str, toMatch.get(str).booleanValue(), entry.matches(str));
}
}
Aggregations