use of org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry in project sling by apache.
the class AclUtil method contains.
// visible for testing
static boolean contains(AccessControlEntry[] existingAces, LocalAccessControlEntry newAce) throws RepositoryException {
for (int i = 0; i < existingAces.length; i++) {
JackrabbitAccessControlEntry existingEntry = (JackrabbitAccessControlEntry) existingAces[i];
LOG.debug("Comparing {} with {}", newAce, toString(existingEntry));
if (newAce.isContainedIn(existingEntry)) {
return true;
}
}
return false;
}
use of org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry in project jackrabbit by apache.
the class EntryTest method testGetGlob.
public void testGetGlob() throws RepositoryException, NotExecutableException {
Privilege[] privs = privilegesFromName(Privilege.JCR_ALL);
JackrabbitAccessControlEntry pe = createEntry(testPrincipal, privs, true);
assertEquals(restrictions.get(glob), pe.getRestriction(glob));
assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
Map<String, Value> restr = new HashMap<String, Value>();
restr.put(nodePath, restrictions.get(nodePath));
pe = createEntry(testPrincipal, privs, true, restr);
assertNull(pe.getRestriction(glob));
restr = new HashMap<String, Value>();
restr.put(nodePath, restrictions.get(nodePath));
restr.put(glob, new StringValue(""));
pe = createEntry(testPrincipal, privs, true, restr);
assertEquals("", pe.getRestriction(glob).getString());
restr = new HashMap<String, Value>();
restr.put(nodePath, restrictions.get(nodePath));
restr.put(glob, new BooleanValue(true));
assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
}
use of org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry in project jackrabbit by apache.
the class EntryTest method testGetNodePath.
public void testGetNodePath() throws RepositoryException, NotExecutableException {
Privilege[] privs = privilegesFromName(Privilege.JCR_ALL);
JackrabbitAccessControlEntry pe = createEntry(testPrincipal, privs, true);
assertEquals(restrictions.get(nodePath), pe.getRestriction(nodePath));
assertEquals(PropertyType.PATH, pe.getRestriction(nodePath).getType());
}
use of org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry in project jackrabbit by apache.
the class EntryTest method testTypeConversion.
public void testTypeConversion() throws RepositoryException, NotExecutableException {
// ACLTemplate impl tries to convert the property types if the don't
// match the required ones.
Privilege[] privs = privilegesFromName(Privilege.JCR_ALL);
Map<String, Value> restr = new HashMap<String, Value>();
restr.put(nodePath, new StringValue("/a/b/c/d"));
JackrabbitAccessControlEntry pe = createEntry(testPrincipal, privs, true, restr);
assertEquals("/a/b/c/d", pe.getRestriction(nodePath).getString());
assertEquals(PropertyType.PATH, pe.getRestriction(nodePath).getType());
restr = new HashMap<String, Value>();
restr.put(nodePath, restrictions.get(nodePath));
restr.put(glob, new BooleanValue(true));
pe = createEntry(testPrincipal, privs, true, restr);
assertEquals(true, pe.getRestriction(glob).getBoolean());
assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
}
use of org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry in project jackrabbit by apache.
the class AccessControlImporterTest method testImportACLRemoveACE.
/**
* Imports a resource-based ACL containing a single entry.
*
* @throws Exception
*/
public void testImportACLRemoveACE() throws Exception {
try {
NodeImpl target = (NodeImpl) testRootNode.addNode(nodeName1);
target.addMixin("rep:AccessControllable");
InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_3.getBytes("UTF-8"));
SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new PseudoConfig());
ImportHandler ih = new ImportHandler(importer, sImpl);
new ParsingContentHandler(ih).parse(in);
in = new ByteArrayInputStream(XML_POLICY_TREE_5.getBytes("UTF-8"));
importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new PseudoConfig());
ih = new ImportHandler(importer, sImpl);
new ParsingContentHandler(ih).parse(in);
String path = target.getPath();
AccessControlManager acMgr = sImpl.getAccessControlManager();
AccessControlPolicy[] policies = acMgr.getPolicies(path);
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof JackrabbitAccessControlList);
AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
assertEquals(1, entries.length);
AccessControlEntry entry = entries[0];
assertEquals("admin", entry.getPrincipal().getName());
assertEquals(1, entry.getPrivileges().length);
assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
if (entry instanceof JackrabbitAccessControlEntry) {
assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
}
} finally {
superuser.refresh(false);
}
}
Aggregations