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));
}
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));
}
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);
}
Aggregations