org.apache.hadoop.security.authentication.util

## Class AuthToken

- java.lang.Object
- - org.apache.hadoop.security.authentication.util.AuthToken

- All Implemented Interfaces:
    Principal
  Direct Known Subclasses:
    AuthenticationToken

      public class AuthToken
      extends Object
      implements Principal

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AuthToken()`
    `` | `AuthToken(String userName, String principal, String type)` Creates an authentication token.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected static void` | `checkForIllegalArgument(String value, String name)` Check if the provided value is invalid.
    `long` | `getExpires()` Returns the expiration time of the token.
    `long` | `getMaxInactives()` Returns the max inactive time of the token.
    `String` | `getName()` Returns the principal name (this method name comes from the JDK `Principal` interface).
    `String` | `getType()` Returns the authentication mechanism of the token.
    `String` | `getUserName()` Returns the user name.
    `boolean` | `isExpired()` Returns true if the token has expired.
    `static AuthToken` | `parse(String tokenStr)`
    `void` | `setExpires(long expires)` Sets the expiration of the token.
    `void` | `setMaxInactives(long interval)` Sets the max inactive interval of the token.
    `String` | `toString()` Returns the string representation of the token.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.security.Principal

      `equals, hashCode, implies`

- - ### Constructor Detail

    - #### AuthToken

          protected AuthToken()

    - #### AuthToken

          public AuthToken(String userName,
                           String principal,
                           String type)

      Creates an authentication token.
      Parameters:
        `userName` - user name.
        `principal` - principal (commonly matches the user name, with Kerberos is the full/long principal name while the userName is the short name).
        `type` - the authentication mechanism name. (`System.currentTimeMillis() + validityPeriod`).

  - ### Method Detail

    - #### checkForIllegalArgument

          protected static void checkForIllegalArgument(String value,
                                                        String name)

      Check if the provided value is invalid. Throw an error if it is invalid, NOP otherwise.
      Parameters:
        `value` - the value to check.
        `name` - the parameter name to use in an error message if the value is invalid.

    - #### setMaxInactives

          public void setMaxInactives(long interval)

      Sets the max inactive interval of the token.
      Parameters:
        `interval` - max inactive interval of the token in milliseconds since the epoch.

    - #### setExpires

          public void setExpires(long expires)

      Sets the expiration of the token.
      Parameters:
        `expires` - expiration time of the token in milliseconds since the epoch.

    - #### isExpired

          public boolean isExpired()

      Returns true if the token has expired.
      Returns:
        true if the token has expired.

    - #### getUserName

          public String getUserName()

      Returns the user name.
      Returns:
        the user name.

    - #### getName

          public String getName()

      Returns the principal name (this method name comes from the JDK `Principal` interface).
      Specified by:
        `getName` in interface `Principal`
      Returns:
        the principal name.

    - #### getType

          public String getType()

      Returns the authentication mechanism of the token.
      Returns:
        the authentication mechanism of the token.

    - #### getMaxInactives

          public long getMaxInactives()

      Returns the max inactive time of the token.
      Returns:
        the max inactive time of the token, in milliseconds since Epoc.

    - #### getExpires

          public long getExpires()

      Returns the expiration time of the token.
      Returns:
        the expiration time of the token, in milliseconds since Epoc.

    - #### toString

          public String toString()

      Returns the string representation of the token.

      This string representation is parseable by the `parse(java.lang.String)` method.

      Specified by:
        `toString` in interface `Principal`
      Overrides:
        `toString` in class `Object`
      Returns:
        the string representation of the token.

    - #### parse

          public static AuthToken parse(String tokenStr)
                                 throws AuthenticationException

      Throws:
        `AuthenticationException`

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.