Multi-Tenant Spring Boot Application with separate databases using Hibernate and H2.

Overview

Multi-Tenant Spring Boot Application License: MIT build

A Spring Boot application that utilises a multi-tenancy architecture by providing multiple databases, one for each tenant.

Tenants, respectively users, are stored in the default database db.mv.db. All requests toward /api/v1/user are subsequently accessing it while the rest is accessing the db of the authenticated user.

How to initialise

In order to use the application, a user must be logged in. This authentication process returns a Bearer token which is used for all other requests.

1. POST request to api/v1/user/signup.

{
  "email": "[email protected]",
  "password": "asdfasdfasdf",
  "confirmation": "asdfasdfasdf"
}

2. POST request to api/v1/user/authentication

{
  "email": "[email protected]",
  "password": "asdfasdfasdf"
}

How to use

The application opens a h2-console to easily manage all available databases. Each one is generated right after the first access / request to it. The filename is the hashed email adress database/[hashed_email].mv.db.

  • Movie endpoint
    • POST api/v1/movie:
    • GET api/v1/movie/{id}:
  • User endpoint
    • PATCH api/v1/user/email

Example request to api/v1/movie

{
  "title": "The Hitchhiker's Guide to the Galaxy",
  "runtime": 109,
  "releaseDate": "2005-04-28"
}

Example request to api/v1/user/email

{
  "email": "[email protected]"
}
Comments
  • Maven tests fail on github but run locally

    Maven tests fail on github but run locally

    Describe the bug Tests fail on Github but run perfectly on my MacBook.

    To Reproduce Steps to reproduce the behavior:

    1. Run workflow

    Expected behaviour Tests should run correctly.

    Actual behaviour One / two tests fail.

    Screenshots

    Additional context NullpointerException while performing mock mvc request (patch request)

    bug 
    opened by agschnitzer 1
  • Enable cross site request forgery (CSRF) protection

    Enable cross site request forgery (CSRF) protection

    Is your feature request related to a problem? Please describe. To improve the security of the application, csrf can be enabled.

    Describe the solution you'd like A simple solution implementing csrf protection.

    Describe alternatives you've considered No alternatives.

    Additional context No additional context.

    enhancement 
    opened by agschnitzer 1
  • Updated hibernate with schema export to automatically initialise db

    Updated hibernate with schema export to automatically initialise db

    Added dependency to scan for packages Added beans for entity manager factory, session factory and transaction manager Added getters to database properties Simplified lookup of current context Removed unnecessary application properties Removed sample data for now Updated tests Updated README.md

    enhancement 
    opened by agschnitzer 1
  • Implementation of multiple testing databases

    Implementation of multiple testing databases

    Is your feature request related to a problem? Please describe. Yes, it is related to a problem. Currently, only one in-memory database is used for testing. Several databases are required to provide meaningful test cases.

    Describe the solution you'd like Replace the existing in-memory database with at least two (in-memory or persistent) databases.

    Describe alternatives you've considered In order to properly test the multi-tenant application, multiple databases are needed. So I think there is no alternative.

    Additional context A testing setup with at least two databases (the default database and a database of a tenant) is needed to generate meaningful test cases.

    enhancement 
    opened by agschnitzer 1
  • After changing email of user, jwt is still valid

    After changing email of user, jwt is still valid

    Describe the bug After changing the email of a user, thejwt with the old email can still be used which results in the creation of duplicate databases.

    To Reproduce Steps to reproduce the behavior:

    1. Start with empty database
    2. Sign up a user
    3. Authenticate the user
    4. Save a movie with the token received after step 3
    5. Change the email of the user
    6. Send a request to get a movie with the 'old' jwt
    7. Database of 'old' user is created

    Expected behaviour After changing the email, the associated jwt should be invalidated.

    Actual behaviour After change the email, the associated jwt is still valid.

    Screenshots

    Additional context Some additional logic must be implemented to ignore the default behaviour of jwt validity.

    bug 
    opened by agschnitzer 0
  • Added proper testing environment

    Added proper testing environment

    Changes

    Changed in-memory to persistent database Added endpoint and mapper to save a movie + all tests Added database location to both application property files DataConfig now switches between normal and testing databases Fixed bug with incorrect datasource of entity manager Removed sql files Updated gitignore

    Issue: #1

    enhancement 
    opened by agschnitzer 0
  • Using Hibernate to initialise databases

    Using Hibernate to initialise databases

    Is your feature request related to a problem? Please describe. Hibernate can't initialise the dynamically generated databases but generates sql files which create the tables.

    Describe the solution you'd like Hibernate initialises the databases without the need of external sql files.

    Describe alternatives you've considered It doesn't have to be Hibernate but I think it's the best solution.

    Additional context The lookup process on each request isn't fully optimised. There is the need for an additional header on some requests which might be removed with a proper Hibernate implementation.

    enhancement 
    opened by agschnitzer 0
Owner
Alex Gschnitzer
I'm a Full-Stack developer and computer science student from Vienna.
Alex Gschnitzer
该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的线上博客项目/企业大型商城系统/前后端分离实践项目等,摆脱各种 hello world 入门案例的束缚,真正的掌握 Spring Boot 开发。

Spring Boot Projects 该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的前

十三 4.5k Dec 30, 2022
The goal of the project is to create a web application using Java EE and database (PostgreSQL) without connecting a modern technology stack like spring boot and hibernate

About The Project SignIn page SignUp page Profile page The goal of the project is to create a web application using Java EE and database (PostgreSQL)

Islam Khabibullin 2 Mar 23, 2022
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc

Spring 系列教程 该仓库为个人博客https://mrbird.cc中Spring系列源码,包含Spring Boot、Spring Boot & Shiro、Spring Cloud,Spring Boot & Spring Security & Spring Security OAuth2

mrbird 24.8k Jan 6, 2023
Spring Kurulumundan Başlayarak, Spring IOC ve Dependency Injection, Hibernate, Maven ve Spring Boot Konularına Giriş Yapıyoruz.

Spring Tutorial for Beginners File Directory Apache Tomcat Apache Tomcat - Eclipse Bağlantısı Spring Paketlerinin İndirilmesi ve Projeye Entegrasyonu

İbrahim Can Erdoğan 11 Apr 11, 2022
Build criterion and ecosystem above multi-model databases

ShardingSphere - Building a Criterion and Ecosystem Above Multi-Model Databases Official Website: https://shardingsphere.apache.org/ Stargazers Over T

The Apache Software Foundation 17.8k Jan 9, 2023
A code sharing platform built using spring boot, hibernate and JPA as ORM with PostgreSQL which also follows a RESTful architecture.

Snap-Snippet A code sharing platform built using spring boot, hibernate and JPA as ORM with PostgreSQL which also follows a RESTful architecture. Tech

Adnan Hossain 7 Nov 29, 2022
A simple quarkus app with hibernate as ORM, used to show the features of Hibernate Search

beer-manager-hibernate-search Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, ple

Sedona Solutions 3 Jan 6, 2022
Customize your device even more by having two separate sets of wallpapers for light and dark mode.

DualWallpaper You can help me out with translations here. Customize your device even more by having two separate sets of wallpapers for light and dark

Yann 18 Dec 25, 2022
Spring JPA Many To Many example with Hibernate and Spring Boot CRUD Rest API - ManyToMany annotation

Spring JPA Many To Many example with Hibernate and Spring Boot CRUD Rest API - ManyToMany annotation

null 17 Dec 28, 2022
Tuya 37 Dec 26, 2022
This project archetype is a template for creating a fully functional MVC web application using Hibernate, JSTL and Bootstrap

This project archetype is a template for creating a fully functional MVC web application using Hibernate, JSTL and Bootstrap. It has an automatic database creation, auto initial load of the data, with different variety of users. It also has a checkstyle to check the proper coding of your project immediately right after you enter the code.

null 90 Oct 21, 2022
The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker.

gke-springboot-sampleapp ?? The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker. Usage To be

KYEONGMIN CHO 1 Feb 1, 2022
hibernate redis 二级缓存使用 spring boot redis 配置

hibernate-redisson-spring-boot-starter 介绍 使用 Redisson 作为 hibernate redis 二级缓存提供器,redisson-hibernate-53(hibernate-version) 无法使用 spring boot 配置文件创建的 org

null 4 Jul 3, 2022
Spring Boot, Hibernate, JpaRepository, RESTful services & PostgreSQL.

HRMS-Project Human Resources Management System Back End application with Java, Spring Boot, Hibernate, JpaRepository, RESTful services & PostgreSQL. S

Hikmet Tutuncu 9 Aug 23, 2022
Um sistema de hospital feito em Spring Boot, contendo alguns CRUD's, e utilizando algumas famosas dependências, como o Hibernate. Vale destacar a interface inspirada no jogo Minecraft.

Introdução ✏ Esse projeto é uma atividade da disciplina de Design, Arquitetura e Construção de Software [DACS]. O objetivo do projeto é simular um sis

Ramon Victor Cardoso 12 Nov 6, 2022
This module explains about the example of Spring MVC + Database Integration with MySQL using Hibernate ORM with practical coding example and required JAR dependencies

SpringMVC-Database-Integration This module explains about the example of Spring MVC + Database Integration with MySQL using Hibernate ORM with practic

GowthamRaj K 3 Nov 2, 2021
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

null 58 Jan 5, 2023
Spring Boot JdbcTemplate example with SQL Server: CRUD Rest API using Spring Data JDBC, Spring Web MVC

Spring Boot JdbcTemplate example with SQL Server: Build CRUD Rest API Build a Spring Boot CRUD Rest API example that uses Spring Data Jdbc to make CRU

null 7 Dec 20, 2022
In this course, we will learn how to build a complete full-stack web application using Spring boot as backend and React (React Hooks) as frontend

In this course, we will learn how to build a complete full-stack web application using Spring boot as backend and React (React Hooks) as frontend. We will use MySQL database to store and retrieve the data.

Ramesh Fadatare 43 Dec 22, 2022