Class TenantFilter
java.lang.Object
com.codename1.backend.tenancy.TenantFilter
- All Implemented Interfaces:
SecurityFilter
Sets TenantContext for the length of each request and clears it after,
whatever the handler does.
A request that names no tenant passes through with none set, so a
tenant-partitioned entity touched while serving it fails with
MissingTenantException; construct the filter with required true to
answer 400 at the door instead. A malformed identifier is always a 400.
Trust: a header is whatever the client sent. Resolve the tenant from something the server vouches for -- the authenticated principal, a host name the proxy routes -- unless a gateway in front strips and sets the header.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceMaps an authenticated principal to its tenant, forauthenticated(TenantFilter.PrincipalTenant). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TenantResolverA resolver askingrulefor the tenant of the authenticated principal.doFilter(HttpServer.Request request, FilterChain chain) The answer torequest; null when nothing under the chain routes it, which the server answers 404.static TenantResolverA resolver reading a header, conventionallyX-Tenant-ID.static TenantResolverA resolver taking the first label of theHostheader belowdomain:acme.example.comunderexample.comis tenantacme.
-
Constructor Details
-
TenantFilter
- Parameters:
resolver- how the tenant is foundrequired- whether a request without a tenant is refused
-
-
Method Details
-
header
A resolver reading a header, conventionallyX-Tenant-ID.- Parameters:
name- the header name- Returns:
- the resolver
-
subdomain
A resolver taking the first label of theHostheader belowdomain:acme.example.comunderexample.comis tenantacme.- Parameters:
domain- the shared parent domain- Returns:
- the resolver
-
authenticated
A resolver askingrulefor the tenant of the authenticated principal. Install the filter after authentication, so the principal is set; a request that is not authenticated resolves no tenant.- Parameters:
rule- how a principal maps to its tenant, such as a claim lookup- Returns:
- the resolver
-
doFilter
Description copied from interface:SecurityFilterThe answer torequest; null when nothing under the chain routes it, which the server answers 404.- Specified by:
doFilterin interfaceSecurityFilter- Throws:
Exception
-