Class TokenMiddleware

  • All Implemented Interfaces:
    LambdaHandler, MiddlewareHandler

    public class TokenMiddleware
    extends Object
    implements MiddlewareHandler
    This middleware is used to get the jwt token for the client credential grant type and put it into the Authorization header when the backend lambda function is invoking another service. The token is cached in the cache manager and it only retrieves a new one before the current one is expired. This is to support the east west security between the services in the light lambda native platform. The middleware will check if service_id header is in the request. Normally, this id should map to an ALB or API Gateway endpoint that is used to call another Lambda function or a service running in a container. When service_url is in the header, it is going to be used to invoke the downstream API, otherwise, the downstream URL will be discovered from the config.
    • Constructor Detail

      • TokenMiddleware

        public TokenMiddleware()
      • TokenMiddleware

        @Deprecated
        public TokenMiddleware​(com.networknt.router.middleware.TokenConfig cfg)
        Deprecated.
        This constructor should only be used for testing. Hence, it is marked as deprecated.
        Parameters:
        cfg - config
    • Method Detail

      • getJwtToken

        public static com.networknt.monad.Result<com.networknt.client.oauth.Jwt> getJwtToken​(String serviceId)
      • isContinueOnFailure

        public boolean isContinueOnFailure()
        Description copied from interface: MiddlewareHandler
        Indicate if this middleware handler will continue on failure or not.
        Specified by:
        isContinueOnFailure in interface MiddlewareHandler
        Returns:
        boolean true if continue on failure
      • isAudited

        public boolean isAudited()
        Description copied from interface: MiddlewareHandler
        Indicate if this middleware handler is audited or not.
        Specified by:
        isAudited in interface MiddlewareHandler
        Returns:
        boolean true if audited
      • isEnabled

        public boolean isEnabled()
        Description copied from interface: LambdaHandler
        Indicate if this handler is enabled or not.
        Specified by:
        isEnabled in interface LambdaHandler
        Returns:
        boolean true if enabled
      • register

        public void register()
        Description copied from interface: LambdaHandler
        Register this handler to the handler registration.
        Specified by:
        register in interface LambdaHandler
      • reload

        public void reload()
        Description copied from interface: LambdaHandler
        Reload config values in case the config values changed by config server.
        Specified by:
        reload in interface LambdaHandler
      • isAsynchronous

        public boolean isAsynchronous()
        Description copied from interface: LambdaHandler
        Indicate if this middleware handler is asynchronous or not.
        Specified by:
        isAsynchronous in interface LambdaHandler
        Returns:
        boolean true if asynchronous