Search in sources :

Example 16 with PrivilegeManager

use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.

the class JcrAllTest method testAllAggregation.

@Test
public void testAllAggregation() throws Exception {
    PrivilegeBits all = bitsProvider.getBits(JCR_ALL);
    PrivilegeManager pMgr = getSecurityProvider().getConfiguration(PrivilegeConfiguration.class).getPrivilegeManager(root, NamePathMapper.DEFAULT);
    Iterable<Privilege> declaredAggr = Arrays.asList(pMgr.getPrivilege(JCR_ALL).getDeclaredAggregatePrivileges());
    String[] allAggregates = Iterables.toArray(Iterables.transform(declaredAggr, new Function<Privilege, String>() {

        @Override
        public String apply(@Nullable Privilege privilege) {
            return checkNotNull(privilege).getName();
        }
    }), String.class);
    PrivilegeBits all2 = bitsProvider.getBits(allAggregates);
    assertEquals(all, all2);
    assertEquals(Collections.singleton(JCR_ALL), bitsProvider.getPrivilegeNames(all2));
    PrivilegeBits bits = PrivilegeBits.getInstance();
    for (String name : allAggregates) {
        bits.add(bitsProvider.getBits(name));
    }
    assertEquals(all, bits.unmodifiable());
}
Also used : Function(com.google.common.base.Function) PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) PrivilegeBits(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits) Privilege(javax.jcr.security.Privilege) PrivilegeConfiguration(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration) Nullable(javax.annotation.Nullable) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 17 with PrivilegeManager

use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.

the class PrivilegeConfigurationImplTest method testGetPrivilegeManager.

@Test
public void testGetPrivilegeManager() {
    PrivilegeManager pMgr = configuration.getPrivilegeManager(Mockito.mock(Root.class), NamePathMapper.DEFAULT);
    assertTrue(pMgr instanceof PrivilegeManagerImpl);
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) Test(org.junit.Test)

Example 18 with PrivilegeManager

use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.

the class PrivilegeBitsProviderTest method getAggregatedNamesWithCustom.

@Test
public void getAggregatedNamesWithCustom() throws Exception {
    PrivilegeManager pMgr = getPrivilegeManager(root);
    pMgr.registerPrivilege("test1", true, null);
    assertEquals(ImmutableSet.of("test1"), ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames("test1")));
    Set<String> expected = Sets.newHashSet(NON_AGGREGATE_PRIVILEGES);
    expected.add("test1");
    assertEquals(expected, ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames(JCR_ALL)));
    assertEquals(expected, ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames(JCR_ALL)));
}
Also used : PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 19 with PrivilegeManager

use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.

the class PrivilegeImplTest method before.

@Override
public void before() throws Exception {
    super.before();
    PrivilegeManager pMgr = getPrivilegeManager(root);
    privilege = pMgr.getPrivilege(JCR_READ_ACCESS_CONTROL);
    aggrPrivilege = pMgr.getPrivilege(REP_WRITE);
    allPrivilege = pMgr.getPrivilege(JCR_ALL);
    abstractPrivilege = pMgr.registerPrivilege("abstractPrivilege", true, null);
}
Also used : PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager)

Example 20 with PrivilegeManager

use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.

the class L3_BuiltInPrivilegesTest method testAggregation.

@Test
public void testAggregation() throws RepositoryException {
    PrivilegeManager privilegeManager = getPrivilegeManager(root);
    // EXERCISE: for all aggregated privileges define the mapping of the privilege name to declaredAggregates
    Map<String, Set<Privilege>> expectedResults = ImmutableMap.of();
    Iterable<Privilege> aggregated = Iterables.<Privilege>filter(ImmutableList.<Privilege>copyOf(privilegeManager.getRegisteredPrivileges()), new Predicate<Privilege>() {

        @Override
        public boolean apply(@Nullable Privilege input) {
            return input != null && input.isAggregate();
        }
    });
    for (Privilege aggrPrivilege : aggregated) {
        Set<Privilege> expected = expectedResults.get(aggrPrivilege.getName());
        assertEquals(expected, ImmutableSet.copyOf(aggrPrivilege.getDeclaredAggregatePrivileges()));
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) Privilege(javax.jcr.security.Privilege) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

PrivilegeManager (org.apache.jackrabbit.api.security.authorization.PrivilegeManager)22 Test (org.junit.Test)12 Privilege (javax.jcr.security.Privilege)9 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)7 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)7 ImmutableSet (com.google.common.collect.ImmutableSet)3 Set (java.util.Set)3 PrivilegeConfiguration (org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration)3 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 NamespaceRegistry (javax.jcr.NamespaceRegistry)2 Session (javax.jcr.Session)2 AccessControlException (javax.jcr.security.AccessControlException)2 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)2 Root (org.apache.jackrabbit.oak.api.Root)2 Tree (org.apache.jackrabbit.oak.api.Tree)2 LocalNameMapper (org.apache.jackrabbit.oak.namepath.LocalNameMapper)2 NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)2 NamePathMapperImpl (org.apache.jackrabbit.oak.namepath.NamePathMapperImpl)2 AuthorizationConfiguration (org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration)2 RestrictionProvider (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider)2