Skip to content

Commit

Permalink
Fix provisioner component load (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
vharseko authored Aug 14, 2024
2 parents 5006e5b + 4e122ce commit 6da56ca
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,20 @@ private ServiceTracker<MetaDataProvider, MetaDataProvider> initServiceTracker(Bu
}

public void addedService(ServiceReference<MetaDataProvider> reference, MetaDataProvider service) {
String pid = (String) reference.getProperty(Constants.SERVICE_PID);
String pid = Long.valueOf(reference.getBundle().getBundleId()).toString();
// Instantiate and set the provider callback
service.setCallback(new ProviderTrackerCallback(service, pid));
// Add the provider to the listener
addProvider(pid, service, true);
}

public void removedService(ServiceReference<MetaDataProvider> reference, MetaDataProvider service) {
String pid = (String) reference.getProperty(Constants.SERVICE_PID);
String pid = Long.valueOf(reference.getBundle().getBundleId()).toString();
providers.remove(pid);
}

public void modifiedService(ServiceReference<MetaDataProvider> reference, MetaDataProvider service) {
String pid = (String) reference.getProperty(Constants.SERVICE_PID);
String pid = Long.valueOf(reference.getBundle().getBundleId()).toString();
modifiedProvider(pid, service, true);
}

Expand All @@ -177,8 +177,8 @@ public Collection<MetaDataProvider> getProviders() {
*/
private class ProviderTrackerCallback implements MetaDataProviderCallback {

private MetaDataProvider provider = null;
private String originId = null;
private MetaDataProvider provider;
private String originId;

/**
* Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@

package org.forgerock.openidm.config.enhanced;

import static org.forgerock.json.JsonValue.json;
import static org.forgerock.json.JsonValue.object;

import java.util.Dictionary;
import java.util.Map;

import org.forgerock.json.JsonValue;
import org.forgerock.json.JsonValueException;
import org.forgerock.openidm.core.PropertyUtil;
import org.forgerock.openidm.core.ServerConstants;
import org.forgerock.openidm.crypto.CryptoService;
import org.forgerock.openidm.osgi.ServiceUtil;
import org.forgerock.openidm.util.JsonUtil;
import org.forgerock.util.Reject;
import org.osgi.framework.BundleContext;
Expand All @@ -42,6 +35,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Dictionary;
import java.util.List;
import java.util.Map;

import static org.forgerock.json.JsonValue.json;
import static org.forgerock.json.JsonValue.object;

/**
* A service to handle enhanced configuration, including nested lists and maps
* to represent JSON based structures.
Expand Down Expand Up @@ -93,7 +93,12 @@ public JsonValue getConfigurationAsJson(ComponentContext compContext)
Reject.ifNull(compContext);

Dictionary<String, Object> dict = compContext.getProperties();
String servicePid = (String) dict.get(Constants.SERVICE_PID);
final String servicePid;
if(dict.get(Constants.SERVICE_PID) instanceof List) {
servicePid = ((List<String>) dict.get(Constants.SERVICE_PID)).get(0);
} else {
servicePid = (String) dict.get(Constants.SERVICE_PID);
}

return getConfiguration(dict, compContext.getBundleContext(), servicePid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
*/
package org.forgerock.openidm.info.impl;

import static org.forgerock.json.resource.Router.uriTemplate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.forgerock.api.models.ApiDescription;
import org.forgerock.http.ApiProducer;
import org.forgerock.json.JsonValue;
Expand Down Expand Up @@ -56,7 +46,6 @@
import org.forgerock.openidm.info.health.ReconInfoResourceProvider;
import org.forgerock.openidm.osgi.ServiceTrackerListener;
import org.forgerock.openidm.osgi.ServiceTrackerNotifier;
import org.forgerock.openidm.osgi.ServiceUtil;
import org.forgerock.services.context.Context;
import org.forgerock.services.descriptor.Describable;
import org.forgerock.util.promise.Promise;
Expand All @@ -82,6 +71,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static org.forgerock.json.resource.Router.uriTemplate;

/**
* A health service determining system state.
*/
Expand Down Expand Up @@ -566,7 +565,12 @@ private void checkState() {
if (refs != null && refs.length > 0) {
for (String req : requiredServices) {
for (ServiceReference<?> ref : refs) {
String pid = (String) ref.getProperty(Constants.SERVICE_PID);
final String pid;
if(ref.getProperty(Constants.SERVICE_PID) instanceof List) {
pid = ((List<String>) ref.getProperty(Constants.SERVICE_PID)).get(0);
} else {
pid = (String) ref.getProperty(Constants.SERVICE_PID);
}
if (pid != null && (pid.matches(req)||pid.replace("org.forgerock.","org.openidentityplatform.").matches(req))) {
missingServices.remove(req);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,9 @@
*/
package org.forgerock.openidm.provisioner.openicf.impl;

import static org.forgerock.json.JsonValue.json;
import static org.forgerock.json.JsonValue.object;
import static org.forgerock.json.resource.Responses.newActionResponse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import org.forgerock.services.context.Context;
import org.apache.commons.lang3.StringUtils;
import org.forgerock.json.JsonValue;
import org.forgerock.json.JsonValueException;
import org.forgerock.json.resource.ActionRequest;
Expand All @@ -47,8 +32,8 @@
import org.forgerock.json.resource.ReadRequest;
import org.forgerock.json.resource.RequestHandler;
import org.forgerock.json.resource.Requests;
import org.forgerock.json.resource.ResourceResponse;
import org.forgerock.json.resource.ResourceException;
import org.forgerock.json.resource.ResourceResponse;
import org.forgerock.json.resource.ServiceUnavailableException;
import org.forgerock.json.resource.SingletonResourceProvider;
import org.forgerock.json.resource.UpdateRequest;
Expand Down Expand Up @@ -77,6 +62,7 @@
import org.forgerock.openidm.router.RouteBuilder;
import org.forgerock.openidm.router.RouteEntry;
import org.forgerock.openidm.router.RouterRegistry;
import org.forgerock.services.context.Context;
import org.forgerock.util.promise.Promise;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.framework.api.APIConfiguration;
Expand All @@ -98,7 +84,6 @@
import org.identityconnectors.framework.common.objects.SyncToken;
import org.identityconnectors.framework.common.serializer.SerializerUtil;
import org.identityconnectors.framework.impl.api.local.LocalConnectorFacadeImpl;
import org.osgi.framework.Constants;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.ComponentException;
import org.osgi.service.component.annotations.Activate;
Expand All @@ -112,6 +97,20 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReference;

import static org.forgerock.json.JsonValue.json;
import static org.forgerock.json.JsonValue.object;
import static org.forgerock.json.resource.Responses.newActionResponse;

/**
* The OpenICFProvisionerService is the implementation of
* {@link CollectionResourceProvider} interface with <a
Expand Down Expand Up @@ -158,9 +157,13 @@ public class OpenICFProvisionerService implements ProvisionerService, SingletonR
private Map<String, ObjectClassInfoHelper> objectTypes;

/** The Connection Factory */
@Reference(policy = ReferencePolicy.STATIC)

protected IDMConnectionFactory connectionFactory;

@Reference(
service = IDMConnectionFactory.class,
unbind = "unbindConnectionFactory",
policy = ReferencePolicy.STATIC)
void bindConnectionFactory(final IDMConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
// update activityLogger to use the "real" activity logger on the router
Expand Down Expand Up @@ -214,6 +217,12 @@ protected void activate(ComponentContext context) {
try {
factoryPid = (String)context.getProperties().get("config.factory-pid");
jsonConfiguration = enhancedConfig.getConfigurationAsJson(context);

if(!jsonConfiguration.isDefined("name")) {
logger.info("OpenICF Provisioner Service config is not defined");
return;
}

systemIdentifier = new SimpleSystemIdentifier(jsonConfiguration);

if (!jsonConfiguration.get("enabled").defaultTo(true).asBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ boolean isLiveSync() {
}
}

private Map<SystemIdentifier, ProvisionerService> provisionerServices = new HashMap<SystemIdentifier, ProvisionerService>();
private final Map<SystemIdentifier, ProvisionerService> provisionerServices = new HashMap<>();

@SuppressWarnings("rawtypes")
@Reference(
Expand Down Expand Up @@ -198,7 +198,7 @@ protected void bindConnectionFactory(IDMConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}

private Map<String, ConnectorConfigurationHelper> connectorConfigurationHelpers = new HashMap<String, ConnectorConfigurationHelper>();
private Map<String, ConnectorConfigurationHelper> connectorConfigurationHelpers = new HashMap<>();

@Reference(
service = ConnectorConfigurationHelper.class,
Expand Down

0 comments on commit 6da56ca

Please sign in to comment.