Class 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 Detail

      • LDAPConnectionConsoleInteraction

        public LDAPConnectionConsoleInteraction​(ConsoleApplication app,
                                                SecureConnectionCliArgs secureArgs)
        Constructs a new console interaction.
        Parameters:
        app - console application
        secureArgs - 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 application
        secureArgs - existing set of arguments that have already been parsed and contain some potential command line specified LDAP arguments
        allowAnonymousIfNonInteractive - 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 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 canUseStartTLS)
                 throws ArgumentException
        Interact 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 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​(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:
        true if the user accepted the certificate and false otherwise.
      • 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 is false.
        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.
      • 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).