Spring data mongo Multi tenant support - rest

I have a requirement to enable multi tenant support for a spring boot application, it uses mongodb ,requirement is to use separate database based on tenant login.
Each request of REST service call will have the tenant information in header.Based on the tenant retrieved from service request, application should connect to corresponding database.

Related

Azure AD Service Principal authentication to SQL DB Using Entity frame work code first approach

we have existing Web API application with EF-code first approach and completed the code using linq queries and its working fine.
Now we got new requirement we have to use Azure AD service principal authentication to SQL DB and received below setting from client.
with reference of below article am successfully establish the connection but am not getting any articles for how can we use dbcontext class for authentication and connection to DB.
Azure AD Service Principal authentication to SQL DB Using Entity frame work code first approach

Keycloak server embedded in a Spring Boot application with custom User Storage SPI

I have managed to set up a Keycloak server embedded in a Spring Boot Application successfully, following this tutorial:
Keycloak Embedded in a Spring Boot Application
in order to avoid setting it up manually.
Since I am dealing with an old implementation that already has it's own DB, I decided to use Keycloak's User Storage SPI to connect to an external postgresql DB and use this for authentication instead of Keycloak DB.
To do this, I followed the tutorial on Keycloak documentation, but it envolves a standalone Keycloak server, creating a .jar with the custom provider and injecting it to <pathToKeycloak>/standalone/deployments/.
I have created an implementation that works with a standalone Keycloak server, but now I want to include it to the embedded one. Is it possible to use a Keycloak server Embedded in a Spring Boot Application and also have an embedded custom User Storage Provider, to avoid setting up manually?
If you have already implemented the provider and the provider factory, you only need to declare the provider factory class in the resources/META-INF/services/org.keycloak.storage.UserStorageProviderFactory file.
Then you can log in to the administration console and enable user storage provider on the User Federation page.

Implementing schema based multi tenancy in springboot application that is secured using keycloak

I have a springboot application linked to a postgresql database. The app is secured using keycloak (keycloak springboot adapter). The idea is to have multiple schemas in the postgres database for different groups of users that login. I hope to identify the user-group using the keycloak token that is received by rest endpoints on the springboot server and then access the respective schema.
Where should I start ? Can anyone point me to a guide for this ? or is there any other better approach ? Any help would be appreciated.
edit ::
Let me try narrowing it down a bit. Lets say the db has the schemas : public, tenant1, tenant2, tenant3. In the keycloak server, I have two clients in the same realm, one for spring boot app and one for my website. I have 3 groups. group 1 has users A and B, group 2 has users C and D, group 3 has users E and F. If the user A logs into the website, he has a keycloak token that is going to help him get the data through ajax requests from the springboot server. I assume that, the incoming ajax request could provide the kc token which would tell spring boot that user A is requesting the data and he belongs to group 1. Here, I want the spring boot server to figure out that the data has to be fetched from the schema "tenant1" and do accordingly. Similarly, group 2 should be directed to tenant2 and group 3 to tenant 3. I want support on the part where the spring boot has to figure out the user and the group and access the right schema..
Cheers,
Vikram

Hapijs SaaS multi Tenant Referene Example

I am trying to build a multi tenant SaaS application with HapiJS and MongoDB. I would like to achieve the following:
Each tenant has a unique URL
I would determine a tenant from the URL
Same code base for all tenants launched with different configuration, and each tenant runs on different node process
Each tenant has separate database
Is there a reference example/application I can use for direction?

How to get spring security oauth2 client details from mongodb instead of inmemory

I am current using spring security oauth2 and configured the oauth2 as using the clients from inMemory, how to get the client id/client secret from mongodb and use mongodb as the store for the client details and how to configure spring oauth2 using that.
One approach I was thinking was to use mongo template to read the client details and configure the inMemory client details using those values. Will this be a way to go about this?
Is there another way to get client details from mongodb and configure the clients for spring security oauth2?
Try
this link. You will have to create custom client details storage along with custom access and refresh token implementation.