Class SecretHintBuilder

java.lang.Object
org.refcodes.textual.SecretHintBuilder
All Implemented Interfaces:
Text<SecretHintBuilder>, TextAccessor, TextAccessor.TextBuilder<Text<SecretHintBuilder>>, TextAccessor.TextMutator, TextAccessor.TextProperty, TextAccessor.TextProvider

public class SecretHintBuilder extends Object implements Text<SecretHintBuilder>
Dangerous builder for printing secret text such as passwords or pass-phrases or keys without unveiling too much of the secret information with still being able to say if the correct secret is being displayed. Useful in log-files, do not use any production log level! USE WITH CAUTION!
  • Constructor Details

    • SecretHintBuilder

      public SecretHintBuilder()
  • Method Details

    • setText

      public void setText(String... aText)
      Sets the text for the text property.
      Specified by:
      setText in interface TextAccessor.TextMutator
      Parameters:
      aText - The text to be stored by the text property.
    • toStrings

      public String[] toStrings()
      The Strings being build by the builder upon the settings of the attributes.
      Specified by:
      toStrings in interface TextAccessor.TextProvider
      Returns:
      The according resulting String array
    • toStrings

      public String[] toStrings(String... aText)
      Race condition safe shortcut for using Text.withText(String...) followed by TextAccessor.TextProvider.toStrings(). Implementation requirements: This method must not(!) be implemented by calling Text.withText(String...) followed by TextAccessor.TextProvider.toStrings() (do not change the text property) as this would not be thread safe!
      Specified by:
      toStrings in interface Text<SecretHintBuilder>
      Parameters:
      aText - The text to be processed.
      Returns:
      The according resulting String array
    • asString

      public static String asString(String aText)
      Convenience method for directly invoking Text.toString(String...) without leaving any state.
      Parameters:
      aText - The text to be obscured.
      Returns:
      The now obscured text.
    • asString

      public static String asString(String... aText)
      Convenience method for directly invoking Text.toString(String...) without leaving any state.
      Parameters:
      aText - The text to be obscured.
      Returns:
      The now obscured text.
    • asStrings

      public static String[] asStrings(String... aText)
      Convenience method for directly invoking Text.toString(String...) without leaving any state.
      Parameters:
      aText - array The text to be obscured.
      Returns:
      The now obscured text array.
    • toString

      protected static String toString(String aSecret)
      This method provides a password hint by keeping the first and the last characters of the password and exchanging the rest by an asterisk "*". In case the password length is smaller than 10 characters, then the complete password is replaced by asterisk "*" characters. ------------------------------------------------------------------------- CAUTION: This method must only be used when being in development environments and a password hint is required in debug log methods to see whether the correct password is being configured.
      Parameters:
      aSecret - The secret to be printed
      Returns:
      The printable secret
    • getText

      public String[] getText()
      Retrieves the text from the text property.
      Specified by:
      getText in interface TextAccessor
      Returns:
      The text stored by the text property.
    • withText

      public SecretHintBuilder withText(String... aText)
      With text.
      Specified by:
      withText in interface Text<B extends Text<B>>
      Specified by:
      withText in interface TextAccessor.TextBuilder<B extends Text<B>>
      Parameters:
      aText - the text
      Returns:
      the b
    • withText

      public SecretHintBuilder withText(Collection<String> aText)
      With text.
      Specified by:
      withText in interface TextAccessor.TextBuilder<B extends Text<B>>
      Parameters:
      aText - the text
      Returns:
      the b
    • toString

      public String toString()
      The String being build by the builder upon the settings of the attributes. In case more then one line has been set as input and the functionality of the builder is applied to each line in separate, then this method returns all of them lines concatenated with a line break between each of them (implementation depended).
      Specified by:
      toString in interface TextAccessor.TextProvider
      Overrides:
      toString in class Object
      Returns:
      The according resulting String
    • toString

      public String toString(String... aText)
      Race condition safe shortcut for using Text.withText(String...) followed by TextAccessor.TextProvider.toString(). Implementation requirements: This method must not(!) be implemented by calling Text.withText(String...) followed by TextAccessor.TextProvider.toString() (do not change the text property) as this would not be thread safe!
      Specified by:
      toString in interface Text<B extends Text<B>>
      Parameters:
      aText - The text to be processed.
      Returns:
      The according resulting String