use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testDeactivate.
@Test
public void testDeactivate() throws Exception {
registration.activate(context.bundleContext(), requiredServiceIdMap("nodeName"));
AuthorizableNodeName mock = Mockito.mock(AuthorizableNodeName.class);
registration.bindAuthorizableNodeName(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
SecurityProvider service = context.getService(SecurityProvider.class);
assertNotNull(service);
registration.deactivate();
// provider must have been unregistered
assertNull(context.getService(SecurityProvider.class));
}
use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testDeactivateClearsPreconditions.
@Test
public void testDeactivateClearsPreconditions() throws Exception {
Field f = registration.getClass().getDeclaredField("preconditions");
f.setAccessible(true);
registration.activate(context.bundleContext(), requiredServiceIdMap("nodeName"));
assertFalse(((Preconditions) f.get(registration)).areSatisfied());
AuthorizableNodeName mock = Mockito.mock(AuthorizableNodeName.class);
registration.bindAuthorizableNodeName(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
assertTrue(((Preconditions) f.get(registration)).areSatisfied());
registration.deactivate();
assertTrue(((Preconditions) f.get(registration)).areSatisfied());
}
use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testUnbindMandatoryCandidateOnPreconditions.
@Test
public void testUnbindMandatoryCandidateOnPreconditions() throws Exception {
registration.activate(context.bundleContext(), requiredServiceIdMap("nodeName"));
Field f = registration.getClass().getDeclaredField("preconditions");
f.setAccessible(true);
AuthorizableNodeName mock = Mockito.mock(AuthorizableNodeName.class);
registration.bindAuthorizableNodeName(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
registration.unbindAuthorizableNodeName(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
Preconditions preconditions = (Preconditions) f.get(registration);
assertFalse(preconditions.areSatisfied());
}
use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.
the class WhiteboardAuthorizableNodeNameTest method testRegisteredImplementation.
@Test
public void testRegisteredImplementation() {
authorizableNodeName.start(whiteboard);
AuthorizableNodeName registered = new AuthorizableNodeName() {
@Nonnull
@Override
public String generateNodeName(@Nonnull String authorizableId) {
return "generated";
}
};
whiteboard.register(AuthorizableNodeName.class, registered, ImmutableMap.of());
assertEquals(registered.generateNodeName(TEST_ID), authorizableNodeName.generateNodeName(TEST_ID));
}
use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.
the class UserProviderTest method testCollisions.
@Test
public void testCollisions() throws Exception {
ConfigurationParameters config = ConfigurationParameters.of(UserConstants.PARAM_AUTHORIZABLE_NODE_NAME, new AuthorizableNodeName() {
@Nonnull
@Override
public String generateNodeName(@Nonnull String authorizableId) {
return "aaa";
}
});
UserProvider up = new UserProvider(root, config);
try {
Tree u1 = up.createUser("a", null);
assertEquals("aaa", u1.getName());
Tree u2 = up.createUser("b", null);
assertEquals("aaa1", u2.getName());
Tree u3 = up.createUser("c", null);
assertEquals("aaa2", u3.getName());
Tree u4 = up.createUser("d", null);
assertEquals("aaa3", u4.getName());
} finally {
root.refresh();
}
}
Aggregations