Package io.vertx.mutiny.ext.web.handler
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 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
original non Mutiny-ified interface using Vert.x codegen.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TypeArg<MultiTenantHandler>static final StringThe default key used to identify a tenant in the context data. -
Constructor Summary
ConstructorsConstructorDescriptionMultiTenantHandler(io.vertx.ext.web.handler.MultiTenantHandler delegate) MultiTenantHandler(Object delegate) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(RoutingContext item) addDefaultHandler(Consumer<RoutingContext> handler) addTenantHandler(String tenant, Consumer<RoutingContext> handler) static MultiTenantHandlerstatic MultiTenantHandlercreate(Function<RoutingContext, String> tenantExtractor) static MultiTenantHandlercreate(Function<RoutingContext, String> tenantExtractor, String contextKey) booleanio.vertx.ext.web.handler.MultiTenantHandlervoidhandle(RoutingContext arg0) inthashCode()static MultiTenantHandlernewInstance(io.vertx.ext.web.handler.MultiTenantHandler arg) removeTenant(String tenant) toString()
-
Field Details
-
__TYPE_ARG
-
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
-
-
Method Details
-
getDelegate
public io.vertx.ext.web.handler.MultiTenantHandler getDelegate()- Specified by:
getDelegatein interfaceMutinyDelegate- Returns:
- the delegate used by this Mutiny object of generated type
-
toString
-
equals
-
hashCode
public int hashCode() -
handle
- Specified by:
handlein interfaceio.vertx.core.Handler<RoutingContext>
-
create
- Parameters:
header- the header to lookup (e.g.: "X-Tenant")- Returns:
- the new handler.
-
create
- 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 requestcontextKey- the custom key to store the tenant id in the context- Returns:
- the new handler.
-
addTenantHandler
- Parameters:
tenant- the tenant idhandler- the handler to register.- Returns:
-
removeTenant
- Parameters:
tenant- the tenant id- Returns:
- a fluent reference to self.
-
addDefaultHandler
- Parameters:
handler- the handler to register.- Returns:
-
accept
- Specified by:
acceptin interfaceConsumer<RoutingContext>
-
newInstance
-