Interface MaskingCallback

  • All Known Implementing Classes:
    SimpleMaskingCallback

    public interface MaskingCallback
    Callback used to mask parts of the line for sensitive input like passwords.

    The MaskingCallback interface provides methods to transform the input line both for display purposes and for history storage. This allows applications to implement custom masking strategies for sensitive information, such as passwords, API keys, or other confidential data.

    When a MaskingCallback is provided to the LineReader, it will be used to:

    • Transform the line before displaying it to the user (e.g., replacing password characters with asterisks)
    • Transform the line before storing it in the history (e.g., removing sensitive information)

    A simple implementation is provided in SimpleMaskingCallback, which replaces all characters with a single mask character.

    See Also:
    SimpleMaskingCallback, LineReader.readLine(String, String, MaskingCallback, String)
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String display​(java.lang.String line)
      Transforms the line before it is displayed so that sensitive parts can be hidden.
      java.lang.String history​(java.lang.String line)
      Transforms the line before storing it in the history.
    • Method Detail

      • display

        java.lang.String display​(java.lang.String line)
        Transforms the line before it is displayed so that sensitive parts can be hidden.

        This method is called by the LineReader whenever the display needs to be updated. It allows the implementation to replace sensitive information with mask characters or other visual indicators while preserving the actual input for processing.

        For example, a password masking implementation might replace each character with an asterisk (*) or hide the input entirely.

        Parameters:
        line - the current line being edited (contains the actual input)
        Returns:
        the modified line to display (with sensitive parts masked)
      • history

        java.lang.String history​(java.lang.String line)
        Transforms the line before storing it in the history.

        This method is called by the LineReader when a line is about to be added to the command history. It allows the implementation to remove or redact sensitive information before it is persisted.

        If the return value is empty or null, the line will not be saved in the history at all, which is often appropriate for commands containing passwords or other sensitive data.

        For example, a command like "login --password=secret" might be transformed to "login --password=****" or simply "login" before being stored in history.

        Parameters:
        line - the line to be added to history (contains the actual input)
        Returns:
        the modified line for history storage, or null/empty to prevent history storage