use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.
the class SecurityProviderRegistration method maybeRegister.
private void maybeRegister() {
BundleContext context;
log.info("Trying to register a SecurityProvider...");
synchronized (this) {
if (this.context == null) {
log.info("Aborting: no BundleContext is available");
return;
}
if (!preconditions.areSatisfied()) {
log.info("Aborting: preconditions are not satisfied: {}", preconditions);
return;
}
if (registration != null) {
log.info("Aborting: a SecurityProvider is already registered");
return;
}
if (registering) {
log.info("Aborting: a SecurityProvider is already being registered");
return;
}
// Mark the start of a registration process.
registering = true;
// Save the BundleContext for local usage.
context = this.context;
}
// Register the SecurityProvider.
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put("type", "default");
ServiceRegistration registration = context.registerService(SecurityProvider.class.getName(), createSecurityProvider(context), properties);
synchronized (this) {
this.registration = registration;
this.registering = false;
}
log.info("SecurityProvider instance registered");
}
use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.
the class ExternalPrincipalConfigurationTest method testRemoveSyncHandler.
@Test
public void testRemoveSyncHandler() throws Exception {
Dictionary<String, Object> enableProps = new Hashtable(ImmutableMap.<String, Object>of(DefaultSyncConfigImpl.PARAM_USER_DYNAMIC_MEMBERSHIP, true));
Dictionary<String, Object> disableProps = new Hashtable(ImmutableMap.<String, Object>of(DefaultSyncConfigImpl.PARAM_USER_DYNAMIC_MEMBERSHIP, false));
DefaultSyncHandler sh = new DefaultSyncHandler();
BundleContext bundleContext = context.bundleContext();
ServiceRegistration registration1 = bundleContext.registerService(SyncHandler.class.getName(), sh, enableProps);
ServiceRegistration registration2 = bundleContext.registerService(SyncHandler.class.getName(), sh, enableProps);
ServiceRegistration registration3 = bundleContext.registerService(SyncHandler.class.getName(), sh, disableProps);
assertIsEnabled(principalConfiguration, true);
registration2.unregister();
assertIsEnabled(principalConfiguration, true);
registration1.unregister();
assertIsEnabled(principalConfiguration, false);
registration3.unregister();
assertIsEnabled(principalConfiguration, false);
}
use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.
the class BaseDocumentDiscoveryLiteServiceTest method createInstance.
SimplifiedInstance createInstance(DocumentNodeStore ns, String workingDir) throws NoSuchFieldException {
DocumentDiscoveryLiteService discoveryLite = new DocumentDiscoveryLiteService();
PrivateAccessor.setField(discoveryLite, "nodeStore", ns);
BundleContext bc = mock(BundleContext.class);
ComponentContext c = mock(ComponentContext.class);
when(c.getBundleContext()).thenReturn(bc);
final Map<String, Object> registeredServices = new HashMap<String, Object>();
when(bc.registerService(anyString(), anyObject(), (Properties) anyObject())).then(new Answer<ServiceRegistration>() {
@Override
public ServiceRegistration answer(InvocationOnMock invocation) {
registeredServices.put((String) invocation.getArguments()[0], invocation.getArguments()[1]);
return null;
}
});
discoveryLite.activate(c);
Descriptors d = (Descriptors) registeredServices.get(Descriptors.class.getName());
final SimplifiedInstance result = new SimplifiedInstance(discoveryLite, ns, d, registeredServices, 500, workingDir);
allInstances.add(result);
logger.info("Created " + result);
return result;
}
use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.
the class DocumentDiscoveryLiteServiceTest method testActivateDeactivate.
@Test
public void testActivateDeactivate() throws Exception {
// then test normal start with a DocumentNodeStore
DocumentMK mk1 = createMK(1, 0);
DocumentDiscoveryLiteService discoveryLite = new DocumentDiscoveryLiteService();
PrivateAccessor.setField(discoveryLite, "nodeStore", mk1.nodeStore);
BundleContext bc = mock(BundleContext.class);
ComponentContext c = mock(ComponentContext.class);
when(c.getBundleContext()).thenReturn(bc);
discoveryLite.activate(c);
verify(c, times(0)).disableComponent(DocumentDiscoveryLiteService.COMPONENT_NAME);
discoveryLite.deactivate();
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class TestBundleFactory method createBundleContext.
public BundleContext createBundleContext() {
BundleContext bundleContext = createMock(BundleContext.class);
Bundle[] bundles = createBundles();
expect(bundleContext.getProperty("karaf.systemBundlesStartLevel")).andReturn(Integer.toString(50)).anyTimes();
expect(bundleContext.getBundles()).andReturn(bundles).anyTimes();
expect(bundleContext.getBundle(0)).andReturn(null).anyTimes();
expect(bundleContext.getBundle(1)).andReturn(bundles[0]).anyTimes();
expect(bundleContext.getBundle(2)).andReturn(bundles[1]).anyTimes();
replay(bundleContext);
return bundleContext;
}
Aggregations