Search in sources :

Example 6 with JackrabbitWorkspace

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();
    }
}
Also used : PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Privilege(javax.jcr.security.Privilege) Test(org.junit.Test)

Example 7 with JackrabbitWorkspace

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);
    }
}
Also used : JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 8 with JackrabbitWorkspace

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);
    }
}
Also used : PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace)

Example 9 with JackrabbitWorkspace

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();
}
Also used : JackrabbitNodeTypeManager(org.apache.jackrabbit.api.JackrabbitNodeTypeManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(javax.jcr.Node) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace)

Example 10 with JackrabbitWorkspace

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);
}
Also used : JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Aggregations

JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)17 PrivilegeManager (org.apache.jackrabbit.api.security.authorization.PrivilegeManager)7 Workspace (javax.jcr.Workspace)5 NamespaceRegistry (javax.jcr.NamespaceRegistry)4 Node (javax.jcr.Node)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Privilege (javax.jcr.security.Privilege)3 BigDecimal (java.math.BigDecimal)2 AccessDeniedException (javax.jcr.AccessDeniedException)2 Binary (javax.jcr.Binary)2 Session (javax.jcr.Session)2 Value (javax.jcr.Value)2 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)2 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)2 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)2 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)2 Name (org.apache.jackrabbit.spi.Name)2