Search in sources :

Example 16 with JackrabbitWorkspace

use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.

the class PrivilegeManagementTest method testRegisterPrivilege.

@Test
public void testRegisterPrivilege() throws Exception {
    try {
        Workspace testWsp = testSession.getWorkspace();
        ((JackrabbitWorkspace) testWsp).getPrivilegeManager().registerPrivilege(getNewPrivilegeName(testWsp), false, new String[0]);
        fail("Privilege registration should be denied.");
    } catch (AccessDeniedException e) {
    // success
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 17 with JackrabbitWorkspace

use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit by apache.

the class RepositoryServiceImpl method getPrivilegeDefinitions.

@Override
public PrivilegeDefinition[] getPrivilegeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Session session = sInfo.getSession();
    Workspace wsp = session.getWorkspace();
    Collection<Privilege> privs;
    if (wsp instanceof JackrabbitWorkspace) {
        privs = Arrays.asList(((JackrabbitWorkspace) wsp).getPrivilegeManager().getRegisteredPrivileges());
    } else {
        Privilege jcrAll = session.getAccessControlManager().privilegeFromName(Privilege.JCR_ALL);
        privs = new HashSet<Privilege>();
        privs.add(jcrAll);
        for (Privilege p : jcrAll.getAggregatePrivileges()) {
            privs.add(p);
        }
    }
    PrivilegeDefinition[] pDefs = new PrivilegeDefinition[privs.size()];
    NamePathResolver npResolver = sInfo.getNamePathResolver();
    int i = 0;
    for (Privilege p : privs) {
        Set<Name> aggrnames = null;
        if (p.isAggregate()) {
            aggrnames = new HashSet<Name>();
            for (Privilege dap : p.getDeclaredAggregatePrivileges()) {
                aggrnames.add(npResolver.getQName(dap.getName()));
            }
        }
        PrivilegeDefinition def = new PrivilegeDefinitionImpl(npResolver.getQName(p.getName()), p.isAbstract(), aggrnames);
        pDefs[i++] = def;
    }
    return pDefs;
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Name(org.apache.jackrabbit.spi.Name) PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) 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