use of org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration 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.security.authorization.composite.CompositeAuthorizationConfiguration in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testAuthorizationRanking.
@Test
public void testAuthorizationRanking() throws Exception {
Field f = registration.getClass().getDeclaredField("authorizationConfiguration");
f.setAccessible(true);
AuthorizationConfiguration testAc = mockConfiguration(AuthorizationConfiguration.class);
registration.bindAuthorizationConfiguration(testAc, ConfigurationParameters.EMPTY);
AuthorizationConfigurationImpl ac = new AuthorizationConfigurationImpl();
ac.setParameters(ConfigurationParameters.of(CompositeConfiguration.PARAM_RANKING, 500));
registration.bindAuthorizationConfiguration(ac, PROPS);
AuthorizationConfiguration testAc2 = mockConfiguration(AuthorizationConfiguration.class);
Map<String, Object> props = ImmutableMap.<String, Object>of(Constants.SERVICE_RANKING, new Integer(100));
registration.bindAuthorizationConfiguration(testAc2, props);
CompositeAuthorizationConfiguration cac = (CompositeAuthorizationConfiguration) f.get(registration);
List<AuthorizationConfiguration> list = cac.getConfigurations();
assertEquals(3, list.size());
assertSame(ac, list.get(0));
assertSame(testAc2, list.get(1));
assertSame(testAc, list.get(2));
}
use of org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testBindRestrictionProviderWithoutAuthorizationConfig.
@Test
public void testBindRestrictionProviderWithoutAuthorizationConfig() {
registration.activate(context.bundleContext(), requiredServiceIdMap("serviceId"));
RestrictionProvider mockRp = Mockito.mock(RestrictionProvider.class);
registration.bindRestrictionProvider(mockRp, ImmutableMap.of(Constants.SERVICE_PID, "serviceId"));
SecurityProvider service = context.getService(SecurityProvider.class);
assertNotNull(service);
AuthorizationConfiguration ac = service.getConfiguration(AuthorizationConfiguration.class);
assertTrue(ac instanceof CompositeAuthorizationConfiguration);
// empty composite configuration => empty rp
RestrictionProvider rp = ac.getRestrictionProvider();
assertSame(RestrictionProvider.EMPTY, rp);
}
Aggregations