{"id":21430099,"url":"https://github.com/cuba-platform/sample-saas","last_synced_at":"2025-07-14T11:31:03.191Z","repository":{"id":150932312,"uuid":"58451241","full_name":"cuba-platform/sample-saas","owner":"cuba-platform","description":"Example of a multi-tenant application","archived":false,"fork":false,"pushed_at":"2018-10-11T08:59:41.000Z","size":158,"stargazers_count":11,"open_issues_count":0,"forks_count":14,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-08T07:18:42.324Z","etag":null,"topics":["cuba-sample"],"latest_commit_sha":null,"homepage":"https://www.cuba-platform.com","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cuba-platform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-10T10:15:20.000Z","updated_at":"2022-10-21T14:18:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7f982b9-1d3e-4245-b4bb-be3cd729399d","html_url":"https://github.com/cuba-platform/sample-saas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cuba-platform/sample-saas","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuba-platform%2Fsample-saas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuba-platform%2Fsample-saas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuba-platform%2Fsample-saas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuba-platform%2Fsample-saas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cuba-platform","download_url":"https://codeload.github.com/cuba-platform/sample-saas/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuba-platform%2Fsample-saas/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265285209,"owners_count":23740483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuba-sample"],"created_at":"2024-11-22T22:20:43.311Z","updated_at":"2025-07-14T11:31:03.184Z","avatar_url":"https://github.com/cuba-platform.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SaaS\n\nThis project demonstrates an approach to the creation of a multi-tenant [CUBA](https://www.cuba-platform.com) application.\n\n## Objective\n\nLet’s suppose that our CUBA application should be used by several clients:\n\n* There are two types of entities in the application:\n    * Shared entities that are available for all clients (typically they represent some reference data). In this project, it is the `PaymentMethod `entity.\n    * Client entities - their instances belong to one certain client. In this project, these are `Customer` and `Order` entities.\n* Client's users can see only their client entities.\n* There is a predefined set of client's user roles:\n    * Admins can create users within their client and assign available roles to them. Admins do not see other clients and their users.\n    * Regular users can only work with data.\n\n## Solution\n\nOpen the project in CUBA Studio, execute *Run \u003e Create database*, then *Run \u003e Start application server* and open the application at `http://localhost:8080/app`.\n\n* Log in as `admin` / `admin`. This account gives the full access to the application and does not belong to any client.\n\n    First, open the *Administration \u003e Access Group* screen.\n\n    The groups under the Clients group represent clients. Each of the client groups has a unique session attribute called `client_id`. This ID will be used to separate client entities.\n\n    Open the *Constraints* tab for the Clients group. It contains restrictions that will be applied when reading entities by users located in the client's groups. All client entities (`Customer` and `Group` in this project) should have the constraint with the following `where` clause: `{E}.client = :session$client_id`. Security-related entities have special restrictions to satisfy requirements of having client admins that are able to manage their own users.\n\n    The `admin` user can create only `PaymentType` entities shared between clients. If you try to create a client-specific entity like `Customer`, you will get an exception.\n\n* Log in as `stark` / `1`. This is an admin of the `Stark Industries` client. You can create customers and orders, as well as create users for your client and assign the roles `client_admin` or `client_user` to them.\n\n* Log in as `potts` / `1`. This is a user of the `Stark Industries` client. You can see and manage the customers and orders created by `stark`, but you cannot create new users.\n\n* Log in as `dent` / `1`. This is an admin of the `Sirius Cybernetics Corp.` client. You can create users, customers and orders, but you don't see entities created by the `Stark Industries` users.\n\n## Implementation Details\n\n1. The `StandardClientEntity` entity is a `@MappedSuperlass` and serves as a base class for all client entities. It has the `client` attribute which is populated from the `client_id` user session attribute when an instance is created (see the `init()` method annotated with `@PostConstruct`).\n\n2. The `Users` role is marked as default and should be assigned to all client users. It restricts access to security screens and does not allow client admins to modify existing roles.\n\n3. The `AppLifecycle` bean registers additional entity listener for the `User` entity. The listener ensures that default roles (including `Users`) are assigned to new users.\n\n4. Due to the constraint for `sec$Role` entity assigned to the Clients group, client users see only roles with names starting with `client_`. That is they do not see `Administrators` and `Users` roles.\n\nBased on CUBA Platform 6.10.1\n\n## Issues\nPlease use https://www.cuba-platform.com/discuss for discussion, support, and reporting problems coressponding to this sample.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuba-platform%2Fsample-saas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuba-platform%2Fsample-saas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuba-platform%2Fsample-saas/lists"}