use of javax.jcr.security.AccessControlManager in project jackrabbit-oak by apache.
the class L3_UserVsPrincipalTest method testAccessControlEntryWithId.
@Test
public void testAccessControlEntryWithId() throws RepositoryException {
AccessControlManager acMgr = getAccessControlManager(root);
// EXERCISE fix the test case
String[] ids = new String[] { testId, testGroupId };
for (String id : ids) {
AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/");
acl.addAccessControlEntry(new PrincipalImpl(id), AccessControlUtils.privilegesFromNames(acMgr, PrivilegeConstants.JCR_READ));
}
}
use of javax.jcr.security.AccessControlManager in project jackrabbit-oak by apache.
the class ObservationQueueTest method prepareTestData.
@Override
protected void prepareTestData(Session s) throws RepositoryException {
UserManager uMgr = ((JackrabbitSession) s).getUserManager();
User user = uMgr.createUser(USER, PASSWORD);
s.save();
AccessControlManager acMgr = s.getAccessControlManager();
JackrabbitAccessControlList tmpl = AccessControlUtils.getAccessControlList(acMgr, "/");
tmpl.addEntry(user.getPrincipal(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) }, true, Collections.<String, Value>emptyMap());
acMgr.setPolicy(tmpl.getPath(), tmpl);
s.save();
}
use of javax.jcr.security.AccessControlManager in project jackrabbit-oak by apache.
the class ImportBesteffortTest method testImportUnknownPrincipal.
@Test
public void testImportUnknownPrincipal() throws Exception {
runImport();
AccessControlManager acMgr = adminSession.getAccessControlManager();
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("unknownprincipal", 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());
}
}
use of javax.jcr.security.AccessControlManager in project jackrabbit-oak by apache.
the class RandomizedReadTest method setupContent.
@Override
protected void setupContent() throws Exception {
for (JackrabbitSession session : writeSessions) {
Node root = session.getRootNode();
Node n1 = root.addNode("n1");
Node n3 = n1.addNode("n3");
n1.addNode("n4");
n1.addNode("n5");
n3.addNode("n6");
n3.addNode("n7");
n3.addNode("n8");
n3.addNode("n9");
root.addNode("n2");
Principal principal = getTestPrincipal(session);
AccessControlManager acm = session.getAccessControlManager();
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acm, "/");
acl.addEntry(principal, AccessControlUtils.privilegesFromNames(acm, PrivilegeConstants.JCR_READ), true);
acm.setPolicy("/", acl);
session.save();
}
}
use of javax.jcr.security.AccessControlManager in project jackrabbit-oak by apache.
the class AccessControlImporterTest method testImportPolicyExists.
/**
* Imports a resource-based ACL containing a single entry for a policy that
* already exists: expected outcome its that the existing ACE is replaced.
*/
public void testImportPolicyExists() throws Exception {
try {
Node target = createImportTargetWithPolicy(EveryonePrincipal.getInstance());
doImport(target.getPath(), XML_POLICY_TREE_2);
AccessControlManager acMgr = superuser.getAccessControlManager();
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(EveryonePrincipal.getInstance(), entry.getPrincipal());
List<Privilege> privs = Arrays.asList(entry.getPrivileges());
assertEquals(1, privs.size());
assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
if (entry instanceof JackrabbitAccessControlEntry) {
assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
}
} finally {
superuser.refresh(false);
}
}
Aggregations