Class AuthenticationTokenManager

    • Method Detail

      • generateToken

        public String generateToken​(long duration,
                                    String type,
                                    String comment)
                             throws RuntimeException
        Generates a new token for the current user
        Parameters:
        duration - The time the token is valid in seconds. 0 means for ever and moreover the ticket will be reusable.
        type - The type of token. Mandatory but can be anything you want between 1 to 32 characters. Such as "Cookie".
        comment - An optional token comment to remember the reason of its creation
        Returns:
        The token
        Throws:
        RuntimeException - If the user is not authenticated, or if there is a database error
      • generateToken

        public String generateToken​(UserIdentity user,
                                    long duration,
                                    String type,
                                    String comment)
                             throws RuntimeException
        Generates a new token
        Parameters:
        user - The user that will be authenticated with the token
        duration - The time the token is valid in seconds. 0 means for ever and moreover the ticket will be reusable
        type - The type of token. Mandatory but can be anything you want between 1 to 32 characters. Such as "Cookie".
        comment - An optional token comment to remember the reason of its creation
        Returns:
        The token
        Throws:
        RuntimeException - If the user is null or if there is a database error or if duration is negative
      • generateToken

        public String generateToken​(UserIdentity user,
                                    long duration,
                                    Integer nbUsesLeft,
                                    String type,
                                    String comment)
                             throws RuntimeException
        Generates a new token
        Parameters:
        user - The user that will be authenticated with the token
        duration - The time the token is valid in seconds. 0 means for ever and moreover the ticket will be reusable
        nbUsesLeft - number of available uses (null for no limit)
        type - The type of token. Mandatory but can be anything you want between 1 to 32 characters. Such as "Cookie".
        comment - An optional token comment to remember the reason of its creation
        Returns:
        The token
        Throws:
        RuntimeException - If the user is null or if there is a database error or if duration is negative
      • generateToken

        public String generateToken​(UserIdentity user,
                                    long duration,
                                    boolean autoRenewDuration,
                                    Integer nbUsesLeft,
                                    Set<String> contexts,
                                    String type,
                                    String comment)
                             throws RuntimeException
        Generates a new token
        Parameters:
        user - The user that will be authenticated with the token
        duration - The time the token is valid in seconds. 0 means for ever and moreover the ticket will be reusable
        autoRenewDuration - true to automatically renew token if used before it's expiration
        nbUsesLeft - number of available uses (null for no limit)
        contexts - contexts where the token can be used
        type - The type of token. Mandatory but can be anything you want between 1 to 32 characters. Such as "Cookie".
        comment - An optional token comment to remember the reason of its creation
        Returns:
        The token
        Throws:
        RuntimeException - If the user is null or if there is a database error or if duration is negative
      • validateToken

        public UserIdentity validateToken​(String token)
        Check if a token is valid and return the user
        Parameters:
        token - The token to validate
        Returns:
        The user associated to the valid token, null otherwise
      • validateToken

        public UserIdentity validateToken​(String token,
                                          String context)
        Check if a token is valid and return the user
        Parameters:
        token - The token to validate
        context - context to validate the token with
        Returns:
        The user associated to the valid token, null otherwise
      • deleteTokenByValue

        public void deleteTokenByValue​(String token,
                                       String context)
        Destroy the given token
        Parameters:
        token - The token to remove
        context - context of the token (null for no context)
      • deleteTokenById

        public void deleteTokenById​(Integer tokenId)
        Destroy the given token
        Parameters:
        tokenId - The token identifier to remove
      • generateAuthenticationToken

        public String generateAuthenticationToken​(Map<String,​Object> parameters)
        Generate a new authentication token
        Parameters:
        parameters - a map of the following parameters for the authentication token : description
        Returns:
        The generated token
      • deleteAuthenticationToken

        public void deleteAuthenticationToken​(List<Integer> ids)
        Delete one or multiples authentication token
        Parameters:
        ids - a list of authentication token ids