ControlPanelInfo.java revision 688633f95faa52515b090ff00440b1eebdaad7d9
/*
* 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 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* This is the classes that is shared among all the different places in the
* Control Panel. It contains information about the server status and
* configuration and some objects that are shared everywhere.
*
*/
public class ControlPanelInfo
{
private long poolingPeriod = 20000;
private ServerDescriptor serverDesc;
private InitialLdapContext ctx;
private InitialLdapContext userDataCtx;
// Used by the browsers
private Thread poolingThread;
private boolean stopPooling;
private boolean pooling;
private ApplicationTrustManager trustManager;
private ConnectionProtocolPolicy connectionPolicy =
private String startTLSURL;
private String adminConnectorURL;
private String localAdminConnectorURL;
private String lastWorkingBindDN;
private String lastWorkingBindPwd;
private String lastRemoteHostName;
private String lastRemoteAdministrationURL;
private static boolean mustDeregisterConfig;
private boolean isLocal = true;
new HashSet<AbstractIndexDescriptor>();
new LinkedHashSet<ConfigChangeListener>();
new LinkedHashSet<BackupCreatedListener>();
new LinkedHashSet<IndexModifiedListener>();
private static ControlPanelInfo instance;
/**
* Default constructor.
*
*/
protected ControlPanelInfo()
{
}
/**
* Returns a singleton for this instance.
* @return the control panel info.
*/
public static ControlPanelInfo getInstance()
{
{
instance = new ControlPanelInfo();
try
{
}
catch (Throwable t)
{
}
}
return instance;
}
/**
* Returns the last ServerDescriptor that has been retrieved.
* @return the last ServerDescriptor that has been retrieved.
*/
public ServerDescriptor getServerDescriptor()
{
return serverDesc;
}
/**
* Returns the list of tasks.
* @return the list of tasks.
*/
{
}
/**
* Registers a task. The Control Panel creates a task every time an operation
* is made and they are stored here.
* @param task the task to be registered.
*/
{
}
/**
* Unregisters a task.
* @param task the task to be unregistered.
*/
{
}
/**
* Tells whether an index must be reindexed or not.
* @param index the index.
* @return <CODE>true</CODE> if the index must be reindexed and
* <CODE>false</CODE> otherwise.
*/
{
boolean mustReindex = false;
for (AbstractIndexDescriptor i : modifiedIndexes)
{
{
mustReindex = true;
break;
}
}
return mustReindex;
}
/**
* Registers an index as modified. This is used by the panels to be able
* to inform the user that a rebuild of the index is required.
* @param index the index.
*/
{
}
/**
* Unregisters a modified index.
* @param index the index.
* @return <CODE>true</CODE> if the index is found in the list of modified
* indexes and <CODE>false</CODE> otherwise.
*/
{
// We might have stored indexes whose configuration has changed, just remove
// them if they have the same name, are of the same type and are defined in
// the same backend.
new HashSet<AbstractIndexDescriptor>();
for (AbstractIndexDescriptor i : modifiedIndexes)
{
{
}
}
{
return returnValue;
}
return false;
}
/**
* Unregisters all the modified indexes on a given backend.
* @param backendName the name of the backend.
*/
{
new HashSet<AbstractIndexDescriptor>();
{
// Compare only the Backend ID, since the backend object attached to
// the registered index might have changed (for instance the number of
// entries). Relying on the backend ID to identify the backend is
// safe.
{
}
}
{
{
{
}
break;
}
}
}
/**
* Returns a collection with all the modified indexes.
* @return a collection with all the modified indexes.
*/
{
}
/**
* Sets the dir context to be used by the ControlPanelInfo to retrieve
* monitoring and configuration information.
* @param ctx the connection.
*/
{
{
}
}
/**
* Returns the dir context to be used by the ControlPanelInfo to retrieve
* monitoring and configuration information.
* @return the dir context to be used by the ControlPanelInfo to retrieve
* monitoring and configuration information.
*/
public InitialLdapContext getDirContext()
{
return ctx;
}
/**
* Sets the dir context to be used by the ControlPanelInfo to retrieve
* user data.
* @param ctx the connection.
* @throws NamingException if there is a problem updating the connection pool.
*/
throws NamingException
{
if (userDataCtx != null)
{
}
this.userDataCtx = ctx;
{
getTrustManager(), null);
}
}
/**
* Returns the dir context to be used by the ControlPanelInfo to retrieve
* user data.
* @return the dir context to be used by the ControlPanelInfo to retrieve
* user data.
*/
public InitialLdapContext getUserDataDirContext()
{
return userDataCtx;
}
/**
* Informs that a backup has been created. The method will notify to all
* the backup listeners that a backup has been created.
* @param newBackup the new created backup.
*/
{
{
}
}
/**
* Informs that a set of backends have been populated. The method will notify
* to all the backend populated listeners.
* @param backends the populated backends.
*/
{
{
}
}
/**
* Informs that an index has been modified. The method will notify to all
* the index listeners that an index has been modified.
* @param modifiedIndex the modified index.
*/
{
{
}
}
/**
* Returns an empty new server descriptor instance.
* @return an empty new server descriptor instance.
*/
protected ServerDescriptor createNewServerDescriptorInstance()
{
return new ServerDescriptor();
}
/**
* Returns a reader that will read the configuration from a file.
* @return a reader that will read the configuration from a file.
*/
protected ConfigFromFile createNewConfigFromFileReader()
{
return new ConfigFromFile();
}
/**
* Returns a reader that will read the configuration from a dir context.
* @return a reader that will read the configuration from a dir context.
*/
{
return configFromDirContext;
}
/**
* Updates the contents of the server descriptor with the provider reader.
* @param reader the configuration reader.
* @param desc the server descriptor.
*/
{
}
/**
* Regenerates the last found ServerDescriptor object.
*
*/
public synchronized void regenerateDescriptor()
{
if (isLocal)
{
boolean windowsServiceEnabled = false;
if (isWindows())
{
}
}
else
{
if (lastRemoteHostName != null)
{
}
}
{
{
if (userDataCtx != null)
{
userDataCtx = null;
}
}
if (isLocal)
{
}
else
{
}
desc.setAuthenticated(false);
}
else if (!isLocal ||
{
{
// Try with previous credentials.
try
{
if (isLocal)
{
}
else if (lastRemoteAdministrationURL != null)
{
getTrustManager(), null);
}
}
catch (ConfigReadException cre)
{
// Ignore: we will ask the user for credentials.
}
catch (NamingException ne)
{
// Ignore: we will ask the user for credentials.
}
{
}
}
{
}
else
{
{
}
else
{
if (!connectionWorks)
{
if (isLocal)
{
// Try with off-line info
}
else
{
}
userDataCtx = null;
}
}
}
{
if (reader instanceof ConfigFromDirContext)
{
if (installPath != null)
{
}
if (instancePath != null)
{
}
}
}
}
else
{
desc.setAuthenticated(false);
}
{
}
{
serverDesc = desc;
if (serverDesc.isLocal())
{
}
{
}
}
}
{
{
{
}
{
}
}
return status;
}
private void unregisterConnection(LDAPConnectionPool connectionPool, InitialLdapContext userDataCtx)
{
{
try
{
}
catch (Throwable t)
{
}
}
}
/**
* Adds a configuration change listener.
* @param listener the listener.
*/
{
}
/**
* Removes a configuration change listener.
* @param listener the listener.
* @return <CODE>true</CODE> if the listener is found and <CODE>false</CODE>
* otherwise.
*/
{
}
/**
* Adds a backup creation listener.
* @param listener the listener.
*/
{
}
/**
* Removes a backup creation listener.
* @param listener the listener.
* @return <CODE>true</CODE> if the listener is found and <CODE>false</CODE>
* otherwise.
*/
{
}
/**
* Adds a backend populated listener.
* @param listener the listener.
*/
{
}
/**
* Removes a backend populated listener.
* @param listener the listener.
* @return <CODE>true</CODE> if the listener is found and <CODE>false</CODE>
* otherwise.
*/
public boolean removeBackendPopulatedListener(
{
}
/**
* Adds an index modification listener.
* @param listener the listener.
*/
{
}
/**
* Removes an index modification listener.
* @param listener the listener.
* @return <CODE>true</CODE> if the listener is found and <CODE>false</CODE>
* otherwise.
*/
{
}
/**
* Starts pooling the server configuration. The period of the pooling is
* specified as a parameter. This method is asynchronous and it will start
* the pooling in another thread.
*/
public synchronized void startPooling()
{
if (poolingThread != null)
{
return;
}
pooling = true;
stopPooling = false;
{
public void run()
{
try
{
while (!stopPooling)
{
cleanupTasks();
}
}
catch (Throwable t)
{
}
pooling = false;
}
});
}
/**
* Stops pooling the server. This method is synchronous, it does not return
* until the pooling is actually stopped.
*
*/
public synchronized void stopPooling()
{
stopPooling = true;
{
try
{
}
catch (Throwable t)
{
// do nothing;
}
}
pooling = false;
}
/**
* Returns the trust manager to be used by this ControlPanelInfo (and in
* general by the control panel).
* @return the trust manager to be used by this ControlPanelInfo.
*/
public ApplicationTrustManager getTrustManager()
{
return trustManager;
}
/**
* Sets the trust manager to be used by this ControlPanelInfo (and in
* general by the control panel).
* @param trustManager the trust manager to be used by this ControlPanelInfo.
*/
{
this.trustManager = trustManager;
}
/**
* Returns the timeout to establish the connection in milliseconds.
* @return the timeout to establish the connection in milliseconds.
*/
public int getConnectTimeout()
{
return connectTimeout;
}
/**
* Sets the timeout to establish the connection in milliseconds.
* Use {@code 0} to express no timeout.
* @param connectTimeout the timeout to establish the connection in
* milliseconds.
* Use {@code 0} to express no timeout.
*/
public void setConnectTimeout(int connectTimeout)
{
this.connectTimeout = connectTimeout;
}
/**
* Returns the connection policy to be used by this ControlPanelInfo (and in
* general by the control panel).
* @return the connection policy to be used by this ControlPanelInfo.
*/
{
return connectionPolicy;
}
/**
* Sets the connection policy to be used by this ControlPanelInfo (and in
* general by the control panel).
* @param connectionPolicy the connection policy to be used by this
* ControlPanelInfo.
*/
{
this.connectionPolicy = connectionPolicy;
}
/**
* Gets the LDAPS URL based in what is read in the configuration. It
* returns <CODE>null</CODE> if no LDAPS URL was found.
* @return the LDAPS URL to be used to connect to the server.
*/
public String getLDAPSURL()
{
return ldapsURL;
}
/**
* Gets the Administration Connector URL based in what is read in the
* configuration. It returns <CODE>null</CODE> if no Administration
* Connector URL was found.
* @return the Administration Connector URL to be used to connect
* to the server.
*/
public String getAdminConnectorURL()
{
if (isLocal)
{
// If the user set isLocal to true, we want to return the
// localAdminConnectorURL (in particular if regenerateDescriptor has not
// been called).
return localAdminConnectorURL;
}
return adminConnectorURL;
}
/**
* Gets the Administration Connector URL based in what is read in the local
* configuration. It returns <CODE>null</CODE> if no Administration
* Connector URL was found.
* @return the Administration Connector URL to be used to connect
* to the local server.
*/
public String getLocalAdminConnectorURL()
{
return localAdminConnectorURL;
}
/**
* Gets the LDAP URL based in what is read in the configuration. It
* returns <CODE>null</CODE> if no LDAP URL was found.
* @return the LDAP URL to be used to connect to the server.
*/
public String getLDAPURL()
{
return ldapURL;
}
/**
* Gets the Start TLS URL based in what is read in the configuration. It
* returns <CODE>null</CODE> if no Start TLS URL is found.
* @return the Start TLS URL to be used to connect to the server.
*/
public String getStartTLSURL()
{
return startTLSURL;
}
/**
* Returns the LDAP URL to be used to connect to a given ServerDescriptor
* using a certain protocol. It returns <CODE>null</CODE> if URL for the
* protocol is not found.
* @param server the server descriptor.
* @param protocol the protocol to be used.
* @return the LDAP URL to be used to connect to a given ServerDescriptor
* using a certain protocol.
*/
{
{
{
if (port > 0)
{
{
{
}
else
{
}
}
else
{
}
}
}
}
return url;
}
{
switch (protocol)
{
case LDAP:
return "ldap";
case LDAPS:
return "ldaps";
case LDAP_STARTTLS:
return "ldap";
case JMX:
return "jmx";
case JMXS:
return "jmxs";
default:
return null;
}
}
/**
* Returns the Administration Connector URL.
* It returns <CODE>null</CODE> if URL for the
* protocol is not found.
* @param server the server descriptor.
* @return the Administration Connector URL.
*/
{
if (port > 0) {
{
}
else
{
}
}
}
return null;
}
/**
* Tells whether we must connect to the server using Start TLS.
* @return <CODE>true</CODE> if we must connect to the server using Start TLS
* and <CODE>false</CODE> otherwise.
*/
public boolean connectUsingStartTLS()
{
boolean connectUsingStartTLS = false;
if (getStartTLSURL() != null)
{
}
return connectUsingStartTLS;
}
/**
* Tells whether we must connect to the server using LDAPS.
* @return <CODE>true</CODE> if we must connect to the server using LDAPS
* and <CODE>false</CODE> otherwise.
*/
public boolean connectUsingLDAPS()
{
boolean connectUsingLDAPS = false;
if (getLDAPSURL() != null)
{
}
return connectUsingLDAPS;
}
/**
* Returns the URL that must be used to connect to the server based on the
* available enabled connection handlers in the server and the connection
* policy.
* @return the URL that must be used to connect to the server.
*/
public String getURLToConnect()
{
switch (getConnectionPolicy())
{
case USE_STARTTLS:
url = getStartTLSURL();
break;
case USE_LDAP:
url = getLDAPURL();
break;
case USE_LDAPS:
url = getLDAPSURL();
break;
case USE_ADMIN:
url = getAdminConnectorURL();
break;
url = getLDAPSURL();
{
url = getStartTLSURL();
}
{
url = getLDAPURL();
}
break;
url = getLDAPURL();
{
url = getStartTLSURL();
}
{
url = getLDAPSURL();
}
break;
default:
}
return url;
}
/**
* Returns <CODE>true</CODE> if the configuration must be deregistered and
* <CODE>false</CODE> otherwise.
* This is required when we use the ConfigFileHandler to update the
* configuration, in these cases cn=config must the deregistered from the
* ConfigFileHandler and after that register again.
* @return <CODE>true</CODE> if the configuration must be deregistered and
* <CODE>false</CODE> otherwise.
*/
public boolean mustDeregisterConfig()
{
return mustDeregisterConfig;
}
/**
* Sets whether the configuration must be deregistered or not.
* @param mustDeregisterConfig whether the configuration must be deregistered
* or not.
*/
public void setMustDeregisterConfig(boolean mustDeregisterConfig)
{
}
/**
* Sets whether the server is local or not.
* @param isLocal whether the server is local or not.
*/
public void setIsLocal(boolean isLocal)
{
}
/**
* Returns <CODE>true</CODE> if we are trying to manage the local host and
* <CODE>false</CODE> otherwise.
* @return <CODE>true</CODE> if we are trying to manage the local host and
* <CODE>false</CODE> otherwise.
*/
public boolean isLocal()
{
return isLocal;
}
/**
* Returns the connection pool to be used by the LDAP entry browsers.
* @return the connection pool to be used by the LDAP entry browsers.
*/
public LDAPConnectionPool getConnectionPool()
{
return connectionPool;
}
/**
* Returns the icon pool to be used by the LDAP entry browsers.
* @return the icon pool to be used by the LDAP entry browsers.
*/
public IconPool getIconPool()
{
return iconPool;
}
/**
* Returns the pooling period in miliseconds.
* @return the pooling period in miliseconds.
*/
public long getPoolingPeriod()
{
return poolingPeriod;
}
/**
* Sets the pooling period in miliseconds.
* @param poolingPeriod the pooling time in miliseconds.
*/
public void setPoolingPeriod(long poolingPeriod)
{
this.poolingPeriod = poolingPeriod;
}
/**
* Cleans the tasks that are over.
*/
private void cleanupTasks()
{
{
{
}
}
{
}
}
/**
* Returns whether the provided task is running on the provided server or not.
* The code takes into account that the server object might not be fully
* initialized (but at least it contains the host name and the instance
* path if it is local).
* @param server the server.
* @param task the task to be analyzed.
* @return <CODE>true</CODE> if the provided task is running on the provided
* server and <CODE>false</CODE> otherwise.
*/
{
boolean isRunningOnServer;
{
{
// At this point we only have connection information about the new
// server. Use the dir context which corresponds to the server to
// compare things.
{
}
else
{
}
if (isRunningOnServer)
{
// Compare administration port;
int adminPort1 = -1;
int adminPort2 = -1;
{
}
if (getDirContext() != null)
{
}
}
}
else
{
// Compare host names and paths
{
}
else
{
}
if (isRunningOnServer)
{
{
}
else
{
}
}
}
}
else
{
isRunningOnServer = true;
}
return isRunningOnServer;
}
{
// Check the connection
boolean connectionWorks = false;
int nMaxErrors = 5;
{
try
{
{
}
connectionWorks = true;
}
catch (NamingException ne)
{
try
{
}
catch (Throwable t)
{
}
}
}
return connectionWorks;
}
/**
* Initialize the new configuration framework if needed.
*
* @throws org.opends.server.config.ConfigException
* If error occurred during the initialization
*/
{
{
try
{
}
catch (ConfigException ce)
{
}
}
}
}