Search in sources :

Example 16 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class PrincipalConfigurationImplTest method testGetPrincipalProvider2.

@Test
public void testGetPrincipalProvider2() {
    pc1.setSecurityProvider(getSecurityProvider());
    PrincipalProvider pp = pc1.getPrincipalProvider(root, NamePathMapper.DEFAULT);
    assertNotNull(pp);
    assertEquals(getUserConfiguration().getUserPrincipalProvider(root, NamePathMapper.DEFAULT).getClass(), pp.getClass());
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 17 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class PrincipalConfigurationImplTest method testGetPrincipalProvider3.

@Test
public void testGetPrincipalProvider3() {
    PrincipalProvider pp = pc2.getPrincipalProvider(root, NamePathMapper.DEFAULT);
    assertNotNull(pp);
    assertEquals(getUserConfiguration().getUserPrincipalProvider(root, NamePathMapper.DEFAULT).getClass(), pp.getClass());
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 18 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class PrincipalConfigurationImplTest method testGetPrincipalProvider4.

@Test
public void testGetPrincipalProvider4() {
    PrincipalConfigurationImpl pc3 = new PrincipalConfigurationImpl();
    final SecurityProvider sp = new SecurityProvider() {

        @Nonnull
        @Override
        public ConfigurationParameters getParameters(@Nullable String name) {
            return ConfigurationParameters.EMPTY;
        }

        @Nonnull
        @Override
        public Iterable<? extends SecurityConfiguration> getConfigurations() {
            return ImmutableList.of();
        }

        @Nonnull
        @Override
        public <T> T getConfiguration(@Nonnull Class<T> configClass) {
            if (configClass.equals(UserConfiguration.class)) {
                return (T) new UserConfigurationImpl(this) {

                    @Nullable
                    @Override
                    public PrincipalProvider getUserPrincipalProvider(@Nonnull Root root, @Nonnull NamePathMapper namePathMapper) {
                        return null;
                    }
                };
            } else {
                throw new IllegalArgumentException();
            }
        }
    };
    pc3.setSecurityProvider(sp);
    PrincipalProvider pp = pc3.getPrincipalProvider(root, NamePathMapper.DEFAULT);
    assertTrue(pp instanceof PrincipalProviderImpl);
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) UserConfigurationImpl(org.apache.jackrabbit.oak.security.user.UserConfigurationImpl) Nullable(javax.annotation.Nullable) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 19 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class UserPrincipalProviderWithCacheTest method testLongOverflow.

@Test
public void testLongOverflow() throws Exception {
    long[] maxCache = new long[] { Long.MAX_VALUE, Long.MAX_VALUE - 1, Long.MAX_VALUE - 10000 };
    Root systemRoot = getSystemSession().getLatestRoot();
    for (long exp : maxCache) {
        changeUserConfiguration(ConfigurationParameters.of(UserPrincipalProvider.PARAM_CACHE_EXPIRATION, exp));
        PrincipalProvider pp = createPrincipalProvider(systemRoot);
        pp.getPrincipals(userId);
        Tree userTree = systemRoot.getTree(getTestUser().getPath());
        Tree cache = userTree.getChild(CacheConstants.REP_CACHE);
        assertTrue(cache.exists());
        PropertyState propertyState = cache.getProperty(CacheConstants.REP_EXPIRATION);
        assertNotNull(propertyState);
        assertEquals(Long.MAX_VALUE, propertyState.getValue(Type.LONG).longValue());
        cache.remove();
        systemRoot.commit();
    }
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractPrincipalProviderTest(org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest) Test(org.junit.Test)

Example 20 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class UserPrincipalProviderWithCacheTest method testGetGroupMembershipForGroups.

@Test
public void testGetGroupMembershipForGroups() throws Exception {
    PrincipalProvider pp = createPrincipalProvider(systemRoot);
    Set<? extends Principal> principals = pp.getGroupMembership(testGroup.getPrincipal());
    assertPrincipals(principals, EveryonePrincipal.getInstance());
    principals = pp.getGroupMembership(testGroup2.getPrincipal());
    assertPrincipals(principals, EveryonePrincipal.getInstance(), testGroup.getPrincipal());
    root.refresh();
    Tree principalCache = getCacheTree(root, testGroup.getPath());
    assertFalse(principalCache.exists());
    principalCache = getCacheTree(root, testGroup2.getPath());
    assertFalse(principalCache.exists());
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) Tree(org.apache.jackrabbit.oak.api.Tree) AbstractPrincipalProviderTest(org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest) Test(org.junit.Test)

Aggregations

PrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider)30 Test (org.junit.Test)26 AbstractPrincipalProviderTest (org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest)16 Tree (org.apache.jackrabbit.oak.api.Tree)10 Principal (java.security.Principal)6 Group (org.apache.jackrabbit.api.security.user.Group)5 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 Nonnull (javax.annotation.Nonnull)3 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)3 Root (org.apache.jackrabbit.oak.api.Root)3 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)3 TestPrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.TestPrincipalProvider)3 HashSet (java.util.HashSet)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)2 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)2 PrincipalConfiguration (org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CheckForNull (javax.annotation.CheckForNull)1