org.opends.server.util.cli
Class LDAPConnectionConsoleInteraction

java.lang.Object
  extended by org.opends.server.util.cli.LDAPConnectionConsoleInteraction

public class LDAPConnectionConsoleInteraction
extends java.lang.Object

Supports interacting with a user through the command line to prompt for information necessary to create an LDAP connection.


Constructor Summary
LDAPConnectionConsoleInteraction(ConsoleApplication app, SecureConnectionCliArgs secureArgs)
          Constructs a parameterized instance.
 
Method Summary
 boolean checkServerCertificate(java.security.cert.X509Certificate[] chain)
          Indicate if the certificate chain can be trusted.
 boolean checkServerCertificate(java.security.cert.X509Certificate[] chain, java.lang.String authType, java.lang.String host)
          Indicate if the certificate chain can be trusted.
 java.lang.String getAdministratorUID()
          Gets the administrator UID name that should be used for connections based on this interaction.
 java.lang.String getBindDN()
          Gets the bind DN name that should be used for connections based on this interaction.
 java.lang.String getBindPassword()
          Gets the bind password that should be used for connections based on this interaction.
 CommandBuilder getCommandBuilder()
          Returns the command builder with the equivalent arguments on the non-interactive mode.
 java.lang.String getHostName()
          Gets the host name that should be used for connections based on this interaction.
 javax.net.ssl.KeyManager getKeyManager()
          Gets the key manager that should be used for connections based on this interaction.
 java.security.KeyStore getKeyStore()
          Gets the key store that should be used for connections based on this interaction.
 int getPortNumber()
          Gets the port number name that should be used for connections based on this interaction.
 java.lang.String getProvidedAdminUID()
          Returns the explicitly provided Admin UID from the user (interactively or through the argument).
 java.lang.String getProvidedBindDN()
          Returns the explicitly provided bind DN from the user (interactively or through the argument).
 javax.net.ssl.TrustManager getTrustManager()
          Gets the trust manager that should be used for connections based on this interaction.
 void initializeTrustManagerIfRequired()
          Forces the initialization of the trust manager with the arguments provided by the user.
 boolean isTrustStoreInMemory()
          Indicate if the truststore is in memory.
 boolean isUseAdminOrBindDn()
          Tells whether during interaction we can ask for both the DN or the admin UID.
 LDAPConnectionOptions populateLDAPOptions(LDAPConnectionOptions options)
          Populates a set of LDAP options with state from this interaction.
 boolean promptForCertificateConfirmation(java.lang.Throwable t, ApplicationTrustManager usedTrustManager, java.lang.String usedUrl, boolean displayErrorMessage, java.util.logging.Logger logger)
          Prompts the user to accept the certificate.
 void resetHeadingDisplayed()
          Resets the heading displayed flag, so that next time we call run the heading is displayed.
 void run()
          Interact with the user though the console to get information necessary to establish an LDAP connection.
 void run(boolean canUseSSL, boolean canUseStartTLS)
          Interact with the user though the console to get information necessary to establish an LDAP connection.
 void setDisplayLdapIfSecureParameters(boolean displayLdapIfSecureParameters)
          Tells whether we propose LDAP as protocol even if the user provided security parameters.
 void setHeadingMessage(Message heading)
          Sets the heading that is displayed in interactive mode.
 void setPortNumber(int portNumber)
          Sets the port number name that should be used for connections based on this interaction.
 void setUseAdminOrBindDn(boolean useAdminOrBindDn)
          Tells whether we can ask during interaction for both the DN and the admin UID or not.
 boolean useSSL()
          Indicates whether or not a connection should use SSL based on this interaction.
 boolean useStartTLS()
          Indicates whether or not a connection should use StartTLS based on this interaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LDAPConnectionConsoleInteraction

public LDAPConnectionConsoleInteraction(ConsoleApplication app,
                                        SecureConnectionCliArgs secureArgs)
Constructs a parameterized instance.

Parameters:
app - console application
secureArgs - existing set of arguments that have already been parsed and contain some potential command line specified LDAP arguments
Method Detail

run

public void run()
         throws ArgumentException
Interact with the user though the console to get information necessary to establish an LDAP connection.

Throws:
ArgumentException - if there is a problem with the arguments

run

public void run(boolean canUseSSL,
                boolean canUseStartTLS)
         throws ArgumentException
Interact with the user though the console to get information necessary to establish an LDAP connection.

Parameters:
canUseSSL - whether we can propose to connect using SSL or not.
canUseStartTLS - whether we can propose to connect using Start TLS or not.
Throws:
ArgumentException - if there is a problem with the arguments

useSSL

public boolean useSSL()
Indicates whether or not a connection should use SSL based on this interaction.

Returns:
boolean where true means use SSL

useStartTLS

public boolean useStartTLS()
Indicates whether or not a connection should use StartTLS based on this interaction.

Returns:
boolean where true means use StartTLS

getHostName

public java.lang.String getHostName()
Gets the host name that should be used for connections based on this interaction.

Returns:
host name for connections

getPortNumber

public int getPortNumber()
Gets the port number name that should be used for connections based on this interaction.

Returns:
port number for connections

setPortNumber

public void setPortNumber(int portNumber)
Sets the port number name that should be used for connections based on this interaction.

Parameters:
portNumber - port number for connections

getBindDN

public java.lang.String getBindDN()
Gets the bind DN name that should be used for connections based on this interaction.

Returns:
bind DN for connections

getAdministratorUID

public java.lang.String getAdministratorUID()
Gets the administrator UID name that should be used for connections based on this interaction.

Returns:
administrator UID for connections

getBindPassword

public java.lang.String getBindPassword()
Gets the bind password that should be used for connections based on this interaction.

Returns:
bind password for connections

getTrustManager

public javax.net.ssl.TrustManager getTrustManager()
Gets the trust manager that should be used for connections based on this interaction.

Returns:
trust manager for connections

getKeyStore

public java.security.KeyStore getKeyStore()
Gets the key store that should be used for connections based on this interaction.

Returns:
key store for connections

getKeyManager

public javax.net.ssl.KeyManager getKeyManager()
Gets the key manager that should be used for connections based on this interaction.

Returns:
key manager for connections

isTrustStoreInMemory

public boolean isTrustStoreInMemory()
Indicate if the truststore is in memory.

Returns:
true if the truststore is in memory.

checkServerCertificate

public boolean checkServerCertificate(java.security.cert.X509Certificate[] chain)
Indicate if the certificate chain can be trusted.

Parameters:
chain - The certificate chain to validate
Returns:
true if the server certificate is trusted.

checkServerCertificate

public boolean checkServerCertificate(java.security.cert.X509Certificate[] chain,
                                      java.lang.String authType,
                                      java.lang.String host)
Indicate if the certificate chain can be trusted.

Parameters:
chain - The certificate chain to validate
authType - the authentication type.
host - the host we tried to connect and that presented the certificate.
Returns:
true if the server certificate is trusted.

populateLDAPOptions

public LDAPConnectionOptions populateLDAPOptions(LDAPConnectionOptions options)
                                          throws SSLConnectionException
Populates a set of LDAP options with state from this interaction.

Parameters:
options - existing set of options; may be null in which case this method will create a new set of LDAPConnectionOptions to be returned
Returns:
used during this interaction
Throws:
SSLConnectionException - if this interaction has specified the use of SSL and there is a problem initializing the SSL connection factory

promptForCertificateConfirmation

public boolean promptForCertificateConfirmation(java.lang.Throwable t,
                                                ApplicationTrustManager usedTrustManager,
                                                java.lang.String usedUrl,
                                                boolean displayErrorMessage,
                                                java.util.logging.Logger logger)
Prompts the user to accept the certificate.

Parameters:
t - the throwable that was generated because the certificate was not trusted.
usedTrustManager - the trustManager used when trying to establish the connection.
usedUrl - the LDAP URL used to connect to the server.
displayErrorMessage - whether to display an error message before asking to accept the certificate or not.
logger - the Logger used to log messages.
Returns:
true if the user accepted the certificate and false otherwise.

setHeadingMessage

public void setHeadingMessage(Message heading)
Sets the heading that is displayed in interactive mode.

Parameters:
heading - the heading that is displayed in interactive mode.

getCommandBuilder

public CommandBuilder getCommandBuilder()
Returns the command builder with the equivalent arguments on the non-interactive mode.

Returns:
the command builder with the equivalent arguments on the non-interactive mode.

isUseAdminOrBindDn

public boolean isUseAdminOrBindDn()
Tells whether during interaction we can ask for both the DN or the admin UID.

Returns:
true if during interaction we can ask for both the DN and the admin UID and false otherwise.

setUseAdminOrBindDn

public void setUseAdminOrBindDn(boolean useAdminOrBindDn)
Tells whether we can ask during interaction for both the DN and the admin UID or not.

Parameters:
useAdminOrBindDn - whether we can ask for both the DN and the admin UID during interaction or not.

setDisplayLdapIfSecureParameters

public void setDisplayLdapIfSecureParameters(boolean displayLdapIfSecureParameters)
Tells whether we propose LDAP as protocol even if the user provided security parameters. This is required in command-lines that access multiple servers (like dsreplication).

Parameters:
displayLdapIfSecureParameters - whether propose LDAP as protocol even if the user provided security parameters or not.

resetHeadingDisplayed

public void resetHeadingDisplayed()
Resets the heading displayed flag, so that next time we call run the heading is displayed.


initializeTrustManagerIfRequired

public void initializeTrustManagerIfRequired()
                                      throws ArgumentException
Forces the initialization of the trust manager with the arguments provided by the user.

Throws:
ArgumentException - if there is an error with the arguments provided by the user.

getProvidedAdminUID

public java.lang.String getProvidedAdminUID()
Returns the explicitly provided Admin UID from the user (interactively or through the argument).

Returns:
the explicitly provided Admin UID from the user (interactively or through the argument).

getProvidedBindDN

public java.lang.String getProvidedBindDN()
Returns the explicitly provided bind DN from the user (interactively or through the argument).

Returns:
the explicitly provided bind DN from the user (interactively or through the argument).