Search in sources :

Example 6 with PrincipalProvider

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

the class UserPrincipalProviderWithCacheTest method testChangeCache.

@Test
public void testChangeCache() throws Exception {
    PrincipalProvider pp = createPrincipalProvider(systemRoot);
    pp.getPrincipals(userId);
    root.refresh();
    List<PropertyState> props = new ArrayList();
    props.add(PropertyStates.createProperty(CacheConstants.REP_EXPIRATION, 25));
    props.add(PropertyStates.createProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, EveryonePrincipal.NAME));
    props.add(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED));
    props.add(PropertyStates.createProperty("residualProp", "anyvalue"));
    // changing cache with (normally) sufficiently privileged session must not succeed
    for (PropertyState ps : props) {
        try {
            Tree cache = getCacheTree(root);
            cache.setProperty(ps);
            root.commit();
            fail("Attempt to modify the cache tree must fail.");
        } catch (CommitFailedException e) {
        // success
        } finally {
            root.refresh();
        }
    }
    // changing cache with system session must not succeed either
    for (PropertyState ps : props) {
        try {
            Tree cache = getCacheTree(systemRoot);
            cache.setProperty(ps);
            systemRoot.commit();
            fail("Attempt to modify the cache tree must fail.");
        } catch (CommitFailedException e) {
        // success
        } finally {
            systemRoot.refresh();
        }
    }
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractPrincipalProviderTest(org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest) Test(org.junit.Test)

Example 7 with PrincipalProvider

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

the class UserPrincipalProviderWithCacheTest method testRemoveCache.

@Test
public void testRemoveCache() throws Exception {
    PrincipalProvider pp = createPrincipalProvider(systemRoot);
    pp.getPrincipals(userId);
    // removing cache with sufficiently privileged session must succeed
    root.refresh();
    Tree cache = getCacheTree(root);
    cache.remove();
    root.commit();
}
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)

Example 8 with PrincipalProvider

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

the class UserPrincipalProviderWithCacheTest method testGetPrincipalsPopulatesCache.

@Test
public void testGetPrincipalsPopulatesCache() throws Exception {
    PrincipalProvider pp = createPrincipalProvider(systemRoot);
    Set<? extends Principal> principals = pp.getPrincipals(userId);
    assertPrincipals(principals, EveryonePrincipal.getInstance(), testGroup.getPrincipal(), getTestUser().getPrincipal());
    root.refresh();
    Tree principalCache = getCacheTree(root);
    assertTrue(principalCache.exists());
    assertEquals(CacheConstants.NT_REP_CACHE, TreeUtil.getPrimaryTypeName(principalCache));
    assertNotNull(principalCache.getProperty(CacheConstants.REP_EXPIRATION));
    PropertyState ps = principalCache.getProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES);
    assertNotNull(ps);
    String val = ps.getValue(Type.STRING);
    assertEquals(testGroup.getPrincipal().getName(), val);
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) 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 9 with PrincipalProvider

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

the class UserPrincipalProviderWithCacheTest method testExtractPrincipalsFromCache.

@Test
public void testExtractPrincipalsFromCache() throws Exception {
    // a) force the cache to be created
    PrincipalProvider pp = createPrincipalProvider(systemRoot);
    // set of principals that read from user + membership-provider.
    Set<? extends Principal> principals = pp.getPrincipals(userId);
    assertPrincipals(principals, EveryonePrincipal.getInstance(), testGroup.getPrincipal(), getTestUser().getPrincipal());
    // b) retrieve principals again (this time from the cache)
    Set<? extends Principal> principalsAgain = pp.getPrincipals(userId);
    // make sure both sets are equal
    assertEquals(principals, principalsAgain);
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) AbstractPrincipalProviderTest(org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest) Test(org.junit.Test)

Example 10 with PrincipalProvider

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

the class UserPrincipalProviderWithCacheTest method testOnlySystemReadsFromCache.

@Test
public void testOnlySystemReadsFromCache() throws Exception {
    String userId = getTestUser().getID();
    PrincipalProvider systemPP = createPrincipalProvider(systemRoot);
    Set<? extends Principal> principals = systemPP.getPrincipals(userId);
    assertPrincipals(principals, EveryonePrincipal.getInstance(), testGroup.getPrincipal(), getTestUser().getPrincipal());
    root.refresh();
    assertPrincipals(principalProvider.getPrincipals(userId), EveryonePrincipal.getInstance(), testGroup.getPrincipal(), getTestUser().getPrincipal());
    testGroup.removeMember(getTestUser());
    root.commit();
    assertPrincipals(principalProvider.getPrincipals(userId), EveryonePrincipal.getInstance(), getTestUser().getPrincipal());
    assertPrincipals(systemPP.getPrincipals(userId), EveryonePrincipal.getInstance(), testGroup.getPrincipal(), getTestUser().getPrincipal());
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) 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