Search in sources :

Example 1 with CompositePrincipalConfiguration

use of org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration in project jackrabbit-oak by apache.

the class SecurityProviderImplTest method testBindPrincipalConfiguration.

@Test
public void testBindPrincipalConfiguration() {
    PrincipalConfiguration defaultConfig = securityProvider.getConfiguration(PrincipalConfiguration.class);
    assertTrue(defaultConfig instanceof CompositePrincipalConfiguration);
    CompositePrincipalConfiguration cpc = (CompositePrincipalConfiguration) defaultConfig;
    PrincipalConfiguration pc = Mockito.mock(PrincipalConfiguration.class);
    when(pc.getParameters()).thenReturn(ConfigurationParameters.EMPTY);
    securityProvider.bindPrincipalConfiguration(pc);
    assertNotSame(pc, securityProvider.getConfiguration(PrincipalConfiguration.class));
    assertSame(defaultConfig, securityProvider.getConfiguration(PrincipalConfiguration.class));
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        if (sc instanceof PrincipalConfiguration) {
            assertSame(defaultConfig, sc);
        }
    }
    assertTrue(cpc.getConfigurations().contains(pc));
}
Also used : CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) Test(org.junit.Test)

Example 2 with CompositePrincipalConfiguration

use of org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration in project jackrabbit-oak by apache.

the class SecurityProviderImplTest method testUnbinPrincipalConfiguration.

@Test
public void testUnbinPrincipalConfiguration() {
    CompositePrincipalConfiguration cpc = (CompositePrincipalConfiguration) securityProvider.getConfiguration(PrincipalConfiguration.class);
    PrincipalConfiguration pc = Mockito.mock(PrincipalConfiguration.class);
    when(pc.getParameters()).thenReturn(ConfigurationParameters.EMPTY);
    securityProvider.bindPrincipalConfiguration(pc);
    assertTrue(cpc.getConfigurations().contains(pc));
    securityProvider.unbindPrincipalConfiguration(pc);
    assertFalse(cpc.getConfigurations().contains(pc));
}
Also used : CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) Test(org.junit.Test)

Example 3 with CompositePrincipalConfiguration

use of org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration 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);
}
Also used : OsgiContext(org.apache.sling.testing.mock.osgi.junit.OsgiContext) Context(org.apache.jackrabbit.oak.spi.security.Context) Field(java.lang.reflect.Field) CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) Tree(org.apache.jackrabbit.oak.api.Tree) PrincipalConfigurationImpl(org.apache.jackrabbit.oak.security.principal.PrincipalConfigurationImpl) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

CompositePrincipalConfiguration (org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration)3 PrincipalConfiguration (org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration)3 Test (org.junit.Test)3 Field (java.lang.reflect.Field)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 PrincipalConfigurationImpl (org.apache.jackrabbit.oak.security.principal.PrincipalConfigurationImpl)1 Context (org.apache.jackrabbit.oak.spi.security.Context)1 SecurityConfiguration (org.apache.jackrabbit.oak.spi.security.SecurityConfiguration)1 OsgiContext (org.apache.sling.testing.mock.osgi.junit.OsgiContext)1