Search in sources :

Example 6 with PrivilegeDefinitionImpl

use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl in project jackrabbit by apache.

the class CustomPrivilegeTest method testCustomDefinitionsWithCyclicReferences.

public void testCustomDefinitionsWithCyclicReferences() throws RepositoryException, FileSystemException, IOException {
    // setup the custom privilege file with cyclic references
    FileSystem fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem();
    FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml");
    if (!resource.exists()) {
        resource.makeParentDirs();
    }
    NameFactory nf = NameFactoryImpl.getInstance();
    Name test = nf.create(Name.NS_DEFAULT_URI, "test");
    Name test2 = nf.create(Name.NS_DEFAULT_URI, "test2");
    Name test3 = nf.create(Name.NS_DEFAULT_URI, "test3");
    Name test4 = nf.create(Name.NS_DEFAULT_URI, "test4");
    Name test5 = nf.create(Name.NS_DEFAULT_URI, "test5");
    OutputStream out = resource.getOutputStream();
    try {
        List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
        defs.add(new PrivilegeDefinitionImpl(test, false, Collections.singleton(test2)));
        defs.add(new PrivilegeDefinitionImpl(test4, true, Collections.singleton(test5)));
        defs.add(new PrivilegeDefinitionImpl(test5, false, Collections.singleton(test3)));
        defs.add(new PrivilegeDefinitionImpl(test3, false, Collections.singleton(test)));
        defs.add(new PrivilegeDefinitionImpl(test2, false, Collections.singleton(test4)));
        PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
        pdw.writeDefinitions(out, defs.toArray(new PrivilegeDefinition[defs.size()]), Collections.<String, String>emptyMap());
        new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
        fail("Cyclic definitions must be detected upon registry startup.");
    } catch (RepositoryException e) {
    // success
    } finally {
        out.close();
        fs.deleteFolder("/privileges");
    }
}
Also used : PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) PrivilegeDefinitionWriter(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter) NameFactory(org.apache.jackrabbit.spi.NameFactory) Name(org.apache.jackrabbit.spi.Name)

Example 7 with PrivilegeDefinitionImpl

use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl 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

PrivilegeDefinition (org.apache.jackrabbit.spi.PrivilegeDefinition)7 PrivilegeDefinitionImpl (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl)7 Name (org.apache.jackrabbit.spi.Name)6 ArrayList (java.util.ArrayList)3 RepositoryException (javax.jcr.RepositoryException)3 OutputStream (java.io.OutputStream)2 Privilege (javax.jcr.security.Privilege)2 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)2 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)2 NameFactory (org.apache.jackrabbit.spi.NameFactory)2 DefaultNamePathResolver (org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)2 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)2 PrivilegeDefinitionWriter (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Session (javax.jcr.Session)1 Workspace (javax.jcr.Workspace)1 HttpResponse (org.apache.http.HttpResponse)1