Skip to content

Multi-tenancy and basic auth#9

Open
ciegler wants to merge 1 commit into
authenticationfrom
multi-tenancy
Open

Multi-tenancy and basic auth#9
ciegler wants to merge 1 commit into
authenticationfrom
multi-tenancy

Conversation

@ciegler

@ciegler ciegler commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

This mini sample project uses the quarkus-multitenancy extension form
mathias82, which is in the process of becoming an official quarkiverse extension.

All parts that I directly copied (without adjusting) from the quarkus-multitenancy demo project are marked by a comment.

The quarkus-multitenancy extension provides a consistent tenant resolution in quarkus, e.g. via a HTTP-Header.
Hereby the extension lets us implement (if needed) our custom:

  • TenantContext
  • TenantResolver
  • TenantDataSourceRegistry
  • TenantResolutionContext
  • ...

The extension itself comes with a filter that resolves the tenant if there is no authorization needed and supports a database-per-tenant approach.

In order to resolve the tenant when making an authorization request it is needed to implement a custom
HTTPAuthenticationMechanism and to implement a custom TenantResolutionContext.

Implementing a custom HTTPAuthenticationMechanism is one of the intended ways when customizing Quarkus Security
(see docs).

The extensions build-in TenantResolutionContext expects an ContainerRequestContext, which is not available in the
authentication step. However, to resolve the Tenant via the TenantResolver we only need to extract a specific HTTP-Header,
which we can also get from the RoutingContext.

Testing

Run docker compose up -d to create the databases in the compose.yaml, then run mvn quarkus:dev.
HTTP Requests for testing are in the localhost.http, all passwords are password.

There will be an error message that the database schema for <default> is not correct. I will look into it again, but since it did not affect the project at all I decided to ignore it for now.

@ciegler ciegler mentioned this pull request Jun 15, 2026
4 tasks
@ciegler ciegler marked this pull request as draft June 25, 2026 13:45
@ciegler ciegler closed this Jun 25, 2026
@ciegler ciegler reopened this Jun 25, 2026
@ciegler ciegler changed the base branch from main to authentication June 25, 2026 13:46
@ciegler ciegler marked this pull request as ready for review June 25, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant