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();
}
}
}
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();
}
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);
}
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);
}
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());
}
Aggregations