-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JPA security : allow @UserDefinition to work with multitenant datasource #16700
Comments
/cc @sberyozkin |
Yeah, this is not supported ATM, IIRC we're loading the entity via the default session, and we should actually set the right PU in I'm not sure I'll have time to work on this soon, though, so if you're game for providing a PR, that could be faster :) |
I forked to attempt a PR, but my knowledge of the code is still quite limited and it's a bit hard for me atm to get the "big picture", as in #12400 I understand Quarkus is a big project too, documentation exists, but its internals has a steep learning curve, for me at least. So at best I can only provide ideas atm, for example maybe quarkus.hibernate-orm.multitenant should be quarkus.hibernate-orm."dataSourceName".multitenant ? The thing is that the lookup does not seem trivial, but again, I'm not that familiar with the codebase. Since |
Oh right, this is not just about specifying a data source, but also resolving the tenant. Yeah, this won't be trivial :( |
What do you use ATM to resolve the tenant for the normal requests? |
We're in a fortunate scenario where all of our calls are HTTP so we're using a custom implementation of a We found an alternative to authenticate without a JPA Maybe the resolved tenant could be captured with a vertx ThreadContext (https://quarkus.io/guides/context-propagation#usage-example-for-completionstage) to propagate it to a JPA identity resolver in the same context. |
@laurentperez we're having the same issue. Can you provide more details on your workaround? |
well we dropped JPA (for tenant datasource resolution). also because our tenants are not known at build time, ours are dynamic ones. I guess once you manage to resolve your tenant, context propagation or maybe EventBus should work to let other parts of your codebase know the tenant |
@jonjanisch I can probably help, if you can give me a minimal reproducer. |
@FroMage thanks I've created a minimal Quarkus app here: https://github.com/jonjanisch/multitenant It requires a MySQL database with two simple tables for the user and role (see README.md). You can likely use any datasource type. I inserted a user "admin" with password "password" (quarkus uses bcrypt with 10 rounds by default):
This is the default Quarkus hello world GET endpoint: This is a simple API endpoint that returns a list of userIds: The path
Attempting to access the above resource will redirect you to login.html. Typing "admin" and "password" and hitting "Sign In" will throw the error:
If you go into application.properties and comment out the auth config the multi-tenancy works fine and the above endpoint will display the users for the given tenant.
|
I wrote couple of tests on top of current main, basically this task is about optional activating request scope (or doing more things manually inside Security JPA, which I think is unnecessary). I think we can just detect when user defined |
Correction: I was testing it with RESTEasy Classic and proactive auth and works when I active request context, the issue was when I requested |
Description
Hi, posting as enhancement but this may be a bug or missing feature.
We're are using quarkus.hibernate-orm.multitenant=DATABASE. Our custom TenantResolver or TenantConnectionResolver implementations work fine, in a @RequestScoped resolving tenant
However, we're facing a problem with JPA, https://quarkus.io/guides/security-jpa . A
io.quarkus.security.jpa.UserDefinition
is needed to trigger theio.quarkus.security.jpa.runtime.JpaIdentityProvider
The problem is that it will fail with the following at startup, because TenantConnectionResolver will not be bound. So the @UserDefinition does not understand how to get the tenant.
Is there a technique to set the tenant in the use case of a secured JPA @UserDefinition ?
Implementation ideas
To reproduce the exception, set quarkus.hibernate-orm.multitenant=DATABASE and annotate a single entity with @UserDefinition as per https://quarkus.io/guides/security-jpa
The text was updated successfully, but these errors were encountered: