use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.
the class PrivilegeManagerImplTest method testGetPrivilege.
@Test
public void testGetPrivilege() throws Exception {
Privilege p = privilegeManager.getPrivilege(PrivilegeConstants.JCR_VERSION_MANAGEMENT);
assertNotNull(p);
assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName());
}
use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.
the class PrivilegeManagerImplTest method testGetPrivilegeExpandedNameMissingMapper.
@Test(expected = AccessControlException.class)
public void testGetPrivilegeExpandedNameMissingMapper() throws Exception {
Privilege p = privilegeManager.getPrivilege(Privilege.JCR_VERSION_MANAGEMENT);
assertNotNull(p);
assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName());
}
use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.
the class PrivilegeRegistrationTest method testRegisterCustomPrivileges.
@Test
public void testRegisterCustomPrivileges() throws RepositoryException {
Workspace workspace = session.getWorkspace();
workspace.getNamespaceRegistry().registerNamespace("test", "http://www.apache.org/jackrabbit/test");
Map<String, String[]> newCustomPrivs = new HashMap<String, String[]>();
newCustomPrivs.put("new", new String[0]);
newCustomPrivs.put("test:new", new String[0]);
for (String name : newCustomPrivs.keySet()) {
boolean isAbstract = true;
String[] aggrNames = newCustomPrivs.get(name);
Privilege registered = privilegeManager.registerPrivilege(name, isAbstract, aggrNames);
// validate definition
Privilege privilege = privilegeManager.getPrivilege(name);
assertNotNull(privilege);
assertEquals(name, privilege.getName());
assertTrue(privilege.isAbstract());
assertEquals(0, privilege.getDeclaredAggregatePrivileges().length);
assertContainsDeclared(privilegeManager.getPrivilege(PrivilegeConstants.JCR_ALL), name);
}
Map<String, String[]> newAggregates = new HashMap<String, String[]>();
// a new aggregate of custom privileges
newAggregates.put("newA2", getAggregateNames("test:new", "new"));
// a new aggregate of custom and built-in privilege
newAggregates.put("newA1", getAggregateNames("new", PrivilegeConstants.JCR_READ));
// aggregating built-in privileges
newAggregates.put("aggrBuiltIn", getAggregateNames(PrivilegeConstants.JCR_MODIFY_PROPERTIES, PrivilegeConstants.JCR_READ));
for (String name : newAggregates.keySet()) {
boolean isAbstract = false;
String[] aggrNames = newAggregates.get(name);
privilegeManager.registerPrivilege(name, isAbstract, aggrNames);
Privilege p = privilegeManager.getPrivilege(name);
assertNotNull(p);
assertEquals(name, p.getName());
assertFalse(p.isAbstract());
for (String n : aggrNames) {
assertContainsDeclared(p, n);
}
assertContainsDeclared(privilegeManager.getPrivilege(PrivilegeConstants.JCR_ALL), name);
}
}
use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.
the class AbstractPrivilegeTest method assertContainsDeclared.
static void assertContainsDeclared(Privilege privilege, String aggrName) {
boolean found = false;
for (Privilege p : privilege.getDeclaredAggregatePrivileges()) {
if (aggrName.equals(p.getName())) {
found = true;
break;
}
}
assertTrue(found);
}
use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.
the class PrivilegeManagerTest method testGetPrivilegeFromName.
@Test
public void testGetPrivilegeFromName() throws AccessControlException, RepositoryException {
Privilege p = privilegeManager.getPrivilege(Privilege.JCR_VERSION_MANAGEMENT);
assertTrue(p != null);
assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName());
assertFalse(p.isAggregate());
p = privilegeManager.getPrivilege(Privilege.JCR_WRITE);
assertTrue(p != null);
assertEquals(PrivilegeConstants.JCR_WRITE, p.getName());
assertTrue(p.isAggregate());
}
Aggregations