Search in sources :

Example 1 with AuthorizationConfigurationImpl

use of org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl 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 AuthorizationConfigurationImpl

use of org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl 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 AuthorizationConfigurationImpl

use of org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl in project jackrabbit-oak by apache.

the class SecurityProviderRegistrationTest method testActivate.

@Test
public void testActivate() {
    registration.activate(context.bundleContext(), requiredServiceIdMap("serviceA", "serviceB"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNull(service);
    RestrictionProvider mockRp = Mockito.mock(RestrictionProvider.class);
    registration.bindRestrictionProvider(mockRp, ImmutableMap.of(Constants.SERVICE_PID, "serviceA"));
    service = context.getService(SecurityProvider.class);
    assertNull(service);
    registration.bindAuthorizationConfiguration(new AuthorizationConfigurationImpl(), ImmutableMap.of(Constants.SERVICE_PID, "serviceB"));
    service = context.getService(SecurityProvider.class);
    assertNotNull(service);
}
Also used : RestrictionProvider(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider) WhiteboardRestrictionProvider(org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider) AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with AuthorizationConfigurationImpl

use of org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl in project jackrabbit-oak by apache.

the class CompositeAuthorizationConfigurationTest method testSingleGetAccessControlManager.

@Test
public void testSingleGetAccessControlManager() {
    CompositeAuthorizationConfiguration cc = getCompositeConfiguration(new AuthorizationConfigurationImpl(getSecurityProvider()));
    AccessControlManager accessControlManager = cc.getAccessControlManager(root, NamePathMapper.DEFAULT);
    assertFalse(accessControlManager instanceof CompositeAccessControlManager);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 5 with AuthorizationConfigurationImpl

use of org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl in project jackrabbit-oak by apache.

the class CompositeAuthorizationConfigurationTest method testMultipleGetPermissionProvider2.

@Test
public void testMultipleGetPermissionProvider2() {
    CompositeAuthorizationConfiguration cc = getCompositeConfiguration(new AuthorizationConfigurationImpl(getSecurityProvider()), new AuthorizationConfigurationImpl(getSecurityProvider()));
    PermissionProvider pp = cc.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), Collections.<Principal>emptySet());
    assertTrue(pp instanceof CompositePermissionProvider);
}
Also used : AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) EmptyPermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.EmptyPermissionProvider) PermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)14 AuthorizationConfigurationImpl (org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl)14 Test (org.junit.Test)14 RestrictionProvider (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider)7 CompositeAuthorizationConfiguration (org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration)4 WhiteboardRestrictionProvider (org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider)4 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)4 AuthorizationConfiguration (org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration)4 EmptyPermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.EmptyPermissionProvider)3 PermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider)3 CompositeRestrictionProvider (org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositeRestrictionProvider)3 Field (java.lang.reflect.Field)2 AccessControlManager (javax.jcr.security.AccessControlManager)2 OpenAuthorizationConfiguration (org.apache.jackrabbit.oak.spi.security.authorization.OpenAuthorizationConfiguration)2 Nonnull (javax.annotation.Nonnull)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 Context (org.apache.jackrabbit.oak.spi.security.Context)1 OsgiContext (org.apache.sling.testing.mock.osgi.junit.OsgiContext)1