## org.apache.hadoop.security.authentication.server
Class AuthenticationToken

    java.lang.Object
      org.apache.hadoop.security.authentication.server.AuthenticationToken

All Implemented Interfaces:
  Principal

    public class AuthenticationToken

extends Object
implements Principal

The `AuthenticationToken` contains information about an authenticated HTTP client and doubles as the `Principal` to be returned by authenticated `HttpServletRequest`s

The token can be serialized/deserialized to and from a string as it is sent and received in HTTP client responses and requests as a HTTP cookie (this is done by the `AuthenticationFilter`).

Field Summary
`static AuthenticationToken` `ANONYMOUS` Constant that identifies an anonymous request.

Constructor Summary
`AuthenticationToken(String userName, String principal, String type)` Creates an authentication token.

Method Summary
`long` `getExpires()` Returns the expiration 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 if the token has expired.
`static AuthenticationToken` `parse(String tokenStr)` Parses a string into an authentication token.
`void` `setExpires(long expires)` Sets the expiration 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`

Field Detail

### ANONYMOUS

    public static final AuthenticationToken ANONYMOUS

  Constant that identifies an anonymous request.

Constructor Detail

### AuthenticationToken

    public AuthenticationToken(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

### setExpires

    public void setExpires(long expires)

  Sets the expiration of the token.

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

### 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.

### getExpires

    public long getExpires()

  Returns the expiration time of the token.

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

### isExpired

    public boolean isExpired()

  Returns if the token has expired.

  Returns:
    if the token has expired.

### 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 AuthenticationToken parse(String tokenStr)
                                     throws AuthenticationException

  Parses a string into an authentication token.

  Parameters:
    `tokenStr` - string representation of a token.
  Returns:
    the parsed authentication token.
  Throws:
    `AuthenticationException` - thrown if the string representation could not be parsed into an authentication token.

Copyright © 2009 The Apache Software Foundation