Package io.vertx.ext.web.handler
Interface MultiTenantHandler
-
- All Superinterfaces:
Handler<RoutingContext>
public interface MultiTenantHandler extends Handler<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
- Author:
- Paulo Lopes
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description MultiTenantHandler
addDefaultHandler(Handler<RoutingContext> handler)
Add a default handler for the case when no tenant was matched.MultiTenantHandler
addTenantHandler(String tenant, Handler<RoutingContext> handler)
Add a handler for a given tenant to this handler.static MultiTenantHandler
create(String header)
Create a MultiTenant handler that will extract the tenant id from a given header name.static MultiTenantHandler
create(java.util.function.Function<RoutingContext,String> tenantExtractor)
Create a MultiTenant handler using a custom tenant extraction function.static MultiTenantHandler
create(java.util.function.Function<RoutingContext,String> tenantExtractor, String contextKey)
Create a MultiTenant handler using a custom tenant extraction function.MultiTenantHandler
removeTenant(String tenant)
Remove a handler for a given tenant from this handler.
-
-
-
Field Detail
-
TENANT
static final String TENANT
The default key used to identify a tenant in the context data.- See Also:
- Constant Field Values
-
-
Method Detail
-
create
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
static MultiTenantHandler create(java.util.function.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
static MultiTenantHandler create(java.util.function.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 requestcontextKey
- the custom key to store the tenant id in the context- Returns:
- the new handler.
-
addTenantHandler
MultiTenantHandler addTenantHandler(String tenant, Handler<RoutingContext> handler)
Add a handler for a given tenant to this handler. Both tenant and handler cannot be null.- Parameters:
tenant
- the tenant idhandler
- the handler to register.- Returns:
- a fluent reference to self.
- Throws:
IllegalStateException
- In case a handler is already present for that tenant.
-
removeTenant
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
MultiTenantHandler addDefaultHandler(Handler<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.
-
-