/*
* 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.
* Portion Copyright 2013 ForgeRock AS.
*/
/**
* The object of this class represent an OpenDS server.
*/
public class ServerDescriptor
{
new HashSet<ReplicaDescriptor>();
/**
* 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.
*/
{
return copy;
}
/**
* 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.
*/
{
if (isReplicationServer())
{
}
return hostPort;
}
/**
* 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()
{
int id = -1;
if (isReplicationServer())
{
}
return id;
}
/**
* 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()
{
int port = -1;
if (isReplicationServer())
{
}
return port;
}
/**
* 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()
{
boolean isReplicationSecure;
if (isReplicationServer())
{
}
else
{
isReplicationSecure = false;
}
return isReplicationSecure;
}
/**
* 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.
*/
{
{
}
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.
*/
{
int port = -1;
if (!serverProperties.isEmpty())
{
if (s != null)
{
for (int i=0; i<s.size(); i++)
{
{
break;
}
}
}
}
if (port != -1)
{
}
return ldapUrl;
}
/**
* 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.
*/
{
int port = -1;
if (!serverProperties.isEmpty())
{
if (s != null)
{
for (int i=0; i<s.size(); i++)
{
{
break;
}
}
}
}
if (port != -1)
{
}
return ldapsUrl;
}
/**
* 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.
*/
{
int port = -1;
if (!serverProperties.isEmpty())
{
if (s != null)
{
for (int i=0; i<s.size(); i++)
{
{
break;
}
}
}
}
if (port != -1)
{
}
return adminConnectorUrl;
}
/**
* 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 (s != null)
{
for (int i=0; i<s.size(); i++)
{
{
break;
}
}
}
if (securePreferred)
{
if (s != null)
{
for (int i=0; i<s.size(); i++)
{
{
break;
}
}
}
}
}
else
{
if (securePreferred)
{
}
else
{
}
{
{
{
}
{
}
{
}
else
{
}
if (p != null)
{
try
{
}
catch (Throwable t)
{
adsProperties, t);
}
break;
}
else
{
}
}
}
}
}
/**
* Returns an Id that is unique for this server.
* @return an Id that is unique for this server.
*/
{
{
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()
{
return((byte[])
}
/**
* Returns the schema generation ID of the server.
* @return the schema generation ID of the server.
*/
{
}
/**
* 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.
*/
{
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)
{
int port = -1;
for (int j=0; j<s.size(); j++)
{
{
break;
}
}
if (port == -1)
{
if (p.size() > 0)
{
}
}
else
{
}
}
}
boolean startTLSEnabled = false;
{
}
}
/**
* 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.
*/
{
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
{
}
}
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
{
}
}
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
{
}
{
if (!addReplica)
{
{
if (addReplica)
{
break;
}
}
}
if(addReplica)
{
suffix.setReplicas(r);
int nEntries = -1;
{
if (index != -1)
{
{
try
{
}
catch (Throwable t)
{
/* Ignore */
}
break;
}
}
}
}
}
}
}
}
finally
{
}
}
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.
*/
{
/* 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;
}
}
}
}
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 posessing 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. */
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;
}
/*
* The following 2 methods are convenience methods to retrieve String values
* from an entry.
*/
throws NamingException
{
}
throws NamingException
{
}
/**
* 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 <CODE>true</CODE> if the the provided strings represent the same
* DN and <CODE>false</CODE> otherwise.
* @param dn1 the first dn to compare.
* @param dn2 the second dn to compare.
* @return <CODE>true</CODE> if the the provided strings represent the same
* DN and <CODE>false</CODE> otherwise.
*/
{
boolean areDnsEqual = false;
try
{
{
/* ignore */
}
return areDnsEqual;
}
/**
* 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.
*/
int replicationPort)
{
}
/**
* 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.
*/
{
}
}