ServerDescriptor.java revision 754f0bca5bd3fd27daabfa5a0b187fea3218f737
/*
* 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 2007-2010 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS.
*/
/** The object of this class represent an OpenDS server. */
public class ServerDescriptor
{
private TopologyCacheException lastException;
/**
* Enumeration containing the different server properties that we can keep in
* the ServerProperty object.
*/
public enum ServerProperty
{
/** The associated value is a String. */
/** The associated value is an ArrayList of Integer. */
/** The associated value is an ArrayList of Integer. */
/** The associated value is an Integer. */
/** The associated value is an ArrayList of Boolean. */
/** The associated value is an ArrayList of Boolean. */
/** The associated value is an ArrayList of Boolean. */
/** The associated value is an ArrayList of Boolean. */
/** The associated value is an ArrayList of Integer. */
/** The associated value is an ArrayList of Integer. */
/** The associated value is an ArrayList of Boolean. */
/** The associated value is an ArrayList of Boolean. */
/** The associated value is an Integer. */
/** The associated value is a Boolean. */
/** The associated value is a Boolean. */
/** The associated value is a Boolean. */
/** List of servers specified in the Replication Server configuration. This is a Set of String. */
/** The associated value is an Integer. */
/**
* The instance key-pair public-key certificate. The associated value is a
* byte[] (ds-cfg-public-key-certificate;binary).
*/
/** The schema generation ID. */
}
/** Default constructor. */
protected ServerDescriptor()
{
}
/**
* Returns the replicas contained on the server.
* @return the replicas contained on the server.
*/
{
}
/**
* Sets the replicas contained on the server.
* @param replicas the replicas contained on the server.
*/
{
}
/**
* Returns a Map containing the ADS properties of the server.
* @return a Map containing the ADS properties of the server.
*/
{
return adsProperties;
}
/**
* Returns a Map containing the properties of the server.
* @return a Map containing the properties of the server.
*/
{
return serverProperties;
}
/**
* Tells whether this server is registered in the ADS or not.
* @return <CODE>true</CODE> if the server is registered in the ADS and
* <CODE>false</CODE> otherwise.
*/
public boolean isRegistered()
{
return !adsProperties.isEmpty();
}
/**
* Tells whether this server is a replication server or not.
* @return <CODE>true</CODE> if the server is a replication server and
* <CODE>false</CODE> otherwise.
*/
public boolean isReplicationServer()
{
}
/**
* Tells whether replication is enabled on this server or not.
* @return <CODE>true</CODE> if replication is enabled and
* <CODE>false</CODE> otherwise.
*/
public boolean isReplicationEnabled()
{
}
/**
* Returns the String representation of this replication server based
* on the information we have ("hostname":"replication port") and
* <CODE>null</CODE> if this is not a replication server.
* @return the String representation of this replication server based
* on the information we have ("hostname":"replication port") and
* <CODE>null</CODE> if this is not a replication server.
*/
public String getReplicationServerHostPort()
{
if (isReplicationServer())
{
}
return null;
}
/**
* Returns the replication server ID of this server and -1 if this is not a
* replications server.
* @return the replication server ID of this server and -1 if this is not a
* replications server.
*/
public int getReplicationServerId()
{
if (isReplicationServer())
{
}
return -1;
}
/**
* Returns the replication port of this server and -1 if this is not a
* replications server.
* @return the replication port of this server and -1 if this is not a
* replications server.
*/
public int getReplicationServerPort()
{
if (isReplicationServer())
{
}
return -1;
}
/**
* Returns whether the communication with the replication port on the server
* is encrypted or not.
* @return <CODE>true</CODE> if the communication with the replication port on
* the server is encrypted and <CODE>false</CODE> otherwise.
*/
public boolean isReplicationSecure()
{
return isReplicationServer()
}
/**
* Sets the ADS properties of the server.
* @param adsProperties a Map containing the ADS properties of the server.
*/
public void setAdsProperties(
{
this.adsProperties.clear();
}
/**
* Returns the host name of the server.
* @return the host name of the server.
*/
public String getHostName()
{
{
return host;
}
}
/**
* Returns the URL to access this server using LDAP. Returns
* <CODE>null</CODE> if the server is not configured to listen on an LDAP
* port.
* @return the URL to access this server using LDAP.
*/
public String getLDAPURL()
{
}
/**
* Returns the URL to access this server using LDAPS. Returns
* <CODE>null</CODE> if the server is not configured to listen on an LDAPS
* port.
* @return the URL to access this server using LDAP.
*/
public String getLDAPsURL()
{
}
{
if (port != -1)
{
}
return null;
}
{
if (!serverProperties.isEmpty())
{
}
return -1;
}
/**
* Returns the URL to access this server using the administration connector.
* Returns <CODE>null</CODE> if the server cannot get the administration
* connector.
* @return the URL to access this server using the administration connector.
*/
public String getAdminConnectorURL()
{
}
/**
* Returns the list of enabled administration ports.
* @return the list of enabled administration ports.
*/
{
if (s != null)
{
for (int i=0; i<s.size(); i++)
{
{
}
}
}
return ports;
}
/**
* Returns a String of type host-name:port-number for the server. If
* the provided securePreferred is set to true the port that will be used
* will be the administration connector port.
* @param securePreferred whether to try to use the secure port as part
* of the returning String or not.
* @return a String of type host-name:port-number for the server.
*/
{
int port = -1;
if (!serverProperties.isEmpty())
{
if (securePreferred)
{
}
}
else
{
if (securePreferred)
{
}
else
{
}
{
{
if (p != null)
{
try
{
}
catch (Throwable t)
{
adsProperties, t));
}
break;
}
else
{
}
}
}
}
}
{
{
}
{
}
{
}
else
{
}
}
{
if (s != null)
{
for (int i=0; i<s.size(); i++)
{
{
}
}
}
return defaultValue;
}
/**
* Returns an Id that is unique for this server.
* @return an Id that is unique for this server.
*/
{
if (!serverProperties.isEmpty())
{
ServerProperty [] props =
{
};
for (Object o : s) {
}
}
}
else
{
{
};
{
if (i != 0)
{
}
}
}
}
/**
* Returns the instance-key public-key certificate retrieved from the
* truststore backend of the instance referenced through this descriptor.
*
* @return The public-key certificate of the instance.
*/
public byte[] getInstancePublicKeyCertificate()
{
}
/**
* Returns the schema generation ID of the server.
* @return the schema generation ID of the server.
*/
public String getSchemaReplicationID()
{
}
/**
* Returns the last exception that was encountered reading the configuration
* of the server. Returns null if there was no problem loading the
* configuration of the server.
* @return the last exception that was encountered reading the configuration
* of the server. Returns null if there was no problem loading the
* configuration of the server.
*/
public TopologyCacheException getLastException()
{
return lastException;
}
/**
* Sets the last exception that occurred while reading the configuration of
* the server.
* @param lastException the last exception that occurred while reading the
* configuration of the server.
*/
{
this.lastException = lastException;
}
/**
* This methods updates the ADS properties (the ones that were read from
* the ADS) with the contents of the server properties (the ones that were
* read directly from the server).
*/
public void updateAdsPropertiesWithServerProperties()
{
ServerProperty[][] sProps =
{
};
{
};
{
if (s != null)
{
if (port == -1)
{
if (!p.isEmpty())
{
}
}
else
{
}
}
}
boolean startTLSEnabled = false;
{
}
}
{
{
{
}
}
return -1;
}
/**
* Creates a ServerDescriptor object based on some ADS properties provided.
* @param adsProperties the ADS properties of the server.
* @return a ServerDescriptor object that corresponds to the provided ADS
* properties.
*/
public static ServerDescriptor createStandalone(
{
return desc;
}
/**
* Creates a ServerDescriptor object based on the configuration that we read
* using the provided InitialLdapContext.
* @param ctx the InitialLdapContext that will be used to read the
* configuration of the server.
* @param filter the topology cache filter describing the information that
* must be retrieved.
* @return a ServerDescriptor object that corresponds to the read
* configuration.
* @throws NamingException if a problem occurred reading the server
* configuration.
*/
throws NamingException
{
return desc;
}
throws NamingException
{
new String[] {
"ds-cfg-enabled",
"ds-cfg-listen-address",
"ds-cfg-listen-port",
"ds-cfg-use-ssl",
"ds-cfg-allow-start-tls",
"objectclass"
});
try
{
{
if (isSecure)
{
}
else
{
}
}
}
finally
{
}
}
private static void updateAdminConnectorConfiguration(ServerDescriptor desc, InitialLdapContext ctx)
throws NamingException
{
new String[] {
"ds-cfg-listen-port",
"objectclass"
});
try
{
// we should have a single administration connector
}
// Even if we have a single port, use an array to be consistent with
// other protocols.
if (adminConnectorPort != null)
{
}
}
finally
{
}
}
private static void updateJmxConfiguration(ServerDescriptor desc, InitialLdapContext ctx) throws NamingException
{
new String[] {
"ds-cfg-enabled",
"ds-cfg-listen-address",
"ds-cfg-listen-port",
"ds-cfg-use-ssl",
"objectclass"
});
try
{
{
if (isSecure)
{
}
else
{
}
}
}
finally
{
}
}
throws NamingException
{
if (!cacheFilter.searchBaseDNInformation())
{
return;
}
new String[] {
"ds-cfg-base-dn",
"ds-cfg-backend-id",
});
try
{
{
{
{
}
else
{
}
{
{
suffix.setReplicas(r);
int nEntries = -1;
{
if (index != -1)
{
{
try
{
}
catch (Throwable t)
{
/* Ignore */
}
break;
}
}
}
}
}
}
}
}
finally
{
}
}
{
if (cacheFilter.searchAllBaseDNs())
{
return true;
}
{
{
return true;
}
}
return false;
}
throws NamingException
{
boolean replicationEnabled = false;
new String[] {
"ds-cfg-enabled"
});
"cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config");
try
{
while(syncProviders.hasMore())
{
"ds-cfg-enabled")))
{
replicationEnabled = true;
}
}
}
catch (NameNotFoundException nse)
{
/* ignore */
}
finally
{
if (syncProviders != null)
{
}
}
{
ctls = new SearchControls();
new String[] {
"ds-cfg-base-dn",
"ds-cfg-replication-server",
"ds-cfg-server-id"
});
filter = "(objectclass=ds-cfg-replication-domain)";
"cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config");
try
{
while(syncProviders.hasMore())
{
"ds-cfg-replication-server");
{
{
{
// Keep the values of the replication servers in lower case
// to make use of Sets as String simpler.
for (String s: replicationServers)
{
}
}
}
}
}
}
catch (NameNotFoundException nse)
{
/* ignore */
}
finally
{
if (syncProviders != null)
{
}
}
}
ctls = new SearchControls();
new String[] {
"ds-cfg-replication-port", "ds-cfg-replication-server",
"ds-cfg-replication-server-id"
});
filter = "(objectclass=ds-cfg-replication-server)";
"Synchronization,cn=Synchronization Providers,cn=config");
try
{
{
// Keep the values of the replication servers in lower case
// to make use of Sets as String simpler.
{
}
}
}
catch (NameNotFoundException nse)
{
/* ignore */
}
finally
{
{
}
}
boolean replicationSecure = false;
if (replicationEnabled)
{
ctls = new SearchControls();
new String[] {"ds-cfg-ssl-encryption"});
filter = "(objectclass=ds-cfg-crypto-manager)";
try
{
{
}
}
finally
{
}
}
}
/**
Updates the instance key public-key certificate value of this context from
the local truststore of the instance bound by this context. Any current
value of the certificate is overwritten. The intent of this method is to
retrieve the instance-key public-key certificate when this context is bound
to an instance, and cache it for later use in registering the instance into
ADS.
@param desc The map to update with the instance key-pair public-key
certificate.
@param ctx The bound server instance.
@throws NamingException if unable to retrieve certificate from bound
instance.
*/
private static void updatePublicKeyCertificate(ServerDescriptor desc, InitialLdapContext ctx) throws NamingException
{
/* TODO: this DN is declared in some core constants file. Create a constants
file for the installer and import it into the core. */
for (int i = 0; i < 2 ; ++i) {
/* If the entry does not exist in the instance's truststore backend, add
it (which induces the CryptoManager to create the public-key
certificate attribute), then repeat the search. */
try {
/* attribute ds-cfg-public-key-certificate is a MUST in the schema */
}
break;
}
catch (NameNotFoundException x) {
if (0 == i) {
// Poke CryptoManager to initialize truststore. Note the special attribute in the request.
}
else {
throw x;
}
}
}
}
private static void updateMiscellaneous(ServerDescriptor desc, InitialLdapContext ctx) throws NamingException
{
new String[] {
"ds-sync-generation-id"
});
try
{
{
}
}
finally
{
}
}
/**
Seeds the bound instance's local ads-truststore with a set of instance
key-pair public key certificates. The result is the instance will trust any
instance possessing the private key corresponding to one of the public-key
certificates. This trust is necessary at least to initialize replication,
which uses the trusted certificate entries in the ads-truststore for server
authentication.
@param ctx The bound instance.
@param keyEntryMap The set of valid (i.e., not tagged as compromised)
instance key-pair public-key certificate entries in ADS represented as a map
from keyID to public-key certificate (binary).
@throws NamingException in case an error occurs while updating the instance's
ads-truststore via LDAP.
*/
public static void seedAdsTrustStore(
throws NamingException
{
/* TODO: this DN is declared in some core constants file. Create a
constants file for the installer and import it into the core. */
final LdapName keyDn = new LdapName(rdnAttr.getID() + "=" + Rdn.escapeValue(rdnAttr.get()) + "," + TRUSTSTORE_DN);
try {
}
catch(NameAlreadyBoundException x){
}
}
}
/**
* Cleans up the contents of the ads truststore.
*
* @param ctx the bound instance.
* @throws NamingException in case an error occurs while updating the
* instance's ads-truststore via LDAP.
*/
throws NamingException
{
try
{
"(objectclass=ds-cfg-instance-key)", sc);
try
{
{
}
}
finally
{
}
{
}
}
catch (NameNotFoundException nnfe)
{
// Ignore
}
}
/**
* Returns the values of the ds-base-dn-entry count attributes for the given
* backend monitor entry using the provided InitialLdapContext.
* @param ctx the InitialLdapContext to use to update the configuration.
* @param backendID the id of the backend.
* @return the values of the ds-base-dn-entry count attribute.
* @throws NamingException if there was an error.
*/
{
new String[] {
"ds-base-dn-entry-count"
});
try
{
{
}
}
finally
{
}
return v;
}
/**
* An convenience method to know if the provided ID corresponds to a
* configuration backend or not.
* @param id the backend ID to analyze
* @return <CODE>true</CODE> if the the id corresponds to a configuration
* backend and <CODE>false</CODE> otherwise.
*/
{
}
/**
* An convenience method to know if the provided ID corresponds to the schema
* backend or not.
* @param id the backend ID to analyze
* @return <CODE>true</CODE> if the the id corresponds to the schema backend
* and <CODE>false</CODE> otherwise.
*/
{
}
/**
* Returns the replication server normalized String for a given host name
* and replication port.
* @param hostName the host name.
* @param replicationPort the replication port.
* @return the replication server normalized String for a given host name
* and replication port.
*/
{
}
/**
* Returns the normalized server representation for a given host name and
* port.
* @param hostName the host name.
* @param port the port.
* @return the normalized server representation for a given host name and
* port.
*/
{
}
/**
* Returns a representation of a base DN for a set of servers.
* @param baseDN the base DN.
* @param servers the servers.
* @return a representation of a base DN for a set of servers.
*/
{
{
}
}
/**
* Tells whether the provided server descriptor represents the same server
* as this object.
* @param server the server to make the comparison.
* @return whether the provided server descriptor represents the same server
* as this object or not.
*/
{
}
}