SynchronizationProviderConfigManager.java revision f983fc4bc7a4dc0e9d175e77cfaf8a2127aaeb2d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* This class defines a utility that will be used to manage the configuration
* for the set of synchronization providers configured in the Directory Server.
* It will perform the necessary initialization of those synchronization
* providers when the server is first started, and then will manage any changes
* to them while the server is running.
*/
public class SynchronizationProviderConfigManager
implements ConfigurationChangeListener<SynchronizationProviderCfg>,
{
/**
* The mapping between configuration entry DNs and their corresponding
* synchronization provider implementations.
*/
private final ConcurrentHashMap<DN,SynchronizationProvider<SynchronizationProviderCfg>> registeredProviders;
private final ServerContext serverContext;
/**
* Creates a new instance of this synchronization provider config manager.
*
* @param serverContext
* The server context.
*/
{
this.serverContext = serverContext;
registeredProviders = new ConcurrentHashMap<DN,SynchronizationProvider<SynchronizationProviderCfg>>();
}
/**
* Initializes the configuration associated with the Directory Server
* synchronization providers. This should only be called at Directory Server
* startup.
*
* @throws ConfigException If a critical configuration problem prevents any
* of the synchronization providers from starting
* properly.
*
* @throws InitializationException If a problem occurs while initializing
* any of the synchronization providers that
* is not related to the Directory Server
* configuration.
*/
public void initializeSynchronizationProviders()
{
// Create an internal server management context and retrieve
// the root configuration which has the synchronization provider relation.
// Register as an add and delete listener so that we can
// be notified when new synchronization providers are added or existing
// sycnhronization providers are removed.
// Initialize existing synchronization providers.
{
// Get the synchronization provider's configuration.
// This will automatically decode and validate its properties.
// Register as a change listener for this synchronization provider
// entry so that we can be notified when it is disabled or enabled.
config.addChangeListener(this);
// Ignore this synchronization provider if it is disabled.
{
// Perform initialization, load the synchronization provider's
// implementation class and initialize it.
// Register the synchronization provider with the Directory Server.
// Put this synchronization provider in the hash map so that we will be
// able to find it if it is deleted or disabled.
}
}
}
/**
* {@inheritDoc}
*/
{
// Attempt to get the existing synchronization provider. This will only
// succeed if it is currently enabled.
// See whether the synchronization provider should be enabled.
{
if (configuration.isEnabled())
{
// The synchronization provider needs to be enabled. Load, initialize,
// and register the synchronization provider as per the add listener
// method.
try
{
// Perform initialization, load the synchronization provider's
// implementation class and initialize it.
// Register the synchronization provider with the Directory Server.
// Put this synchronization provider in the hash map so that we will
// be able to find it if it is deleted or disabled.
}
catch (ConfigException e)
{
if (logger.isTraceEnabled())
{
logger.traceException(e);
}
}
catch (Exception e)
{
logger.traceException(e);
}
}
}
else
{
if (configuration.isEnabled())
{
// The synchronization provider is currently active, so we don't
// need to do anything. Changes to the class name cannot be
// applied dynamically, so if the class name did change then
// indicate that administrative action is required for that
// change to take effect.
{
ccr.setAdminActionRequired(true);
}
}
else
{
// The connection handler is being disabled so remove it from
// the DirectorySerevr list, shut it down and remove it from the
// hash map.
}
}
return ccr;
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
return !configuration.isEnabled()
}
/**
* {@inheritDoc}
*/
{
// Register as a change listener for this synchronization provider entry
// so that we will be notified if when it is disabled or enabled.
configuration.addChangeListener(this);
// Ignore this synchronization provider if it is disabled.
if (configuration.isEnabled())
{
try
{
// Perform initialization, load the synchronization provider's
// implementation class and initialize it.
// Register the synchronization provider with the Directory Server.
// Put this synchronization provider in the hash map so that we will be
// able to find it if it is deleted or disabled.
}
catch (ConfigException e)
{
if (logger.isTraceEnabled())
{
logger.traceException(e);
}
}
catch (Exception e)
{
logger.traceException(e);
}
}
return ccr;
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationAddAcceptable(
{
return !configuration.isEnabled()
}
/**
* Check if the class provided in the configuration is an acceptable
* java class for a synchronization provider.
*
* @param configuration The configuration for which the class must be
* checked.
* @return true if the class is acceptable or false if not.
*/
@SuppressWarnings("unchecked")
throws ConfigException
{
// Load the class
try
{
} catch (Exception e)
{
// Handle the exception: put a message in the unacceptable reasons.
throw new ConfigException(message, e);
}
try
{
// Instantiate the class.
} catch (Exception e)
{
// Handle the exception: put a message in the unacceptable reasons.
throw new ConfigException(message, e);
}
try
{
// Initialize the Synchronization Provider.
} catch (Exception e)
{
try
{
}
{}
// Handle the exception: put a message in the unacceptable reasons.
throw new ConfigException(message, e);
}
return provider;
}
/**
* Check if the class provided in the configuration is an acceptable
* java class for a synchronization provider.
*
* @param configuration The configuration for which the class must be
* checked.
* @param unacceptableReasons A list containing the reasons why the class is
* not acceptable.
*
* @return true if the class is acceptable or false if not.
*/
private boolean isJavaClassAcceptable(
{
try
{
} catch (Exception e)
{
// Handle the exception: put a message in the unacceptable reasons.
return false;
}
}
/**
* {@inheritDoc}
*/
{
// See if the entry is registered as a synchronization provider. If so,
// deregister and stop it.
{
}
return ccr;
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationDeleteAcceptable(
{
// A delete should always be acceptable, so just return true.
return true;
}
}