use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class PrivilegeUpgradeTest method verifyCustomPrivileges.
@Test
public void verifyCustomPrivileges() throws Exception {
JackrabbitSession session = createAdminSession();
try {
JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
PrivilegeManager manager = workspace.getPrivilegeManager();
Privilege privilege = manager.getPrivilege("test:privilege");
assertNotNull(privilege);
assertFalse(privilege.isAbstract());
assertFalse(privilege.isAggregate());
assertEquals(0, privilege.getDeclaredAggregatePrivileges().length);
Privilege privilege2 = manager.getPrivilege("test:privilege2");
assertNotNull(privilege2);
assertTrue(privilege2.isAbstract());
assertFalse(privilege2.isAggregate());
assertEquals(0, privilege.getDeclaredAggregatePrivileges().length);
Privilege aggregate = manager.getPrivilege("test:aggregate");
assertNotNull(aggregate);
assertFalse(aggregate.isAbstract());
assertTrue(aggregate.isAggregate());
List<Privilege> agg = ImmutableList.copyOf(aggregate.getDeclaredAggregatePrivileges());
assertEquals(2, agg.size());
assertTrue(agg.contains(privilege));
assertTrue(agg.contains(manager.getPrivilege(JCR_READ)));
Privilege aggregate2 = manager.getPrivilege("test:aggregate2");
assertNotNull(aggregate2);
assertTrue(aggregate2.isAbstract());
assertTrue(aggregate2.isAggregate());
List<Privilege> agg2 = ImmutableList.copyOf(aggregate2.getDeclaredAggregatePrivileges());
assertEquals(2, agg2.size());
assertTrue(agg2.contains(aggregate));
assertTrue(agg2.contains(privilege2));
Privilege jcrAll = manager.getPrivilege("jcr:all");
List<Privilege> privileges = asList(jcrAll.getAggregatePrivileges());
assertTrue(privileges.contains(privilege));
assertTrue(privileges.contains(privilege2));
assertTrue(privileges.contains(aggregate));
assertTrue(privileges.contains(aggregate2));
} finally {
session.logout();
}
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class PrivilegeManagementTest method testRegisterPrivilegeWithPrivilege.
@Test
public void testRegisterPrivilegeWithPrivilege() throws Exception {
modify(null, PrivilegeConstants.REP_PRIVILEGE_MANAGEMENT, true);
try {
Workspace testWsp = testSession.getWorkspace();
((JackrabbitWorkspace) testWsp).getPrivilegeManager().registerPrivilege(getNewPrivilegeName(testWsp), false, new String[0]);
} finally {
modify(null, PrivilegeConstants.REP_PRIVILEGE_MANAGEMENT, false);
}
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class WriteWithCustomPrivilege method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
PrivilegeManager privilegeManager = ((JackrabbitWorkspace) superuser.getWorkspace()).getPrivilegeManager();
try {
privilegeManager.getPrivilege("replicate");
} catch (AccessControlException e) {
privilegeManager.registerPrivilege("replicate", false, null);
}
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit by apache.
the class TestContentLoader method loadTestContent.
public void loadTestContent(Session session) throws RepositoryException, IOException {
JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
Collection<String> workspaces = Arrays.asList(workspace.getAccessibleWorkspaceNames());
if (!workspaces.contains("test")) {
workspace.createWorkspace("test");
}
JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager) workspace.getNodeTypeManager();
if (!manager.hasNodeType("test:versionable")) {
InputStream xml = TestContentLoader.class.getResourceAsStream("test-nodetypes.xml");
try {
manager.registerNodeTypes(xml, JackrabbitNodeTypeManager.TEXT_XML);
} finally {
xml.close();
}
}
Node data = getOrAddNode(session.getRootNode(), "testdata");
addPropertyTestData(getOrAddNode(data, "property"));
addQueryTestData(getOrAddNode(data, "query"));
addNodeTestData(getOrAddNode(data, "node"));
addLifecycleTestData(getOrAddNode(data, "lifecycle"));
addExportTestData(getOrAddNode(data, "docViewTest"));
Node conf = getOrAddNode(session.getRootNode(), "testconf");
addRetentionTestData(getOrAddNode(conf, "retentionTest"));
session.save();
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit by apache.
the class AbstractRepositoryOperationTest method testRegisterPrivilegeWithPrivilege.
public void testRegisterPrivilegeWithPrivilege() throws Exception {
assertDefaultPrivileges(PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT_NAME);
assertPermission(Permission.PRIVILEGE_MNGMT, false);
modifyPrivileges(null, PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT_NAME.toString(), true);
assertPrivilege(PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT_NAME, true);
assertPermission(Permission.PRIVILEGE_MNGMT, true);
try {
Workspace testWsp = getTestWorkspace();
((JackrabbitWorkspace) testWsp).getPrivilegeManager().registerPrivilege(getNewPrivilegeName(testWsp), false, new String[0]);
} finally {
modifyPrivileges(null, PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT_NAME.toString(), false);
}
assertPrivilege(PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT_NAME, false);
assertPermission(Permission.PRIVILEGE_MNGMT, false);
}
Aggregations