Class OathTokenCode


  • public class OathTokenCode
    extends java.lang.Object
    Represents a currently active OTP token.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected OathTokenCode​(TimeKeeper timeKeeper, java.lang.String code, long start, long until, OathMechanism.TokenType tokenType)
      Creates a OathTokenCode wrap with given data
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getCurrentCode()
      Gets the code which is currently active.
      OathMechanism.TokenType getOathType()
      Returns the token type (HOTP, TOTP)
      int getProgress()
      Get the current percent progress of the code for TOTPMechanism.
      long getStart()
      Get the started timestamp of current Oath token.
      long getUntil()
      Get the expiration timestamp for TOTP tokens.
      boolean isValid()
      Indicates whether the current OathTokenCode is valid or not.
      java.lang.String toJson()
      Creates a JSON string representation of OathTokenCode object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OathTokenCode

        protected OathTokenCode​(TimeKeeper timeKeeper,
                                java.lang.String code,
                                long start,
                                long until,
                                OathMechanism.TokenType tokenType)
        Creates a OathTokenCode wrap with given data
        Parameters:
        timeKeeper - class containing timekeeping functionality
        code - OTP code with 6 or 8 digits
        start - start timestamp for current Oath code
        until - expiration timestamp for current Oath code
    • Method Detail

      • getCurrentCode

        public java.lang.String getCurrentCode()
        Gets the code which is currently active.
        Returns:
        The currently active token.
      • getStart

        public long getStart()
        Get the started timestamp of current Oath token.
        Returns:
        The start time in milliseconds.
      • getUntil

        public long getUntil()
        Get the expiration timestamp for TOTP tokens. For HOTP, it returns 0 as it does not expires.
        Returns:
        The expiration time in milliseconds.
      • isValid

        public boolean isValid()
        Indicates whether the current OathTokenCode is valid or not. For HOTP, isValid always returns 'true'. For TOTP, this property computes, start and end timestamp of OathTokenCode and determines its validity.
        Returns:
        true if the OathTokenCode is still valid, false otherwise.
      • getOathType

        public OathMechanism.TokenType getOathType()
        Returns the token type (HOTP, TOTP)
        Returns:
        The token type.
      • getProgress

        public int getProgress()
        Get the current percent progress of the code for TOTPMechanism. This is a number between 0 and 1000, and represents the amount of time that has passed between the start and end times of the code. For HOTPMechanism, progress always returns 0.
        Returns:
        The percentage progress, a number between 0 and 1000.
      • toJson

        public java.lang.String toJson()
        Creates a JSON string representation of OathTokenCode object.
        Returns:
        a JSON string object