Class MultiTenantHandler

java.lang.Object
io.vertx.mutiny.ext.web.handler.MultiTenantHandler
All Implemented Interfaces:
MutinyDelegate, io.vertx.core.Handler<RoutingContext>, Consumer<RoutingContext>

public class MultiTenantHandler extends Object implements io.vertx.core.Handler<RoutingContext>, Consumer<RoutingContext>, MutinyDelegate
A handler which selectively executes another handler if a precondition is met. There are cases where applications are build as multi tenant, in this cases one of the common tasks is to configure different authentication mechanisms for each tenant. This handler will allow registering any other handler and will only execute it if the precondition is met. There are 2 way of defining a precondition:
  • A http header value for example
    X-Tenant
  • A custom extractor function that can return a String from the context
Requests that pass the validation will contain a new key in the routing context with the tenant id, for the case of being a default handler the value if this key will be "default".

NOTE: This class has been automatically generated from the original non Mutiny-ified interface.

Author:
Paulo Lopes
See Also:
  • MultiTenantHandler
  • Field Details

  • Constructor Details

    • MultiTenantHandler

      public MultiTenantHandler(io.vertx.ext.web.handler.MultiTenantHandler delegate)
      Create a new instance of MultiTenantHandler delegating to the given (non-null) instance of MultiTenantHandler.
    • MultiTenantHandler

      public MultiTenantHandler(Object delegate)
  • Method Details

    • accept

      public void accept(RoutingContext item)
      Handle an item. This method is generated from the original method."
      Specified by:
      accept in interface Consumer<RoutingContext>
    • handle

      public void handle(RoutingContext item)
      Handle an item. This method is generated from the original method."
      Specified by:
      handle in interface io.vertx.core.Handler<RoutingContext>
    • getDelegate

      public io.vertx.ext.web.handler.MultiTenantHandler getDelegate()
      Get the delegate instance.

      This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.

      Specified by:
      getDelegate in interface MutinyDelegate
      Returns:
      the delegate instance
    • create

      public static MultiTenantHandler create(String header)
      Create a MultiTenant handler that will extract the tenant id from a given header name.
      Parameters:
      header - the header to lookup (e.g.: "X-Tenant")
      Returns:
      the new handler.
    • create

      public static MultiTenantHandler create(Function<RoutingContext,String> tenantExtractor)
      Create a MultiTenant handler using a custom tenant extraction function.
      Parameters:
      tenantExtractor - the function that extracts the tenant id from the request
      Returns:
      the new handler.
    • create

      public static MultiTenantHandler create(Function<RoutingContext,String> tenantExtractor, String contextKey)
      Create a MultiTenant handler using a custom tenant extraction function.
      Parameters:
      tenantExtractor - the function that extracts the tenant id from the request
      contextKey - the custom key to store the tenant id in the context
      Returns:
      the new handler.
    • addTenantHandler

      public MultiTenantHandler addTenantHandler(String tenant, Consumer<RoutingContext> handler)
      Add a handler for a given tenant to this handler. Both tenant and handler cannot be null.
      Parameters:
      tenant - the tenant id
      handler - the handler to register.
      Returns:
      a fluent reference to self.
      Throws:
      In - case a handler is already present for that tenant.
    • removeTenant

      public MultiTenantHandler removeTenant(String tenant)
      Remove a handler for a given tenant from this handler. Tenant cannot be null.
      Parameters:
      tenant - the tenant id
      Returns:
      a fluent reference to self.
    • addDefaultHandler

      public MultiTenantHandler addDefaultHandler(Consumer<RoutingContext> handler)
      Add a default handler for the case when no tenant was matched. The handler cannot be null.
      Parameters:
      handler - the handler to register.
      Returns:
      a fluent reference to self.
    • newInstance

      public static MultiTenantHandler newInstance(io.vertx.ext.web.handler.MultiTenantHandler delegate)
      Creates a new instance of the MultiTenantHandler.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object