Tenant information storage method, device, electronic device and storage medium

By receiving and storing tenant identity information in a multi-tenant architecture, the problem of tenant isolation is solved, clear data isolation and security is achieved, operation and maintenance management is simplified, and flexible expansion of multi-tenant environments is supported.

CN119046984BActive Publication Date: 2025-09-02CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411159435.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-22
Publication Date
2025-09-02
Estimated Expiration
2044-08-22

AI Technical Summary

Technical Problem

In a multi-tenant architecture, how to effectively implement tenant isolation, ensure that each tenant's data and resources can be independent of other tenants, prevent data breaches and illegal access, and meet compliance requirements.

Method used

By receiving the client's request message, the tenant's identity information is detected. If it is valid, it is encapsulated into the variable area to save the object, and stored in the database when the entity is persisted. The business platform and listener mechanism are used to ensure that the tenant's identity information is associated with the entity records and achieve clear isolation of the data.

Benefits of technology

It improves the privacy and security of tenant data, prevents data leakage, simplifies operation and maintenance management, supports a large number of tenants and expands with business growth, reduces data confusion and errors, and improves system stability and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119046984B_ABST
    Figure CN119046984B_ABST
Patent Text Reader

Abstract

The embodiments of the present application disclose a tenant information storage method, apparatus, device and medium. The method includes: receiving a request message sent by a client, wherein the request message carries tenant identity information; if it is detected that the tenant identity information is valid tenant identity information, the request message is forwarded to the business platform; the tenant identity information is encapsulated into a variable area storage object by the business platform; when the entity is persisted, the tenant identity information is stored in the database based on the variable area storage object. The embodiments of the present application can further clearly distinguish and isolate the data of different tenants by encapsulating and storing the tenant identity information in each entity record in the database, thereby improving the effectiveness of tenant isolation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data management technology, and in particular to a tenant information storage generation method, device, electronic device, and computer-readable storage medium. Background Art

[0002] With the rapid development of cloud computing technology, multi-tenant architecture has become the mainstream model for SaaS (Software as a Service) applications. Multi-tenant architecture allows multiple tenants to share the same hardware and software resources, achieving data independence and security through logical isolation. Therefore, tenant interception technology, as a key component of multi-tenant architecture, is becoming increasingly important.

[0003] Tenant isolation is a management and technical means whose core goal is to ensure the security and privacy of each tenant in a multi-user environment. Therefore, how to achieve tenant isolation so that each tenant's data and resources can be independent of other tenants is an urgent problem that needs to be solved. Summary of the Invention

[0004] To solve the above technical problems, embodiments of the present application provide a tenant information storage method and device, an electronic device, a computer-readable storage medium, and a computer program product.

[0005] According to one aspect of an embodiment of the present application, a tenant information storage method is provided, including: receiving a request message sent by a client, the request message carrying tenant identity information; if it is detected that the tenant identity information is valid tenant identity information, forwarding the request message to a business platform; encapsulating the valid tenant identity information into a variable area storage object through the business platform; and when the entity is persisted, storing the valid tenant identity information in a database based on the variable area storage object.

[0006] According to one aspect of this embodiment, the method also includes: monitoring operations for entity persistence to obtain monitoring results; obtaining the valid tenant identity information from the object saved in the variable area based on the monitoring results; generating corresponding entity fields based on the tenant identity information to synchronously persist the tenant identity.

[0007] According to one aspect of an embodiment of the present application, the method further includes: obtaining the entity field when the entity is persisted; setting the entity field to the target field corresponding to the entity to obtain target data; and storing the valid tenant identity identification information in a database based on the target data.

[0008] According to one aspect of an embodiment of the present application, the method further includes: if the business platform detects valid tenant identity information from the request message, binding the valid tenant identity information to the context of the current thread to obtain a variable area storage object.

[0009] According to one aspect of an embodiment of the present application, encapsulating the valid tenant identity identification information into a variable area storage object through the business platform also includes: defining a request header context category, and obtaining the context object of the current thread based on the context category; encapsulating the valid tenant identity identification information into a text context object, and saving it to the current thread storage to obtain a variable area storage object.

[0010] According to one aspect of an embodiment of the present application, the method further includes: detecting, by a service gateway, whether the request message contains tenant identity information; if the request message does not contain tenant identity information, returning an error response message to the client.

[0011] According to one aspect of an embodiment of the present application, after the valid tenant identity identification information is stored in the database based on the variable area saving object, the method further includes: responding to a request message sent by the tenant, determining the tenant identity information corresponding to the rental house based on the request message; searching for matching target tenant identity information from the database based on the tenant identity information; and determining the resource information corresponding to the tenant based on the displayed target tenant identity information.

[0012] According to one aspect of an embodiment of the present application, a tenant information storage device is provided, including: a receiving module for receiving a request message sent by a client, the request message carrying tenant identity information; a forwarding module for forwarding the request message to a business platform if it is detected that the valid tenant identity information is valid tenant identity information; an encapsulation module for encapsulating the valid tenant identity information into a variable area storage object through the business platform; and a storage module for storing the valid tenant identity information in a database based on the variable area storage object when the entity is persisted.

[0013] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device implements the tenant information storage method as described above.

[0014] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the tenant information storage method as described above.

[0015] According to one aspect of an embodiment of the present application, a computer program product is further provided, including a computer program, which implements the steps in the tenant information storage method described above when executed by a processor.

[0016] In the technical solution provided in the embodiment of the present application, by receiving the request message sent by the client and detecting whether the tenant identity information carried in the request message is valid tenant identity information, the data of different tenants can be clearly distinguished, thereby achieving data isolation at the database level. Then, the tenant identity information is encapsulated into a variable area to save the object through the business platform; and then, by encapsulating and storing the tenant identity information in each entity record in the database, the data of different tenants can be clearly distinguished and isolated, thereby improving the effectiveness of tenant isolation. The tenant identity information is encapsulated into a variable area to save the object, and is stored in the database when the entity is persisted, so that the system can flexibly support a multi-tenant environment.

[0017] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The accompanying drawings are incorporated into and constitute a part of the specification, illustrating embodiments consistent with the present application and, together with the specification, serving to explain the principles of the present application. It is obvious that the drawings described below are merely some embodiments of the present application, and a person of ordinary skill in the art can derive other drawings based on these drawings without inventive effort. In the drawings:

[0019] Figure 1 is a schematic diagram of an implementation environment for storing tenant information according to an exemplary embodiment of the present application;

[0020] Figure 2 is a flowchart of a tenant information storage method shown in an exemplary embodiment of the present application;

[0021] Figure 3 is a flowchart of a tenant information storage method shown in another exemplary embodiment of the present application;

[0022] Figure 4 is a flowchart of a tenant information storage method shown in another exemplary embodiment of the present application;

[0023] Figure 5 is a flowchart of a tenant information storage method shown in another exemplary embodiment of the present application;

[0024] Figure 6 is a flowchart of a tenant information storage method shown in another exemplary embodiment of the present application;

[0025] Figure 7 is a flowchart of a tenant information storage method shown in another exemplary embodiment of the present application;

[0026] Figure 8 This is a brief flowchart of tenant information storage in a navigation interface in an exemplary application scenario;

[0027] Figure 9 is a block diagram of a tenant information storage device shown in an exemplary embodiment of the present application;

[0028] Figure 10 A schematic diagram of the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0029] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. When the following description refers to the drawings, identical numerals in different figures represent identical or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.

[0030] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0031] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.

[0032] In this application, "plurality" refers to two or more. "And / or" describes the relationship between related objects, indicating that three possible relationships exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.

[0033] First of all, it should be explained that tenant data isolation is the physical or logical isolation of data from different tenants in a multi-tenant environment to ensure that each tenant can only access and operate their own data, thereby protecting the privacy and security of the data. The importance of tenant data isolation: Protecting data privacy: In a multi-tenant system, each tenant's data is independent, and isolation measures can prevent data leakage and illegal access, protecting the privacy rights and interests of tenants; Improving security: Through data isolation, a tenant's data can be prevented from being maliciously tampered with or destroyed by other tenants, enhancing the overall security of the system; Meeting compliance requirements: Many industries have strict data protection regulations, such as GDPR (EU General Data Protection Regulation), etc. Tenant data isolation helps enterprises meet these compliance requirements. Management of tenant data isolation: Access control: Implement fine-grained access control policies to limit user access rights to data and ensure that only authorized users can access the data of the tenant to which they belong. Security audit: Establish a comprehensive security audit system to record all access and operation behaviors to data so that they can be traced and investigated when security incidents occur. Compliance management: Ensure that the multi-tenant environment complies with applicable regulations and compliance standards, including data privacy regulations, etc.

[0034] Specifically, with the rapid development of cloud computing technology, multi-tenant architectures play a crucial role in SaaS (Software as a Service) applications. By allowing multiple tenants to share the same hardware and software resources, multi-tenant architectures significantly reduce enterprise operating costs and improve resource utilization. At the same time, to ensure the independence and security of each tenant's data, logical isolation has become a core mechanism in multi-tenant architectures. In this context, tenant interception technology, as a key component in achieving logical isolation, has become increasingly important. The importance of tenant interception technology includes: ensuring data isolation: Tenant interception technology ensures that each tenant's data is logically isolated, preventing data leakage and unauthorized access. This is fundamental to protecting tenant privacy and data security; improving system performance: Through intelligent tenant interception policies, the system can more efficiently manage resources, avoid resource conflicts and waste, and thus improve overall system performance; and simplifying operations and maintenance management: In multi-tenant architectures, tenant interception technology helps streamline operations and management processes. Administrators can use tenant isolation policies to quickly identify and resolve issues, reducing operations and maintenance costs. The implementation methods of tenant interception technology include: Network layer interception: By configuring network devices (such as routers, switches, etc.) and using VLAN (virtual local area network) and other technical means, the network traffic of different tenants can be isolated. This method mainly realizes physical or logical isolation between tenants at the network layer, Application layer interception: At the application layer, through components such as middleware, filters or interceptors, requests entering the system are intercepted and processed. These components can route requests to the corresponding tenant instance or data resource based on tenant information (such as tenant ID, domain name, etc.). This method mainly realizes logical isolation between tenants at the application layer, Data layer interception: At the data layer, through database permission control, data encryption and other technical means, ensure that each tenant can only access and operate his own data. At the same time, a multi-tenant database architecture (such as independent database, shared database independent schema, etc.) can also be adopted to achieve isolation between tenants at the data level.

[0035] Figure 1 This is a schematic diagram of an implementation environment for tenant information storage according to an exemplary embodiment of the present application. Figure 1 As shown, the client 110 initiates a tenant information storage request to the server 120 according to actual needs, and carries the tenant identity information in the request header of the request. After receiving the request message sent by the client 110, the server 120 detects whether the request header of the request message contains the tenant identity information. When the request header contains tenant identity identification information, the tenant identity information can be extracted from the request header and encapsulated in the request header context encapsulation class. The object is saved in the local thread variable area. When the entity is persisted, the tenant information in the object saved in the local thread variable area can be persisted to the database together, thereby realizing the storage of tenant information.

[0036] in, Figure 1 The client 110 shown can be any terminal device such as a smart phone, a car computer, a tablet computer, a laptop computer or a wearable device, but is not limited thereto. Figure 1 The navigation server 120 shown can be, for example, an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, and there is no limitation here. The client 110 can communicate with the server 120 through wireless networks such as 3G (third generation mobile information technology), 4G (fourth generation mobile information technology), and 5G (fifth generation mobile information technology), and there is no limitation here.

[0037] Tenant isolation is a management and technical means whose core goal is to ensure the security and privacy of each tenant in a multi-user environment. Therefore, how to achieve tenant isolation so that each tenant's data and resources can be independent of other tenants is a problem that needs to be solved urgently.

[0038] The above-mentioned issues are generally applicable to general tenant isolation scenarios. As can be seen, to address these issues, the embodiments of this application respectively propose a tenant information storage method, a tenant information storage device, an electronic device, a computer-readable storage medium, and a computer program product. These embodiments are described in detail below.

[0039] See also Figure 2 , Figure 2 This is a flowchart of a tenant information storage method shown in an exemplary embodiment of the present application. This method can be applied to Figure 2 The implementation environment shown is specifically executed by the server 120 in the implementation environment. It should be understood that the method can also be applied to other exemplary implementation environments and specifically executed by devices in other implementation environments. This embodiment does not limit the implementation environment to which the method is applicable.

[0040] like Figure 2 As shown, in an exemplary embodiment, the specific implementation method of the tenant information storage method includes at least steps S210 to S240, which are described in detail as follows:

[0041] Step S210: Receive a request message sent by the client, where the request message carries tenant identity information.

[0042] Specifically, the backend service needs to be able to receive HTTP requests from the client. These requests may be sent through HTTP GET, POST, PUT, DELETE and other methods, and may contain multiple types of data (such as JSON, XML, etc.). Parsing HTTP headers: Tenant identity information may be included in HTTP request headers, such as the Authorization header (often used to carry JWT tokens), X-Tenant-ID, or custom headers. It also includes parsing the request body in the request message. If the authentication information is included in the request body (such as a POST request), the request body content (such as JSON) needs to be parsed to obtain the tenant information. Verifying the token: If JWT (JSON Web Tokens) or other token mechanisms are used, the legitimacy, signature, and validity (including expiration time) of the token need to be verified. Checking the tenant ID: Confirming whether the tenant ID provided in the request exists in the system and that the tenant status is active (not deleted or disabled). Permission check: Based on the tenant ID and the specific operation requested, check whether the tenant has permission to perform the operation.

[0043] Step S220: If it is detected that the tenant identity information is valid tenant identity information, the request message is forwarded to the business platform.

[0044] Specifically, if it is detected that the tenant identity information included in the request header of the request message is valid tenant identity information, the request message can be forwarded to the business platform, so that the business platform can parse the request message and store the identity information in the request message in and out to achieve data isolation for the tenant.

[0045] For example, if the tenant identity information is valid, this information can be attached to the request message (although it may already be in the request header, it needs to be explicitly included in the internal request object according to the corresponding system architecture). Ensure that other parts of the request message (such as the request body, request method, etc.) are also complete and valid, and call the internal API call. If the business logic is layered or microservice architecture, it is necessary to forward the request message to the business service responsible for processing the request through the internal API (such as REST API, gRPC, etc.). Optionally, in some feasible embodiments, another option is to put the request message into a message queue, and the service of the business platform listens for and processes these request messages.

[0046] Step S230: Encapsulate the valid tenant identity information into a variable area storage object through the business platform.

[0047] Specifically, after forwarding the request message to the business platform, the business platform intercepts the request header in the request message through an interceptor, obtains the tenant identity information from the request header, and then encapsulates the tenant identity information in the request header context encapsulation to save the object through the local thread variable area.

[0048] For example, after forwarding the request message to the business platform, the business platform will usually process the request through a series of middleware or framework features (such as interceptors, filters, etc.). When the request reaches the interceptor, the interceptor will first read the HTTP request header. Look for the header field containing the tenant identity information (such as X-Tenant-ID) in the request header. Verify whether the tenant identity information is valid (for example, check whether it exists in the database and the corresponding tenant status is active). If the tenant identity information is valid, the interceptor will encapsulate it in a request context object. This context object can be a custom class that contains tenant identity information and other request metadata that may be required.

[0049] Alternatively, in some feasible embodiments, another common practice is to store the tenant identity information in a local thread variable (ThreadLocal). Since HTTP requests are usually processed by multiple threads, using ThreadLocal can ensure that each request has its own copy of the tenant identity information, which will not be mixed with data from other requests.

[0050] Step S240: When the entity is persisted, the valid tenant identity information is stored in the database based on the object saved in the variable area.

[0051] Specifically, when the entity is persisted, the listener simplifies the entity, extracts the tenant identity information from the object stored in the variable area when the entity is created or modified, and stores it in the database.

[0052] For example, during the entity persistence process, a listener (such as JPA's EntityListeners, Hibernate's EventListener, or Spring Data's corresponding mechanism) is used to intercept entity creation or modification operations, and the tenant identity information is extracted from the thread variable area (such as ThreadLocal) or the request context (Request Context), and then stored in the database.

[0053] In this embodiment, by encapsulating and storing tenant identity information in each entity record in the database, the system is able to clearly distinguish and isolate data from different tenants. This is crucial for multi-tenant applications because it ensures the privacy and security of data and prevents data leakage between different tenants. When a new tenant joins the system, there is no need to make major modifications to the system architecture or database structure. The new tenant identity information only needs to be processed and stored according to the same process. This flexibility allows the system to easily support a large number of tenants and expand as the business grows. It also verifies and identifies tenant identities in the early stages of request processing, allowing subsequent business logic processing to be based on the correct tenant context. This reduces confusion and errors that may occur when mishandling data from different tenants, and improves the stability and reliability of the system.

[0054] Further, based on the above embodiment, please refer to Figure 3 In one of the exemplary embodiments provided in this application, the specific implementation process of the above tenant information storage method may further include steps S310 to S330, which are described in detail as follows:

[0055] Step S310: monitor the operation on entity persistence and obtain the monitoring result;

[0056] Step S320: Obtain valid tenant identity information from the object stored in the variable area based on the monitoring result;

[0057] Step S330: Generate the value of the corresponding entity field based on the tenant identity information to synchronize and persist the tenant identity.

[0058] Specifically, you can monitor entity persistence operations to obtain corresponding monitoring results. For example, when monitoring entity persistence operations, such as inserting an entity into the database or saving updates to certain fields, the corresponding logic is executed when these operations are detected. The tenant identification information stored in the variable area is retrieved and set to the corresponding field in the entity, ensuring that the tenant identification information is persisted synchronously with the entity when the entity is persisted. For example, this can be achieved by annotating the listener with @EntityListeners and @PrePersist.

[0059] For example, a listener (such as JPA's @EntityListeners and @PrePersist) is used to set the value of an entity field before the entity is persisted. Here, the tenant identity (usually obtained from the request header or other context information) can be set as the value of the entity field.

[0060] In this embodiment, through a monitoring mechanism, the system can capture changes in variable area stored objects, particularly updates to tenant identity information, in real time or on demand. This dynamic nature enables the system to flexibly respond to changes in tenant information in a multi-tenant environment, automatically adapting to changes without manual intervention or service restarts. Furthermore, monitoring and generating entity field values ​​based on the latest tenant identity information helps ensure that the data stored in the database is consistent with the actual state of the current tenant. This reduces errors and issues caused by data inconsistencies and improves data accuracy and reliability.

[0061] Further, based on the above embodiment, please refer to Figure 4 In one of the exemplary embodiments provided in this application, the specific implementation process of the above tenant information storage method may further include steps S410 to S430, which are described in detail as follows:

[0062] Step S410, when the entity is persisted, obtaining the value of the entity field;

[0063] Step S420, setting the value of the entity field to the target field corresponding to the entity to obtain the target data;

[0064] Step S430: Store the valid tenant identity information in the database based on the target data.

[0065] Specifically, during the persistence process, the entity field value generated by the tenant identity identifier in the object saved in the variable area of ​​the above embodiment is obtained, and the entity field value is set to the target field corresponding to the entity, thereby obtaining the corresponding target data, and then the tenant identity identifier information is stored in the database based on the target data, thereby realizing tenant isolation.

[0066] For example, before persistence, you need to get the tenant ID from some part of the application (such as the request context, thread local variables, etc.) and set it to the tenantId field of the entity. This can be achieved in a variety of ways, but the most common is to use the features of the Spring framework, such as @RequestScope beans, ThreadLocal variables, or Spring's RequestContextHolder. JPA (Java Persistence API) is a Java specification for object-relational mapping (ORM) that allows developers to map Java objects to tables in the database and automatically handle the data persistence process. When using JPA, you can define entity classes to represent tables in the database and manage the interaction between these entities and the database through a JPA provider (such as Hibernate).

[0067] When implementing tenant isolation, JPA can be a powerful tool to help manage entities that contain tenant IDs and ensure that these entities are correctly persisted to the database.

[0068] Once the tenant ID for an entity is set, you can use JPA's entity listener to automatically set the tenant ID, but this is more common in the repository or service layer. Because the entity listener works at the JPA level, it may not have direct access to Spring's context or ThreadLocal variables. Therefore, you may need to explicitly set the tenant ID in the service layer. You can then use the JPA repository to save the entity as usual. JPA will automatically handle persisting the entity and its tenant ID to the database.

[0069] In this embodiment, by persisting tenant identity information as part of the entity, the integrity of the data during storage is ensured, so that each entity record clearly identifies the tenant to which it belongs. This is crucial for maintaining data isolation and access control in a multi-tenant system. By closely associating tenant identity information with entity data, the system can more easily implement fine-grained access control.

[0070] Furthermore, based on the above embodiment, in one of the exemplary embodiments provided in this application, the specific implementation process of the above tenant information storage method may further include the following steps, which are described in detail as follows:

[0071] If the business platform detects valid tenant identity information from the request message, it binds the valid tenant identity information to the context of the current thread to obtain the variable area storage object.

[0072] Specifically, when the business platform detects valid tenant identity information (such as the tenant ID) from a request message, it typically binds this information to the current thread's context to ensure convenient access to the tenant identity during subsequent business logic processing. In Java, this can be achieved in a variety of ways, such as using a ThreadLocal variable, Spring's RequestContextHolder, or a custom context management tool.

[0073] In this embodiment, in a multi-threaded environment, tenant identity information is bound to the current thread's context, ensuring that each thread has its own independent tenant context when processing requests. This isolation mechanism prevents confusion between tenant data across threads, thereby improving data security.

[0074] Further, based on the above embodiment, please refer to Figure 5In one of the exemplary embodiments provided in this application, the specific implementation process of the above step of encapsulating the tenant identity information into the variable area storage object through the business platform may also include steps S510 and S520, which are detailed as follows:

[0075] Step S510, defining a request header context category, and obtaining a context object of the current thread based on the context category;

[0076] Step S520: Encapsulate the valid tenant identity information into a context object and save it to the current thread storage to obtain a variable area storage object.

[0077] Specifically, you can define a request header context category (here I call it RequestHeaderContext) and encapsulate context information related to the request header, including tenant identity information, in this category. Then, you can get or set the context object of the current thread based on this context category. Specifically, you can use ThreadLocal to implement thread-isolated context storage. First, define a RequestHeaderContext class. This class can contain multiple properties, but in this example, we only focus on tenant identity information. Then, define a context management class (such as ContextHolder) and use ThreadLocal to store the RequestHeaderContext object.

[0078] In this embodiment, by defining the request header context category, request-related data, including tenant identity information, can be managed in a structured manner. Since the context object is bound to the current thread, each thread has its own independent context instance. This design ensures data isolation and thread safety in a multi-threaded environment, avoids data competition and conflicts, and thus achieves tenant isolation.

[0079] Further, based on the above embodiment, please refer to Figure 6 In one of the exemplary embodiments provided in this application, the specific implementation process of the above tenant information storage method may further include steps S610 and S620, which are described in detail as follows:

[0080] Step S610: Detecting whether the request message contains tenant identity information through the service gateway;

[0081] Step S620: If the request message does not include tenant identity information, an error response message is returned to the client.

[0082] Specifically, a business gateway is typically a component in the system architecture that routes, filters, and transforms requests. In this scenario, you can add logic to the gateway's filters or middleware to check whether the request contains the tenant identifier. If it detects that the request message does not contain tenant identifier information, an error response can be returned to the client to indicate that the tenant identifier information was not set in the request message.

[0083] For example, first, determine whether the tenant identity is passed through HTTP request headers, query parameters, cookies, or other means. This usually depends on the system design and client constraints. Depending on the gateway framework used (such as Spring Cloud Gateway, Nginx+Lua, Zuul, etc.), write a custom filter or middleware to intercept every request entering the gateway. In the filter or middleware, check whether the tenant identity exists in the specified location of the request (such as the HTTP request header). If the request does not contain the tenant identity, based on business needs, you can choose to return an error response to the client, prompting the client that the request lacks the necessary tenant identity information. The error response can be a standard HTTP status code (such as 400 Bad Request) plus a custom error message. You can also set the Content-Type of the response to application / json and return an error object in JSON format to make it easier for the client to parse and process.

[0084] In this embodiment, ensuring that each request clearly specifies tenant identification information helps prevent unauthorized access or data leakage. By early detecting and rejecting non-compliant requests, the system can more effectively protect its resources and data from potential security threats. Ensuring that all processed data is associated with the correct tenant avoids data confusion or errors caused by unclear tenant identities. This helps maintain data accuracy and consistency, improving the overall quality of the system.

[0085] Further, based on the above embodiment, please refer to Figure 7 In one of the exemplary embodiments provided in this application, after the tenant identity information is stored in the database based on the variable area storage object, the specific implementation process of the tenant data storage method may further include steps S710 to S730, which are described in detail as follows:

[0086] Step S710, in response to the request message sent by the tenant, determining the tenant identity information corresponding to the rental based on the request message;

[0087] Step S720: searching for matching target tenant identity information from a database based on the tenant identity information;

[0088] Step S730: Determine resource information corresponding to the tenant based on the target tenant identity information.

[0089] Specifically, tenants can send request messages to the system in some way (such as HTTP requests, API calls, etc.). These request messages may contain the resource identifiers, operation types, etc. that the tenants need to access, and may also contain credentials for authentication (such as tokens, usernames / passwords, etc.). The system first parses the request message and extracts data related to tenant authentication. This data may directly contain the tenant's identity information (such as tenant ID, username, etc.), or may require further processing (such as verifying the validity of the token) to obtain it indirectly. The system uses the extracted tenant identity information as a query condition to search the database for matching target tenant records. This database may contain information about all tenants, including but not limited to tenant ID, username, password hash, associated rental information, permissions, etc.

[0090] The query process may involve associated queries between multiple tables, especially when it is necessary to obtain source information associated with the tenant. If the matching target tenant identity information is found, the system will proceed to the next step; if not found, it may return an error response, indicating that the tenant identity information is invalid or does not exist. Once the identity information of the target tenant is determined, the system can use this information to find and determine the resource information corresponding to the tenant. This resource information may include services, data, configurations, etc. that the tenant can access. The process of finding resource information may involve access rights checks to ensure that tenants can only access authorized resources. Finally, the system will perform corresponding operations (such as providing data, executing services, etc.) based on the tenant's request and resource information, and return the results to the tenant.

[0091] In this embodiment, by accurately identifying the tenant identity information in the request message and searching the database for matching target tenant identity information, the system ensures that the correct resources are allocated to the tenant. This precise resource allocation helps avoid resource confusion or misuse, improving resource utilization efficiency. Tenants can quickly obtain the resource information they need without going through tedious verification or query processes. This efficient and convenient service experience helps improve user satisfaction and loyalty.

[0092] Figure 8This is a brief flowchart of tenant information storage in an exemplary application scenario. In the application scenario shown in Figure 8, the client sends a request message carrying tenant identity information to the server. After receiving the request message, the server detects whether the request message contains tenant identity information through the business gateway; if the request message does not contain tenant identity information, an error response message is returned to the client. If the business platform detects valid tenant identity information from the request message, the valid tenant identity information is bound to the context of the current thread to obtain a variable area storage object. Then, the variable area storage object is monitored to obtain the monitoring result, and the valid tenant identity information is obtained from the variable area storage object based on the monitoring result. The value of the corresponding entity field is generated based on the valid tenant identity information. When the entity is persisted, the value of the entity field is obtained; the value of the entity field is set to the target field corresponding to the entity to obtain the target data, and the valid tenant identity information is stored in the database based on the target data. For the detailed implementation process, please refer to the records in the aforementioned embodiments, and no further details will be given here.

[0093] Figure 9 This is a block diagram of a tenant information storage device shown in an exemplary embodiment of the present application. The device can be applied to Figure 1 The implementation environment shown in FIG. 1 is specifically configured in the server 110. The apparatus may also be applicable to other exemplary implementation environments and specifically configured in other devices. This embodiment does not limit the implementation environment to which the apparatus is applicable.

[0094] like Figure 9 As shown, the exemplary tenant information storage device includes: a receiving module 910, which is used to receive a request message sent by a client, and the request message carries tenant identity information; a forwarding module 920, which is used to forward the request message to the business platform if it is detected that the tenant identity information is valid tenant identity information; an encapsulation module 930, which is used to encapsulate the valid tenant identity information into a variable area storage object through the business platform; and a storage module 940, which is used to store the valid tenant identity information in the database based on the variable area storage object when the entity is persisted.

[0095] According to one aspect of an embodiment of the present application, the above-mentioned tenant information storage device also includes: a monitoring module, which is used to monitor operations for entity persistence and obtain monitoring results; an acquisition module, which is used to obtain valid tenant identity information from the object saved in the variable area based on the monitoring results; and a generation module, which is used to generate the value of the corresponding entity field based on the tenant identity information to synchronize and persist the tenant identity.

[0096] According to one aspect of an embodiment of the present application, the above-mentioned storage module 940 is also used to: obtain the value of the entity field when the entity is persisted; set the value of the entity field to the target field corresponding to the entity to obtain the target data; and store the valid tenant identity identification information in the database based on the target data.

[0097] According to one aspect of an embodiment of the present application, the above-mentioned encapsulation module 930 is also used to bind the valid tenant identity information to the context of the current thread if the business platform detects valid tenant identity information from the request message to obtain a variable area storage object.

[0098] According to one aspect of an embodiment of the present application, the above-mentioned encapsulation module 930 is also used to define a request header context category and obtain the context object of the current thread based on the context category; encapsulate the valid tenant identity identification information into a context object and save it to the current thread storage to obtain a variable area storage object.

[0099] According to one aspect of an embodiment of the present application, the above-mentioned tenant information storage device also includes: a detection module, which is used to detect whether the request message contains tenant identity identification information through the service gateway; and a sending module, which is used to return an error response message to the client if the request message does not contain tenant identity identification information.

[0100] According to one aspect of an embodiment of the present application, the above-mentioned tenant information storage device also includes: a response module, which is used to respond to the request message sent by the tenant and determine the tenant identity information corresponding to the rental based on the request message; a search module, which is used to search for matching target tenant identity information from the database based on the tenant identity information; and a determination module, which is used to determine the resource information corresponding to the tenant based on the target tenant identity information shown.

[0101] It should be noted that the tenant information storage device provided in the above embodiment and the tenant information storage method provided in the above embodiment are based on the same concept. The specific manner in which each module and unit performs operations has been described in detail in the method embodiment and will not be repeated here. In actual applications, the tenant information storage device provided in the above embodiment can, as needed, allocate the above functions to different functional modules, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.

[0102] An embodiment of the present application also provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by one or more processors, the electronic device implements the tenant information storage method provided in the above-mentioned embodiments.

[0103] Figure 10The following is a schematic diagram showing the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application. Figure 10 The computer system 1000 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0104] like Figure 10 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage part 1008 into the random access memory (RAM) 1003, such as executing the method in the above embodiment. Various programs and data required for system operation are also stored in the RAM 1003. The CPU 1001, ROM 1002 and RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.

[0105] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, and the like; an output section 1007 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 1008 including a hard disk and the like; and a communication section 1009 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. Removable media 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1010 as needed, so that computer programs read therefrom can be installed into the storage section 1008 as needed.

[0106] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1009, and / or installed from a removable medium 1011. When the computer program is executed by the central processing unit (CPU) 1001, the various functions defined in the system of the present application are executed.

[0107] It should be noted that the computer-readable medium shown in the embodiments of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable computer program. This propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. A computer program embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or any suitable combination thereof.

[0108] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, program segment, or part of the code, and the above-mentioned module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0109] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. In some cases, the names of these units do not constitute limitations on the units themselves.

[0110] Another aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the tenant information storage method described above. The computer-readable storage medium may be included in the electronic device described in the above embodiments, or may exist independently and not be incorporated into the electronic device.

[0111] Another aspect of the present application provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the tenant information storage method provided in each of the above embodiments.

[0112] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. Ordinary technicians in this field can easily make corresponding changes or modifications based on the main ideas and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.

Claims

1. A tenant information storage method, characterized in that: include: Receive a request message sent by a client, wherein the request message carries tenant identity information; If it is detected that the tenant identity information is valid tenant identity information, forwarding the request message to the service platform; If the business platform detects valid tenant identity information from the request message, it defines a request header context category and obtains a context object of the current thread based on the context category; Encapsulating the valid tenant identity information into a context object and saving it to the current thread storage to obtain a variable area storage object; According to the monitoring result of the entity persistence operation, when the entity is persisted, the valid tenant identity information is stored in the database based on the variable area storage object.

2. The method according to claim 1, wherein The method further comprises: Monitor the operations on entity persistence and obtain the monitoring results; Based on the monitoring result, the valid tenant identity information is obtained from the object stored in the variable area; The value of the corresponding entity field is generated based on the tenant identity information to synchronize and persist the tenant identity.

3. The method according to claim 2, wherein The method further comprises: When the entity is persisted, the value of the entity field is obtained; Setting the value of the entity field to the target field corresponding to the entity to obtain target data; The valid tenant identity information is stored in a database based on the target data.

4. The method according to claim 1, wherein The method further comprises: Detecting, by the service gateway, whether the request message contains tenant identity information; If the request message does not include tenant identity information, an error response message is returned to the client.

5. The method according to claim 1, wherein After storing the valid tenant identity information in the database based on the variable area storage object, the method further includes: In response to a request message sent by a tenant, determining tenant identity information corresponding to the tenant based on the request message; searching the database for matching target tenant identity information based on the tenant identity information; Determine resource information corresponding to the tenant based on the target tenant identity information.

6. A tenant information storage device, characterized in that: The device comprises: A receiving module, configured to receive a request message sent by a client, wherein the request message carries tenant identity information; a forwarding module, configured to forward the request message to the service platform if it is detected that the tenant identity information is valid tenant identity information; an encapsulation module configured to, if the business platform detects valid tenant identity information from the request message, define a request header context category and obtain a context object for the current thread based on the context category; encapsulate the valid tenant identity information into a context object and save it to the current thread storage to obtain a variable area storage object; The storage module is used to store the valid tenant identity information in a database based on the variable area storage object when the entity is persisted according to the monitoring result of the entity persistence operation.

7. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the electronic device to implement the tenant information storage method as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the tenant information storage method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data isolation method and system for multi-tenant platform based on micro-service architecture

    CN115391828A

  • Tenant management method and device for distributed database and readable storage medium

    CN117932645A