Class LinkTokenUsername

java.lang.Object
com.irurueta.authserver.authorization.api.web.ott.LinkTokenUsername

public final class LinkTokenUsername extends Object
The user name a magic link token is stored with. Spring's token store only keeps a user name next to the token, so the purpose of a link travels in it: the token of a link requested as a second factor starts with a control character that no identifier can carry (identifiers are stripped of control characters before they are used), and OttLinkAuthenticationProvider accepts it only in the session of the signed-in user it was requested for. The column holds 100 characters, so an identifier is cut to what fits; a second-factor link of a user name longer than 99 characters would be cut and never match its user, so OttGenerationSuccessHandler does not deliver it (fitsSecondFactorLink(String)).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Characters the user name column of the token store holds.
    static final int
    Characters a user name may have to fit the column next to the marker of a second-factor link.
    (package private) static final char
    Marker of the token of a link requested as a second factor.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Utility class: not meant to be instantiated.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    clean(String identifier)
    Cleans an identifier typed in a form: no control characters, no surrounding blanks, and no more characters than the column holds.
    static boolean
    Tells whether a user name fits the column next to the marker of a second-factor link, so that the stored name of the link still identifies the user.
    static String
    forLink(String identifier, boolean secondFactor)
    Builds the stored user name of a link.
    static String
    Gets the identifier of a stored user name.
    static boolean
    Tells whether a stored user name is the one of a link requested as a second factor.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_LENGTH

      public static final int MAX_LENGTH
      Characters the user name column of the token store holds.
      See Also:
    • MAX_SECOND_FACTOR_LENGTH

      public static final int MAX_SECOND_FACTOR_LENGTH
      Characters a user name may have to fit the column next to the marker of a second-factor link.
      See Also:
    • SECOND_FACTOR_MARKER

      static final char SECOND_FACTOR_MARKER
      Marker of the token of a link requested as a second factor.
      See Also:
  • Constructor Details

    • LinkTokenUsername

      private LinkTokenUsername()
      Utility class: not meant to be instantiated.
  • Method Details

    • clean

      public static String clean(String identifier)
      Cleans an identifier typed in a form: no control characters, no surrounding blanks, and no more characters than the column holds.
      Parameters:
      identifier - the identifier, or null.
      Returns:
      the identifier ready to be stored; the empty text when nothing is left of it.
    • forLink

      public static String forLink(String identifier, boolean secondFactor)
      Builds the stored user name of a link.
      Parameters:
      identifier - the cleaned identifier.
      secondFactor - whether the link is requested as a second factor.
      Returns:
      the identifier, preceded by the marker for a second factor and cut to the column's size.
    • fitsSecondFactorLink

      public static boolean fitsSecondFactorLink(String username)
      Tells whether a user name fits the column next to the marker of a second-factor link, so that the stored name of the link still identifies the user.
      Parameters:
      username - the name of the signed-in user.
      Returns:
      true when it has at most 99 characters.
    • isSecondFactor

      public static boolean isSecondFactor(String stored)
      Tells whether a stored user name is the one of a link requested as a second factor.
      Parameters:
      stored - the stored user name.
      Returns:
      true when it carries the marker.
    • identifierOf

      public static String identifierOf(String stored)
      Gets the identifier of a stored user name.
      Parameters:
      stored - the stored user name.
      Returns:
      the identifier, without the marker.