Code Monkey home page Code Monkey logo

quarkus-dynamic-multi-tenant's Introduction

Quarkus multi tenant

In this example, we build a very simple quarkus application:

Requirements

To compile and run this demo you will need:

  • JDK 1.8+
  • GraalVM
  • NodeJS

Make sure you have this ports available

  • 80
  • 8080
  • 8180
  • 5432

Setup environment

  • Adding a host name in the /etc/hosts file
sudo gedit /etc/hosts

#paste this hostnames#
127.0.0.1       tenant1.maxilog.io
127.0.0.1       tenant2.maxilog.io
127.0.0.1       tenant3.maxilog.io
  • To start a Keycloak Server,Nginx, Postgres you can use Docker and just run the following command:
docker-compose -f src/main/docker/docker-compose.yaml up -d

You should be able to access your Keycloak Server at http://localhost:8180/auth .

Log in as admin to access the Keycloak Administration Console. Username should be admin and password admin.

For more details, see the Keycloak documentation about how to https://www.keycloak.org/docs/latest/server_admin/index.html#_create-realm[create a new realm].

Initialized Tenant

keycloak realms:
  • default:
    • Clients :
      • front
      • back | back (backend)
    • Users :
      • admin | admin
      • user | user
  • tenant1:
    • Clients :
      • front
      • back | back (backend)
    • Users :
      • admin | admin
      • user | user
  • tenant2:
    • Clients :
      • front
      • back | back (backend)
    • Users :
      • admin | admin
      • user | user
Databases:
  • default:
    • maxilog-default:
      • maxilog-default-user | maxilog-default-password
  • tenant1:
    • maxilog-tenant1:
      • maxilog-tenant1-user | maxilog-tenant1-password
  • tenant2:
    • maxilog-tenant2:
      • maxilog-tenant2-user | maxilog-tenant2-password

Get an access token

Change REALM, USERNAME and PASSWORD by the information of the realm you want to connect :

export access_token=$(\
    curl -X POST http://localhost:8180/auth/realms/REALM/protocol/openid-connect/token \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'username=USERNAME' \
    --data-urlencode 'password=PASSWORD' \
    --data-urlencode 'client_id=front' \
    --data-urlencode 'grant_type=password' | jq --raw-output '.access_token' \
 )

Example :

export access_token=$(\
    curl -X POST http://localhost:8180/auth/realms/tenant1/protocol/openid-connect/token \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'username=admin' \
    --data-urlencode 'password=admin' \
    --data-urlencode 'client_id=front' \
    --data-urlencode 'grant_type=password' | jq --raw-output '.access_token' \
 )

Get your task list

If you get the token from tenant1 realm :

curl -X GET -v http://localhost:8080/api/tasks/me \
--header  "x-tenant: tenant1" \
--header  "Authorization: Bearer $access_token"

Create new Tenant

To create new tenant you have to use default tenant.

Let's create tenant named tenant3

export access_token=$(\
    curl -X POST http://localhost:8180/auth/realms/default/protocol/openid-connect/token \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'username=admin' \
    --data-urlencode 'password=admin' \
    --data-urlencode 'client_id=front' \
    --data-urlencode 'grant_type=password' | jq --raw-output '.access_token' \
 )
 
curl -X POST -v http://localhost:8080/api/tenants/tenant3 \
--header  "x-tenant: default" \
--header  "Authorization: Bearer $access_token"

This command will create realm tenant3 and database maxilog-tenant3.

PS: In this case, you have to add hostname to /etc/hosts :

127.0.0.1 tenant3.maxilog.io

Backend(quarkus)

./mvnw compile quarkus:dev

This command will leave Quarkus running in the foreground listening on port 8080.

Frontend(angular)

cd src/main/webapp/
npm install
npm start

You should be able to access your angular app at http://tenant1.maxilog.io or http://tenant2.maxilog.io.

test

quarkus-dynamic-multi-tenant's People

Contributors

mossabtn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

quarkus-dynamic-multi-tenant's Issues

同学,您这个项目引入了158个开源组件,存在26个漏洞,辛苦升级一下

检测到 MossabTN/quarkus-dynamic-multi-tenant 一共引入了158个开源组件,存在26个漏洞

漏洞标题:netty 安全漏洞
缺陷组件:io.netty:[email protected]
漏洞编号:CVE-2021-37136
漏洞描述:Netty是Netty社区的一款非阻塞I/O客户端-服务器框架,它主要用于开发Java网络应用程序,如协议服务器和客户端等。
netty存在安全漏洞,该漏洞源于Bzip2 decompression decoder功能不允许对解压输出数据设置大小限制(这会影响解压期间使用的分配大小)。攻击者可利用该漏洞引发DoS攻击。
影响范围:(∞, 4.1.68.Final)
最小修复版本:4.1.68.Final
缺陷组件引入路径:io.maxilog:[email protected]>io.quarkus:[email protected]>io.quarkus:[email protected]>io.quarkus:[email protected]>io.netty:[email protected]

另外还有26个漏洞,详细报告:https://mofeisec.com/jr?p=i22050

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.