Search in sources :

Example 1 with CompositeAuthorizationConfiguration

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);
}
Also used : OsgiContext(org.apache.sling.testing.mock.osgi.junit.OsgiContext) Context(org.apache.jackrabbit.oak.spi.security.Context) Field(java.lang.reflect.Field) CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) Tree(org.apache.jackrabbit.oak.api.Tree) CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with CompositeAuthorizationConfiguration

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));
}
Also used : Field(java.lang.reflect.Field) CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with CompositeAuthorizationConfiguration

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);
}
Also used : CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) RestrictionProvider(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider) WhiteboardRestrictionProvider(org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)3 CompositeAuthorizationConfiguration (org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration)3 AuthorizationConfiguration (org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration)3 Test (org.junit.Test)3 Field (java.lang.reflect.Field)2 AuthorizationConfigurationImpl (org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl)2 Tree (org.apache.jackrabbit.oak.api.Tree)1 WhiteboardRestrictionProvider (org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider)1 Context (org.apache.jackrabbit.oak.spi.security.Context)1 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)1 RestrictionProvider (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider)1 OsgiContext (org.apache.sling.testing.mock.osgi.junit.OsgiContext)1