Class AuthToken


  • public class AuthToken
    extends java.lang.Object
    Authentication Token generator
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static AuthToken NULL_AUTH_TOKEN
      A null AuthToken, which can be passed to a method to override global settings.
    • Constructor Summary

      Constructors 
      Constructor Description
      AuthToken()  
      AuthToken​(java.lang.String key)  
      AuthToken​(java.util.Map options)
      Create a new AuthToken configuration.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AuthToken acl​(java.lang.String acl)
      Define an ACL for a cookie token
      java.util.Map<java.lang.String,​java.lang.Object> asMap()  
      AuthToken copy()
      Create a copy of this AuthToken
      AuthToken duration​(long duration)
      The duration of the token in seconds.
      boolean equals​(java.lang.Object o)  
      AuthToken expiration​(long expiration)
      Set the end time (expiration) of the token
      java.lang.String generate()
      Generate the authentication token
      java.lang.String generate​(java.lang.String url)
      Generate a URL token for the given URL.
      int hashCode()  
      AuthToken ip​(java.lang.String ip)
      Set the ip of the client
      AuthToken merge​(AuthToken other)
      Merge this token with another, creating a new token.
      AuthToken startTime​(long startTime)
      Set the start time of the token.
      AuthToken tokenName​(java.lang.String tokenName)
      Create a new AuthToken configuration overriding the default token name.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NULL_AUTH_TOKEN

        public static final AuthToken NULL_AUTH_TOKEN
        A null AuthToken, which can be passed to a method to override global settings.
    • Constructor Detail

      • AuthToken

        public AuthToken()
      • AuthToken

        public AuthToken​(java.lang.String key)
      • AuthToken

        public AuthToken​(java.util.Map options)
        Create a new AuthToken configuration.
        Parameters:
        options - The following keys may be used in the options: key, startTime, expiration, ip, acl, duration.
    • Method Detail

      • asMap

        public java.util.Map<java.lang.String,​java.lang.Object> asMap()
      • tokenName

        public AuthToken tokenName​(java.lang.String tokenName)
        Create a new AuthToken configuration overriding the default token name.
        Parameters:
        tokenName - the name of the token. must be supported by the server.
        Returns:
        this
      • startTime

        public AuthToken startTime​(long startTime)
        Set the start time of the token. Defaults to now.
        Parameters:
        startTime - in seconds since epoch
        Returns:
        this
      • expiration

        public AuthToken expiration​(long expiration)
        Set the end time (expiration) of the token
        Parameters:
        expiration - in seconds since epoch
        Returns:
        this
      • ip

        public AuthToken ip​(java.lang.String ip)
        Set the ip of the client
        Parameters:
        ip -
        Returns:
        this
      • acl

        public AuthToken acl​(java.lang.String acl)
        Define an ACL for a cookie token
        Parameters:
        acl -
        Returns:
        this
      • duration

        public AuthToken duration​(long duration)
        The duration of the token in seconds. This value is used to calculate the expiration of the token. It is ignored if expiration is provided.
        Parameters:
        duration - in seconds
        Returns:
        this
      • generate

        public java.lang.String generate()
        Generate the authentication token
        Returns:
        a signed token
      • generate

        public java.lang.String generate​(java.lang.String url)
        Generate a URL token for the given URL.
        Parameters:
        url - the URL to be authorized
        Returns:
        a URL token
      • copy

        public AuthToken copy()
        Create a copy of this AuthToken
        Returns:
        a new AuthToken object
      • merge

        public AuthToken merge​(AuthToken other)
        Merge this token with another, creating a new token. Other's members who are not null or 0 will override this object's members.
        Parameters:
        other - the token to merge from
        Returns:
        a new token
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object