Package org.opends.server.util.cli
Class LDAPConnectionConsoleInteraction
- java.lang.Object
-
- org.opends.server.util.cli.LDAPConnectionConsoleInteraction
-
public class LDAPConnectionConsoleInteraction extends Object
Supports interacting with a user through the command line to prompt for information necessary to create an LDAP connection. Actually the LDAPConnectionConsoleInteraction is used by UninstallCliHelper, StatusCli, LDAPManagementContextFactory and ReplicationCliMain.
-
-
Constructor Summary
Constructors Constructor Description LDAPConnectionConsoleInteraction(ConsoleApplication app, SecureConnectionCliArgs secureArgs)Constructs a new console interaction.LDAPConnectionConsoleInteraction(ConsoleApplication app, SecureConnectionCliArgs secureArgs, boolean allowAnonymousIfNonInteractive)Constructs a new console interaction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckServerCertificate(X509Certificate[] chain, String authType, String host)Indicate if the certificate chain can be trusted.StringgetAdministratorUID()Gets the administrator UID name that should be used for connections based on this interaction.DNgetBindDN()Gets the bind DN name that should be used for connections based on this interaction.StringgetBindPassword()Gets the bind password that should be used for connections based on this interaction.CommandBuildergetCommandBuilder()Returns the command builder with the equivalent arguments on the non-interactive mode.intgetConnectTimeout()Returns the timeout to be used to connect with the server.StringgetHostName()Gets the host name that should be used for connections based on this interaction.KeyManagergetKeyManager()Gets the key manager that should be used for connections based on this interaction.KeyStoregetKeyStore()Gets the key store that should be used for connections based on this interaction.intgetPortNumber()Gets the port number name that should be used for connections based on this interaction.StringgetProvidedAdminUID()Returns the explicitly provided Admin UID from the user (interactively or through the argument).DNgetProvidedBindDN()Returns the explicitly provided bind DN from the user (interactively or through the argument).ApplicationTrustManagergetTrustManager()Gets the trust manager that should be used for connections based on this interaction.voidinitializeGlobalArguments(String hostName, int port, String adminUid, DN bindDn, String bindPwd, LinkedHashMap<String,String> pwdFile)Initializes the global arguments in the parser with the provided values.voidinitializeTrustManagerIfRequired()Forces the initialization of the trust manager with the arguments provided by the user.booleanisTrustAll()Indicate if all certificates must be accepted.booleanisTrustStoreInMemory()Indicate if the trust store is in memory.LDAPConnectionOptionspopulateLDAPOptions(LDAPConnectionOptions options)Populates a set of LDAP options with state from this interaction.booleanpromptForCertificateConfirmation(Throwable errorRaised, ApplicationTrustManager usedTrustManager, HostPort hostPort, org.forgerock.i18n.slf4j.LocalizedLogger logger)Prompts the user to accept the certificate.voidresetConnectionArguments()Resets the connection parameters for the LDAPConsoleInteraction object.voidresetHeadingDisplayed()Resets the heading displayed flag, so that next time we call run the heading is displayed.voidrun()Interact with the user though the console to get information necessary to establish an LDAP connection.voidrun(boolean canUseStartTLS)Interact with the user though the console to get information necessary to establish an LDAP connection.voidsetDisplayLdapIfSecureParameters(boolean displayLdapIfSecureParameters)Tells whether we propose LDAP as protocol even if the user provided security parameters.voidsetHeadingMessage(org.forgerock.i18n.LocalizableMessage heading)Sets the heading that is displayed in interactive mode.voidsetPortNumber(int portNumber)Sets the port number name that should be used for connections based on this interaction.voidsetUseAdminOrBindDn(boolean useAdminOrBindDn)Tells whether we can ask during interaction for both the DN and the admin UID or not.booleanuseSSL()Indicates whether a connection should use SSL based on this interaction.booleanuseStartTLS()Indicates whether a connection should use StartTLS based on this interaction.
-
-
-
Constructor Detail
-
LDAPConnectionConsoleInteraction
public LDAPConnectionConsoleInteraction(ConsoleApplication app, SecureConnectionCliArgs secureArgs)
Constructs a new console interaction.- Parameters:
app- console applicationsecureArgs- existing set of arguments that have already been parsed and contain some potential command line specified LDAP arguments
-
LDAPConnectionConsoleInteraction
public LDAPConnectionConsoleInteraction(ConsoleApplication app, SecureConnectionCliArgs secureArgs, boolean allowAnonymousIfNonInteractive)
Constructs a new console interaction.- Parameters:
app- console applicationsecureArgs- existing set of arguments that have already been parsed and contain some potential command line specified LDAP argumentsallowAnonymousIfNonInteractive- If this console interaction should allow anonymous user in non interactive mode. If console application is interactive, the user will always be prompted for credentials.
-
-
Method Detail
-
run
public void run() throws ArgumentExceptionInteract 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 canUseStartTLS) throws ArgumentExceptionInteract with the user though the console to get information necessary to establish an LDAP connection.- Parameters:
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 a connection should use SSL based on this interaction.- Returns:
- boolean where true means use SSL
-
useStartTLS
public boolean useStartTLS()
Indicates whether a connection should use StartTLS based on this interaction.- Returns:
- boolean where true means use StartTLS
-
getHostName
public 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 DN getBindDN()
Gets the bind DN name that should be used for connections based on this interaction.- Returns:
- bind DN for connections
-
getAdministratorUID
public String getAdministratorUID()
Gets the administrator UID name that should be used for connections based on this interaction.- Returns:
- administrator UID for connections
-
getBindPassword
public String getBindPassword()
Gets the bind password that should be used for connections based on this interaction.- Returns:
- bind password for connections
-
getTrustManager
public ApplicationTrustManager getTrustManager()
Gets the trust manager that should be used for connections based on this interaction.- Returns:
- trust manager for connections
-
getKeyStore
public KeyStore getKeyStore()
Gets the key store that should be used for connections based on this interaction.- Returns:
- key store for connections
-
getKeyManager
public 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 trust store is in memory.- Returns:
- true if the trust store is in memory.
-
isTrustAll
public boolean isTrustAll()
Indicate if all certificates must be accepted.- Returns:
- true all certificates must be accepted.
-
getConnectTimeout
public int getConnectTimeout()
Returns the timeout to be used to connect with the server.- Returns:
- the timeout to be used to connect with the server.
-
checkServerCertificate
public boolean checkServerCertificate(X509Certificate[] chain, String authType, String host)
Indicate if the certificate chain can be trusted.- Parameters:
chain- The certificate chain to validateauthType- 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 ofLDAPConnectionOptionsto 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(Throwable errorRaised, ApplicationTrustManager usedTrustManager, HostPort hostPort, org.forgerock.i18n.slf4j.LocalizedLogger logger)
Prompts the user to accept the certificate.- Parameters:
errorRaised- the error raised because the certificate was not trusted.usedTrustManager- the trustManager used when trying to establish the connection.hostPort- the HostPort used to connect to the server.logger- the Logger used to log messages.- Returns:
trueif the user accepted the certificate andfalseotherwise.
-
setHeadingMessage
public void setHeadingMessage(org.forgerock.i18n.LocalizableMessage 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.
-
setUseAdminOrBindDn
public void setUseAdminOrBindDn(boolean useAdminOrBindDn)
Tells whether we can ask during interaction for both the DN and the admin UID or not. Default value isfalse.- 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 ArgumentExceptionForces 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.
-
initializeGlobalArguments
public void initializeGlobalArguments(String hostName, int port, String adminUid, DN bindDn, String bindPwd, LinkedHashMap<String,String> pwdFile)
Initializes the global arguments in the parser with the provided values. This is useful when we want to call LDAPConnectionConsoleInteraction.run() with some default values.- Parameters:
hostName- the host name.port- the port to connect to the server.adminUid- the administrator UID.bindDn- the bind DN to bind to the server.bindPwd- the password to bind.pwdFile- the Map containing the file and the password to bind.
-
resetConnectionArguments
public void resetConnectionArguments()
Resets the connection parameters for the LDAPConsoleInteraction object. The reset does not apply to the certificate parameters. This is called in order the LDAPConnectionConsoleInteraction object to ask for all this connection parameters next time we call LDAPConnectionConsoleInteraction.run().
-
getProvidedAdminUID
public 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 DN 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).
-
-