Class MultiTenantHandler

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

public class MultiTenantHandler extends Object implements io.smallrye.mutiny.vertx.MutinyDelegate, io.vertx.core.Handler<RoutingContext>, Consumer<RoutingContext>
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 using Vert.x codegen.

  • Field Details

    • __TYPE_ARG

      public static final io.smallrye.mutiny.vertx.TypeArg<MultiTenantHandler> __TYPE_ARG
    • TENANT

      public static final String TENANT
      The default key used to identify a tenant in the context data.
      See Also:
  • Constructor Details

    • MultiTenantHandler

      public MultiTenantHandler(io.vertx.ext.web.handler.MultiTenantHandler delegate)
    • MultiTenantHandler

      public MultiTenantHandler(Object delegate)
  • Method Details

    • getDelegate

      public io.vertx.ext.web.handler.MultiTenantHandler getDelegate()
      Specified by:
      getDelegate in interface io.smallrye.mutiny.vertx.MutinyDelegate
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

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

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

      public void handle(RoutingContext arg0)
      Specified by:
      handle in interface io.vertx.core.Handler<RoutingContext>
    • create

      public static MultiTenantHandler create(String header)
      Parameters:
      header - the header to lookup (e.g.: "X-Tenant")
      Returns:
      the new handler.
    • create

      public static MultiTenantHandler create(Function<RoutingContext,String> tenantExtractor)
      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)
      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)
      Parameters:
      tenant - the tenant id
      handler - the handler to register.
      Returns:
    • removeTenant

      public MultiTenantHandler removeTenant(String tenant)
      Parameters:
      tenant - the tenant id
      Returns:
      a fluent reference to self.
    • addDefaultHandler

      public MultiTenantHandler addDefaultHandler(Consumer<RoutingContext> handler)
      Parameters:
      handler - the handler to register.
      Returns:
    • accept

      public void accept(RoutingContext item)
      Specified by:
      accept in interface Consumer<RoutingContext>
    • newInstance

      public static MultiTenantHandler newInstance(io.vertx.ext.web.handler.MultiTenantHandler arg)