use of org.apache.jackrabbit.oak.spi.security.Context in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testAuthorizationContext.
@Test
public void testAuthorizationContext() throws Exception {
Tree t = root.getTree("/");
Field f = registration.getClass().getDeclaredField("authorizationConfiguration");
f.setAccessible(true);
AuthorizationConfiguration ac = new AuthorizationConfigurationImpl();
registration.bindAuthorizationConfiguration(ac, PROPS);
CompositeAuthorizationConfiguration cac = (CompositeAuthorizationConfiguration) f.get(registration);
Context ctx = cac.getContext();
assertContext(ctx, 1, t, false);
AuthorizationConfiguration ac1 = mockConfiguration(AuthorizationConfiguration.class);
registration.bindAuthorizationConfiguration(ac1, PROPS);
cac = (CompositeAuthorizationConfiguration) f.get(registration);
ctx = cac.getContext();
assertContext(ctx, 2, t, true);
AuthorizationConfiguration ac2 = mockConfiguration(AuthorizationConfiguration.class);
registration.bindAuthorizationConfiguration(ac2, PROPS);
cac = (CompositeAuthorizationConfiguration) f.get(registration);
ctx = cac.getContext();
assertContext(ctx, 3, t, true);
// unbind again:
registration.unbindAuthorizationConfiguration(ac1, PROPS);
cac = (CompositeAuthorizationConfiguration) f.get(registration);
ctx = cac.getContext();
assertContext(ctx, 2, t, true);
registration.unbindAuthorizationConfiguration(ac, PROPS);
cac = (CompositeAuthorizationConfiguration) f.get(registration);
ctx = cac.getContext();
assertContext(ctx, 1, t, true);
registration.unbindAuthorizationConfiguration(ac2, PROPS);
cac = (CompositeAuthorizationConfiguration) f.get(registration);
ctx = cac.getContext();
assertContext(ctx, 0, t, false);
}
use of org.apache.jackrabbit.oak.spi.security.Context in project jackrabbit-oak by apache.
the class AuthorizationContextTest method testLocation.
@Test
public void testLocation() throws Exception {
createAcl("/", PrivilegeConstants.JCR_READ);
Context ctx = AuthorizationContext.getInstance();
String policyPath = "/rep:policy";
assertTrue(ctx.definesLocation(TreeLocation.create(root, policyPath + "/allow")));
assertTrue(ctx.definesLocation(TreeLocation.create(root, policyPath + "/allow/" + AccessControlConstants.REP_PRINCIPAL_NAME)));
assertTrue(ctx.definesLocation(TreeLocation.create(root, policyPath + "/allow/" + AccessControlConstants.REP_PRIVILEGES)));
List<String> existingRegular = ImmutableList.of("/", "/jcr:system");
for (String path : existingRegular) {
assertFalse(path, ctx.definesLocation(TreeLocation.create(root, path)));
assertFalse(path, ctx.definesLocation(TreeLocation.create(root, PathUtils.concat(path, JcrConstants.JCR_PRIMARYTYPE))));
}
List<String> nonExistingItem = ImmutableList.of('/' + AccessControlConstants.REP_REPO_POLICY, "/content/" + AccessControlConstants.REP_POLICY, "/content/" + AccessControlConstants.REP_PRIVILEGES, "/content/" + AccessControlConstants.REP_REPO_POLICY, "/jcr:system/" + AccessControlConstants.REP_POLICY, PermissionConstants.PERMISSIONS_STORE_PATH + "/nonexisting");
for (String path : nonExistingItem) {
assertTrue(path, ctx.definesLocation(TreeLocation.create(root, path)));
assertTrue(path, ctx.definesLocation(TreeLocation.create(root, PathUtils.concat(path, AccessControlConstants.REP_PRIVILEGES))));
}
}
use of org.apache.jackrabbit.oak.spi.security.Context in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method assertContext.
private static void assertContext(@Nonnull Context context, int expectedSize, @Nonnull Tree tree, boolean isDefined) throws Exception {
Class<?> c = context.getClass();
assertTrue(c.getName().endsWith("CompositeContext"));
Field f = c.getDeclaredField("delegatees");
f.setAccessible(true);
if (expectedSize == 0) {
assertNull(f.get(context));
} else {
assertEquals(expectedSize, ((Context[]) f.get(context)).length);
}
assertEquals(isDefined, context.definesContextRoot(tree));
assertEquals(isDefined, context.definesTree(tree));
assertEquals(isDefined, context.definesProperty(tree, PropertyStates.createProperty("abc", "abc")));
assertEquals(isDefined, context.definesLocation(TreeLocation.create(tree)));
}
use of org.apache.jackrabbit.oak.spi.security.Context in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testPrincipalContext.
@Test
public void testPrincipalContext() throws Exception {
Tree t = root.getTree("/");
Field f = registration.getClass().getDeclaredField("principalConfiguration");
f.setAccessible(true);
PrincipalConfiguration pc = new PrincipalConfigurationImpl();
registration.bindPrincipalConfiguration(pc, PROPS);
CompositePrincipalConfiguration cpc = (CompositePrincipalConfiguration) f.get(registration);
Context ctx = cpc.getContext();
// expected size = 0 because PrincipalConfigurationImpl comes with the default ctx
assertContext(ctx, 0, t, false);
PrincipalConfiguration pc1 = mockConfiguration(PrincipalConfiguration.class);
registration.bindPrincipalConfiguration(pc1, PROPS);
cpc = (CompositePrincipalConfiguration) f.get(registration);
ctx = cpc.getContext();
// expected size 1 because the PrincipalConfigurationImpl comes with the default ctx
assertContext(ctx, 1, t, true);
PrincipalConfiguration pc2 = mockConfiguration(PrincipalConfiguration.class);
registration.bindPrincipalConfiguration(pc2, PROPS);
cpc = (CompositePrincipalConfiguration) f.get(registration);
ctx = cpc.getContext();
assertContext(ctx, 2, t, true);
// unbind again:
registration.unbindPrincipalConfiguration(pc, PROPS);
cpc = (CompositePrincipalConfiguration) f.get(registration);
ctx = cpc.getContext();
assertContext(ctx, 2, t, true);
registration.unbindPrincipalConfiguration(pc1, PROPS);
cpc = (CompositePrincipalConfiguration) f.get(registration);
ctx = cpc.getContext();
assertContext(ctx, 1, t, true);
registration.unbindPrincipalConfiguration(pc2, PROPS);
cpc = (CompositePrincipalConfiguration) f.get(registration);
ctx = cpc.getContext();
assertContext(ctx, 0, t, false);
}
use of org.apache.jackrabbit.oak.spi.security.Context in project jackrabbit-oak by apache.
the class AbstractAccessControlManagerTest method testGetTreeDefinesAcContent.
@Test(expected = AccessControlException.class)
public void testGetTreeDefinesAcContent() throws Exception {
Context ctx = new Context.Default() {
@Override
public boolean definesTree(@Nonnull Tree tree) {
return true;
}
};
when(authorizationConfiguration.getContext()).thenReturn(ctx);
acMgr.getTree(testPath, Permissions.NO_PERMISSION, true);
}
Aggregations