Package org.apache.jackrabbit.spi

Examples of org.apache.jackrabbit.spi.PrivilegeDefinition


            Set<Name> aggrNames = newCustomPrivs.get(name);

            privilegeRegistry.registerDefinition(name, isAbstract, aggrNames);

            // validate definition
            PrivilegeDefinition definition = privilegeRegistry.get(name);
            assertNotNull(definition);
            assertEquals(name, definition.getName());
            assertTrue(definition.isAbstract());
            assertTrue(definition.getDeclaredAggregateNames().isEmpty());
            assertEquals(aggrNames.size(), definition.getDeclaredAggregateNames().size());
            for (Name n : aggrNames) {
                assertTrue(definition.getDeclaredAggregateNames().contains(n));
            }

            Set<Name> allAgg = privilegeRegistry.get(NameConstants.JCR_ALL).getDeclaredAggregateNames();
            assertTrue(allAgg.contains(name));

            // re-read the filesystem resource and check if definition is correct
            PrivilegeRegistry registry = new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
            PrivilegeDefinition def = registry.get(name);
            assertEquals(isAbstract, def.isAbstract());
            assertEquals(aggrNames.size(), def.getDeclaredAggregateNames().size());
            for (Name n : aggrNames) {
                assertTrue(def.getDeclaredAggregateNames().contains(n));
            }

            assertPrivilege(privilegeRegistry, (SessionImpl) superuser, definition);
        }

        Map<Name, Set<Name>> newAggregates = new HashMap<Name, Set<Name>>();
        // a new aggregate of custom privileges
        newAggregates.put(resolver.getQName("newA2"), createNameSet(resolver.getQName("test:new"), resolver.getQName("new")));
        // a new aggregate of custom and built-in privilege
        newAggregates.put(resolver.getQName("newA1"), createNameSet(resolver.getQName("new"), NameConstants.JCR_READ));
        // aggregating built-in privileges
        newAggregates.put(resolver.getQName("aggrBuiltIn"), createNameSet(NameConstants.JCR_MODIFY_PROPERTIES, NameConstants.JCR_READ));

        for (Name name : newAggregates.keySet()) {
            boolean isAbstract = false;
            Set<Name> aggrNames = newAggregates.get(name);
            privilegeRegistry.registerDefinition(name, isAbstract, aggrNames);
            PrivilegeDefinition definition = privilegeRegistry.get(name);

            assertNotNull(definition);
            assertEquals(name, definition.getName());
            assertFalse(definition.isAbstract());
            assertFalse(definition.getDeclaredAggregateNames().isEmpty());
            assertEquals(aggrNames.size(), definition.getDeclaredAggregateNames().size());
            for (Name n : aggrNames) {
                assertTrue(definition.getDeclaredAggregateNames().contains(n));
            }

            Set<Name> allAgg = privilegeRegistry.get(NameConstants.JCR_ALL).getDeclaredAggregateNames();
            assertTrue(allAgg.contains(name));

            // re-read the filesystem resource and check if definition is correct
            PrivilegeRegistry registry = new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
            PrivilegeDefinition def = registry.get(name);
            assertEquals(isAbstract, def.isAbstract());
            assertEquals(isAbstract, def.isAbstract());
            assertEquals(aggrNames.size(), def.getDeclaredAggregateNames().size());
            for (Name n : aggrNames) {
                assertTrue(def.getDeclaredAggregateNames().contains(n));
            }

            assertPrivilege(registry, (SessionImpl) superuser, def);
        }
    }
View Full Code Here


     * @param declaredAggregateName
     * @param toRegister
     * @return
     */
    private boolean isCircularAggregation(PrivilegeDefinition def, Name declaredAggregateName, Map<Name, PrivilegeDefinition> toRegister) {
        PrivilegeDefinition d = toRegister.get(declaredAggregateName);
        if (d.getDeclaredAggregateNames().isEmpty()) {
            return false;
        } else {
            boolean isCircular = false;
            for (Name n : d.getDeclaredAggregateNames()) {
                if (def.getName().equals(n)) {
                    return true;
                }
                if (toRegister.containsKey(n)) {
                    isCircular = isCircularAggregation(def, n, toRegister);
View Full Code Here

            updateNamespaceMapping(root, namespaces);

            NodeList nl = root.getElementsByTagName(XML_PRIVILEGE);
            for (int i = 0; i < nl.getLength(); i++) {
                Node n = nl.item(i);
                PrivilegeDefinition def = parseDefinition(n, namespaces);
                if (def != null) {
                    defs.add(def);
                }
            }
            return defs.toArray(new PrivilegeDefinition[defs.size()]);
View Full Code Here

        Privilege privilege;
        synchronized (cache) {
            if (cache.containsKey(name)) {
                privilege = cache.get(name);
            } else {
                PrivilegeDefinition def = registry.get(name);
                if (def != null) {
                    privilege = new PrivilegeImpl(def);
                    cache.put(name, privilege);
                } else {
                    throw new AccessControlException("Unknown privilege " + resolver.getJCRName(name));
View Full Code Here

     * @param declaredAggregateNames
     * @throws RepositoryException If the privilege could not be registered due
     * to constraint violations or if persisting the custom privilege fails.
     */
    void registerDefinition(Name privilegeName, boolean isAbstract, Set<Name> declaredAggregateNames) throws RepositoryException {
        PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, isAbstract, declaredAggregateNames);
        Map<Name, PrivilegeDefinition> stubs = Collections.singletonMap(privilegeName, def);
        registerCustomDefinitions(stubs);

        // inform clustering about the new privilege.
        if (eventChannel != null) {
View Full Code Here

            // monitor progress of resolution into proper definitions.
            int cnt = aggregates.size();

            // look for those definitions whose declared aggregates have all been processed.
            for (Iterator<PrivilegeDefinition> itr = aggregates.iterator(); itr.hasNext();) {
                PrivilegeDefinition stub = itr.next();
                PrivilegeBits bts = getAggregateBits(stub.getDeclaredAggregateNames(), definitions);
                if (!bts.isEmpty()) {
                    // make sure the same aggregation is not yet covered by an
                    // already registered privilege
                    if (bitsToNames.containsKey(bts) && bitsToNames.get(bts).size() == 1) {
                        Name existingName = bitsToNames.get(bts).iterator().next();
                        throw new RepositoryException("Custom aggregate privilege '" + stub.getName() + "' is already covered by '" + existingName.toString() + "'");
                    }
                    // ... nor is present within the set of definitions that have
                    // been created before for registration.
                    for (Definition d : definitions.values()) {
                        if (bts.equals(d.bits)) {
                            throw new RepositoryException("Custom aggregate privilege '" + stub.getName() + "' is already defined by '"+ d.getName()+"'");
                        }
                    }

                    // now its save to create the new definition
                    Definition def = new Definition(stub, bts);
View Full Code Here

     * @param declaredAggregateName
     * @param toRegister
     * @return
     */
    private boolean isCircularAggregation(PrivilegeDefinition def, Name declaredAggregateName, Map<Name, PrivilegeDefinition> toRegister) {
        PrivilegeDefinition d = toRegister.get(declaredAggregateName);
        if (d.getDeclaredAggregateNames().isEmpty()) {
            return false;
        } else {
            boolean isCircular = false;
            for (Name n : d.getDeclaredAggregateNames()) {
                if (def.getName().equals(n)) {
                    return true;
                }
                if (toRegister.containsKey(n)) {
                    isCircular = isCircularAggregation(def, n, toRegister);
View Full Code Here

        PrivilegeBits previous = privilegeRegistry.getBits(privilegeRegistry.get(PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT_NAME)).unmodifiable();
        for (int i = 0; i < 100; i++) {
            boolean isAbstract = true;
            Name name = ((SessionImpl) superuser).getQName("test"+i);
            privilegeRegistry.registerDefinition(name, isAbstract, Collections.<Name>emptySet());
            PrivilegeDefinition definition = privilegeRegistry.get(name);

            assertNotNull(definition);
            assertEquals(name, definition.getName());

            PrivilegeBits modifiable = privilegeRegistry.getBits(definition);
            PrivilegeBits bits = modifiable.unmodifiable();
            assertNotNull(bits);
            assertFalse(bits.isEmpty());
            assertEquals(modifiable, bits);

            assertFalse(previous.equals(bits));
            assertEquals(previous.nextBits(), bits);

            PrivilegeDefinition all = privilegeRegistry.get(NameConstants.JCR_ALL);
            assertTrue(all.getDeclaredAggregateNames().contains(name));
            assertTrue(privilegeRegistry.getBits(all).includes(bits));

            previous = bits;
        }
    }
View Full Code Here

        Privilege privilege;
        synchronized (cache) {
            if (cache.containsKey(name)) {
                privilege = cache.get(name);
            } else {
                PrivilegeDefinition def = registry.get(name);
                if (def != null) {
                    privilege = new PrivilegeImpl(def);
                    cache.put(name, privilege);
                } else {
                    throw new AccessControlException("Unknown privilege " + resolver.getJCRName(name));
View Full Code Here

     * @param declaredAggregateNames
     * @throws RepositoryException If the privilege could not be registered due
     * to constraint violations or if persisting the custom privilege fails.
     */
    void registerDefinition(Name privilegeName, boolean isAbstract, Set<Name> declaredAggregateNames) throws RepositoryException {
        PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, isAbstract, declaredAggregateNames);
        Map<Name, PrivilegeDefinition> stubs = Collections.singletonMap(privilegeName, def);
        registerCustomDefinitions(stubs);

        // inform clustering about the new privilege.
        if (eventChannel != null) {
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.spi.PrivilegeDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.