Class TokenManager


  • public class TokenManager
    extends Object
    This class is a singleton to manage ALL tokens. This TokenManager provides a simple method to consumer to get a token. It manages caches based on different cache strategies underneath.
    • Method Detail

      • getJwt

        public Result<Jwt> getJwt​(Jwt.Key key)
        get a Jwt with a provided Key (Key is either scope or a service id inputted by user, for caching usage): 1.if a token is cached with provided key - if the token is expired, renew it right away. - if the token is almost expired, use this token and renew it silently. - if the token is not almost expired, just use this token. 2.if a token is not cached with provided key - get a new jwt from oauth server 3.after getting the valid token, cache that token no matter if it's already cached or not. The strategy should determine how to cache it.
        Parameters:
        key - either based on scope or service id
        Returns:
        a Jwt if successful, otherwise return error Status.
      • getJwt

        public Result<Jwt> getJwt​(Set<String> scopeSet,
                                  String serviceId)
        get a Jwt with a provided clientRequest, it will get token based on Jwt.Key (either scope or service_id) if the user declared both scope and service_id in header, it will get jwt based on scope
        Parameters:
        scopeSet - scope set for cache
        serviceId - service id for cache
        Returns:
        Result