A cloud pharmacy multi-source heterogeneous data unified access and security access control method and system

By configuring independent data sources and a three-layer interceptor chain for multiple business domains of the cloud pharmacy system, the problems of poor isolation and insufficient security access control of multi-source heterogeneous data are solved, achieving efficient and unified control of data isolation and secure access, and simplifying system expansion and maintenance.

CN123145014APending Publication Date: 2026-11-20SICHUAN SHENIAO SHANGYI CLOUD TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611315287.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-27
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In existing cloud pharmacy systems, the physical and logical mixing of multi-source heterogeneous data leads to poor data isolation, high risk of single point of failure, and a lack of unified security access control mechanism. When adding new data sources or connecting to external systems, the configuration is complex and maintenance is difficult.

Method used

Configure independent data sources for multiple business domains of the cloud pharmacy server, and configure a corresponding database session factory and transaction manager for each data source. Bind database operations through mapper scanning annotations. Set up a three-layer interceptor chain at the server entry point to perform version verification, user request verification and signature verification to achieve data isolation and secure access control.

Benefits of technology

It achieves data isolation across business domains, reduces the risk of single points of failure, enhances the strength of security access control, simplifies the process of adding new data sources or connecting to external systems, and supports rapid response and horizontal scaling in high-concurrency scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123145014A_ABST
    Figure CN123145014A_ABST
Patent Text Reader

Abstract

The present application relates to the field of computer software development and information security technology, in particular to a cloud pharmacy multi-source heterogeneous data unified access and security access control method and system, independent data sources, database session factories and transaction managers are respectively configured for business domains such as internet hospitals, B2B procurement, pharmacy inventory, appointment registration and the like in the cloud pharmacy server, the mapper interface package paths of each business domain are bound to the corresponding database session factory through the mapper scanning annotation, a three-layer interceptor chain is set, the version checking interceptor queries the version information table according to the client identifier, checks whether the server version number matches, the user request interceptor checks the validity of the access credential in the memory database and injects the user context, and the signature checking interceptor compares the timestamp and the digest value of the key, after the check, the corresponding mapper is called according to the business domain to execute the database operation. The present application solves the problems of poor isolation of multi-source heterogeneous data and high single-point failure risk.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of computer software development and information security technology, specifically to a method and system for unified access and secure access control of multi-source heterogeneous data in cloud pharmacies. Background Technology

[0002] In the field of pharmaceutical IT, cloud pharmacy systems typically need to connect to multiple heterogeneous systems, such as internet hospitals, pharmacy inventory management systems, business-to-business (B2B) procurement platforms, third-party payment platforms, and decoction delivery platforms. The business data generated by these systems is often stored in different types of databases, such as multiple open-source relational databases like MySQL and PostgreSQL, as well as commercial relational databases like Microsoft SQL Server.

[0003] Existing technologies typically address the above problems in the following two ways: The first model is the "single data source + unified authentication" model, where the entire cloud pharmacy system is configured with only one master database. All business modules share the same data source, Structured Query Language (SQL) session factory, and transaction manager, while unified login authentication is performed at the application gateway or controller layer. This model results in data from different business domains being completely mixed physically and logically. Internet hospital prescription data, purchase order data, payment transaction data, and decoction delivery data are all stored in the same database. Once this database fails or is attacked, the core business of the entire cloud pharmacy system will be affected, and it is difficult to implement differentiated permission isolation and backup strategies between different data sources.

[0004] The second approach is the "simple multi-data source configuration" model, which configures data sources separately for different business modules. However, it lacks a unified layered design for security mechanisms such as interceptor chains, access credential verification, and signature verification, often implemented independently by each interface or module. This model lacks a unified security access control layer. Existing solutions typically perform simple access credential verification in only one interceptor or filter, failing to perform layered and phased verification of client version, user identity, and request signature. For example, an expired client app may still access the server interface; the lack of signature verification or the vulnerability of signatures to replay attacks allows unauthorized third parties to forge requests; and inconsistent exception handling after access credential verification failures can easily leak internal error information.

[0005] Furthermore, when dealing with new data sources or new external system connections, existing technologies require extensive copying and pasting of configuration classes, mapper scan paths, transaction managers, and pagination plugins, leading to configuration bloat, maintenance difficulties, and a high risk of data source confusion or transaction failure due to configuration errors. Summary of the Invention

[0006] In order to overcome the above-mentioned technical problems in the prior art, the present invention provides a unified access and secure access control method and system for multi-source heterogeneous data in cloud pharmacies. It solves the problems of poor data isolation and high risk of single point of failure caused by the physical and logical mixing of data from different business domains. It also solves the problems of insufficient security verification strength caused by the lack of a unified hierarchical secure access control mechanism and the problems of complex configuration and difficult maintenance when adding new data sources or external systems.

[0007] To achieve the above objectives, embodiments of the present invention provide a method for unified access and secure access control of multi-source heterogeneous data in a cloud pharmacy, comprising: configuring independent data sources for multiple business domains in the cloud pharmacy server, the multiple business domains including an internet hospital business domain, a business-to-business procurement business domain, a pharmacy inventory management business domain, and an appointment registration business domain; configuring a corresponding database session factory and transaction manager for each data source, and binding the mapper interface package path of each business domain to the corresponding database session factory through mapper scanning annotations, so that database operations of different business domains are bound to their respective dedicated data sources at compile time; setting up a three-layer interceptor chain at the cloud pharmacy server entry point, and verifying client requests in the following order: the first-layer version verification interceptor: reading the client identifier and server version number in the request header, and querying based on the client identifier. The system consists of three layers: a version information table, a version number table, and a user request interceptor. The first layer checks if the server version number carried in the request matches the version number published in the database. If they don't match, the request is blocked. The second layer extracts access credentials from the authorization field of the request header, checks if the credentials exist in the in-memory database, and if so, retrieves the login user information corresponding to the credentials from the database and injects it into the thread context. The third layer reads the system signature and system timestamp from the request header, calculates the digest value of the timestamp and key using the key configured on the server, and compares it with the system signature. If they don't match, the request is blocked. After successful verification, the system performs database operations by calling the mapper interface of the corresponding business domain, based on the business domain of the request, thus storing data from different business domains in heterogeneous databases.

[0008] Preferably, configuring a corresponding database session factory and transaction manager for each data source includes: declaring three managed components—the main data source, the main database session factory, and the main transaction manager—in the main data source configuration class; declaring the enterprise-to-enterprise data source, the enterprise-to-enterprise database session factory, and the enterprise-to-enterprise transaction manager in the enterprise-to-enterprise data source configuration class; and independently loading the mapper configuration file under the corresponding mapper package path for each database session factory.

[0009] Preferably, the method further includes configuring an independent pagination plugin for each data source based on the database type corresponding to each data source.

[0010] Preferably, in the user request interceptor, verifying whether the access credential exists in the memory database includes: constructing a first memory database key: an access credential validity identifier prefix plus the access credential; constructing a second memory database key: a cloud pharmacy access credential prefix plus the access credential; first verifying whether the first memory database key exists in the memory database, then verifying whether the second memory database key exists in the memory database; if either does not exist, an authentication failure exception is thrown.

[0011] Preferably, obtaining the login user information corresponding to the access credential from the memory database includes: deserializing the login user object from the value corresponding to the key in the second memory database, and writing the login user object into a thread-local variable of the user context container.

[0012] Preferably, it also includes a logout step: when actively logging out or forcibly logging off, the first memory database key, the second memory database key, and all associated keys are deleted simultaneously.

[0013] Preferably, the signature verification interceptor further includes time window verification: obtaining the system timestamp carried in the request, comparing it with the current server time, and rejecting the request if the difference exceeds a preset threshold.

[0014] Preferably, the signature verification interceptor further includes random number anti-replay verification: obtaining the random number carried in the request, querying the memory database to see if the random number has been used, and rejecting the request if it has been used; if it has not been used, storing the random number in the memory database and setting an expiration period.

[0015] Preferably, the three-layer interceptor chain is registered through an interceptor configuration class, the version verification interceptor is executed first with a sequence number of 1, and the user request interceptor and the signature verification interceptor are executed sequentially according to the registration order; when adding a new interceptor, it is embedded at any position in the three-layer interceptor chain by setting a sequence number.

[0016] Accordingly, the present invention also provides a unified access and secure access control system for multi-source heterogeneous data in cloud pharmacies, comprising: a multi-data source configuration module, used to configure independent data sources, database session factories, and transaction managers for multiple business domains in the cloud pharmacy server, and to bind the mapper interface package path of each business domain to the corresponding database session factory through mapper scanning annotations, so that database operations of different business domains are bound to their respective exclusive data sources at compile time; a three-layer interceptor chain module, set at the entry point of the cloud pharmacy server, including a version verification interceptor, a user request interceptor, and a signature verification interceptor, which sequentially performs version verification, access credential authentication, and request signature verification on client requests; and a data source routing module, used to, after the three-layer interceptor chain module has passed the verification, route the database operation to the corresponding data source by calling the mapper interface of the corresponding business domain according to the business domain corresponding to the request.

[0017] The present invention has at least the following technical effects through the technical solution provided by the present invention: This invention, by independently configuring DataSource, SqlSessionFactory, TransactionManager, and pagination plugins for each data source, allows data from different business domains such as internet hospitals, B2B procurement, pharmacy inventory management systems, and appointment registration to be stored in heterogeneous databases, including multiple open-source relational databases and Microsoft relational databases. This ensures business isolation (failure of any data source does not affect other business domains) and achieves unified server-side access, enabling unified access and isolation of multi-source heterogeneous data. A three-layer interceptor chain decouples version verification, identity authentication, and signature verification into different processing stages, with each layer responsible for a single security function, facilitating independent maintenance and upgrades. Compared to single-interceptor solutions, this invention effectively intercepts expired clients, invalid access credentials, and forged signature requests. The dual-key in-memory database structure separates "credential validity" from "user identity information." Forced logout / forced offline operations do not require loading and deserializing large user objects; simply deleting a lightweight valid identifier key is sufficient to invalidate the user. In high-concurrency scenarios, this significantly reduces the read I / O overhead and cross-network transmission latency of the in-memory database, significantly improving the strength of secure access control. Distributed session management based on the in-memory database (Redis) enables multi-instance deployment of the server, with access credential status shared among instances. The signature time window and random number mechanism effectively resist replay attacks, meeting the high security and compliance requirements of healthcare systems and providing excellent horizontal scalability. When adding a new data source, only a new configuration class similar to the main data source configuration class needs to be added, specifying an independent mapper package path, SqlSessionFactory reference, and TransactionManager name, to achieve isolation from existing data sources and avoid configuration conflicts. Adding interceptors also only requires implementing the HandlerInterceptor interface and registering it in the configuration class; they can be embedded in any position using sequential numbering, adhering to the design principle of "open to extension, closed to modification," reducing the cost of integrating new data sources and external systems. Attached Figure Description

[0018] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings: Figure 1 This is the complete business process of a unified access and secure access control method for multi-source heterogeneous data in a cloud pharmacy provided by an embodiment of the present invention; Figure 2 This is a block diagram of a cloud pharmacy multi-source heterogeneous data unified access and secure access control system provided in an embodiment of the present invention. Detailed Implementation

[0019] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.

[0020] In this invention, the terms "system" and "network" are used interchangeably. "Multiple" refers to two or more; therefore, in this invention, "multiple" can also be understood as "at least two." "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Additionally, the character " / ", unless otherwise specified, generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, it should be understood that in the description of this invention, terms such as "first" and "second" are used only for descriptive purposes and should not be construed as indicating or implying relative importance or order.

[0021] This invention provides a method for unified access and secure access control of multi-source heterogeneous data in a cloud pharmacy, comprising: configuring independent data sources for multiple business domains in the cloud pharmacy server, including an internet hospital business domain, a business-to-business procurement business domain, a pharmacy inventory management business domain, and an appointment registration business domain; configuring a corresponding database session factory and transaction manager for each data source, and binding the mapper interface package path of each business domain to the corresponding database session factory through mapper scanning annotations, so that database operations of different business domains are bound to their respective dedicated data sources at compile time; setting up a three-layer interceptor chain at the cloud pharmacy server entry point, and verifying client requests in the following order: the first-layer version verification interceptor reads the client identifier and server version number in the request header, and queries the version information based on the client identifier. The first layer checks if the server version number carried in the request matches the version number published in the database. If they don't match, the request is blocked. The second layer is a user request interceptor: it extracts access credentials from the authorization field of the request header, checks if the access credentials exist in the in-memory database, and if they do, retrieves the login user information corresponding to the access credentials from the in-memory database and injects the login user information into the thread context. The third layer is a signature verification interceptor: it reads the system signature and system timestamp from the request header, calculates the digest value of the timestamp and key using the key configured on the server, and compares it with the system signature. If they don't match, the request is blocked. After successful verification, based on the business domain corresponding to the request, it performs database operations by calling the mapper interface of the corresponding business domain, so that data from different business domains are stored in heterogeneous databases.

[0022] In this embodiment of the invention, independent configuration of multiple data sources is first performed. In view of the current situation in cloud pharmacy business where multiple open source relational databases and Microsoft relational databases exist at the same time, this invention independently configures the data source (DataSource), database session factory (SqlSessionFactory), and transaction manager (TransactionManager) for each data source.

[0023] In one feasible implementation, we will take the example of a cloud pharmacy server simultaneously integrating internet hospital services, B2B procurement services, pharmacy inventory management, and appointment booking services. In the cloud pharmacy server, each business domain is configured with an independent data source, database session factory, and transaction manager. Each data source configuration class is annotated with configuration annotations, and the mapper interface package path and database session factory reference corresponding to that data source are specified through mapper scan annotations (such as @MapperScan).

[0024] Taking the primary data source configuration as an example: The primary data source configuration class declares three managed components: the primary data source, the primary database session factory, and the primary transaction manager. The mapper scan path of the primary database session factory points to the mapper interface package of the primary business domain (Internet Hospital business). The primary transaction manager is bound to the primary data source, ensuring that database operations in the primary business domain are executed within the transaction context corresponding to the primary data source. The B2B data source configuration class declares a B2B data source, a B2B database session factory, and a B2B transaction manager. The mapper scan path of the B2B database session factory points to the mapper interface package of the B2B procurement business domain. The B2B transaction manager is bound to the B2B data source, ensuring that database operations in the B2B procurement business domain are executed within the transaction context corresponding to the B2B data source.

[0025] Specifically, the structures of the pharmacy inventory management data source configuration class and the appointment registration data source configuration class are similar to those described above, each specifying its own independent mapper package path, database session factory reference, and transaction manager name. Each database session factory independently loads the mapper configuration file (i.e., the SQL mapping file) under its corresponding package path, avoiding the overwriting of SQL mappings from different data sources. In other words, the main database session factory only loads the configuration file under the main mapper package path, the B2B database session factory only loads the configuration file under the B2B mapper package path, and so on.

[0026] Furthermore, each data source is configured with an independent pagination plugin based on its database type: the main data source uses a pagination interception plugin for an open-source relational database (database type set to open-source relational database), and the B2B data source also uses the same plugin (database type set to open-source relational database). If a Microsoft relational database is subsequently introduced as a new data source, a pagination interception plugin suitable for Microsoft relational databases is configured for that new data source (database type set to Microsoft relational database). This ensures that pagination queries can be correctly executed by each data source in a multi-source heterogeneous environment.

[0027] In this embodiment of the invention, a three-layer interceptor chain is set up at the cloud pharmacy server entry point, executed in sequence: version verification interceptor → user request interceptor → signature verification interceptor. Specifically, the first-layer version verification interceptor is responsible for client version compatibility verification. This interceptor reads the client identifier (e.g., Client-Type), server version (e.g., Server-Version), and service group field from the request header. The second-layer user request interceptor is responsible for user authentication and context injection. This interceptor extracts the holder's access credential (Token) from the authorization field (e.g., Authorization) in the request header. The third-layer signature verification interceptor is responsible for request signature verification. This interceptor reads the system signature (e.g., X-Sign) and system timestamp (e.g., X-Timestamp) from the request header, uses the key configured on the server to calculate the digest value of "timestamp + key" using a digest algorithm (e.g., SHA-256 or MD5), and performs a case-insensitive comparison with the system signature. If the signatures do not match, an authentication failure exception is thrown.

[0028] Specifically, all three interceptors are registered through the interceptor configuration class, theoretically covering all requests (including static resources and health check endpoints). However, two "exemption / no-pass" mechanisms ensure that they are actually unaffected by the three-layer authentication: (1) The version verification interceptor allows the request to pass directly when the "client identifier" header is empty. Static resources and health checks usually do not have a client identifier header, so version verification is ineffective for them.

[0029] (2) The user request interceptor excludes endpoints that do not require login, such as interface documentation tools, error pages, website icons, interface documentation addresses, third-party callback addresses, login / sending SMS messages, etc., by using the "exclusion address whitelist".

[0030] Therefore, static resources are naturally not intercepted by the three-layer authentication; if health checks need to be skipped, simply add their paths to the excluded address whitelist. In terms of performance, all three layers of interceptors are in-memory database existence checks or string comparisons, with minimal overhead and no bottleneck. This invention employs a registration-based interceptor chain based on a network view configurator, with the order determined by both the "sequence number" and the registration order: the version verification interceptor, with sequence number 1, executes first; the user request interceptor and signature verification interceptor follow in registration order. Adding a new interceptor (such as an address blacklist / whitelist filtering interceptor) requires no modification to any existing interceptor code, only two steps: first, add a component implementing the processor interceptor; second, add the registration to the registration method of the interceptor configuration class, embedding it in any position by adjusting the sequence number value (e.g., sequence number 0 is inserted before version verification, and sequence number 2 is inserted between user and signature verification). This conforms to the design principle of "open to extension, closed to modification," and the new interceptor is completely decoupled from the existing three layers.

[0031] In one implementation, a three-layer interceptor chain is set at the entry point of the cloud pharmacy server, executing sequentially: version verification interceptor → user request interceptor → signature verification interceptor. Specifically, the version verification interceptor reads the client identifier, server version, and service group fields from the HTTP request header. When the client identifier is "Mini Program," it queries the version information table for records with version type 1, status 1, and matching service group; when the client identifier is "Web Page," it queries the version information table for records with version type 2. If the server version number carried in the request is inconsistent with the version number published in the database, a version error exception is thrown, preventing expired clients from continuing to access the service. If the client identifier in the request header is empty (e.g., for static resource requests), the request is allowed directly without version verification. The user request interceptor extracts the holder's access credentials from the authorization field of the HTTP request header. Two in-memory database (e.g., Redis) keys are constructed: the first key is prefixed with "valid access credential identifier" plus the access credential (e.g., token:valid:{token}), and the second key is prefixed with "cloud pharmacy access credential" plus the access credential (e.g., cloud:token:{token}). First, the system checks if the first key exists in the in-memory database, then checks if the second key exists in the in-memory database; if either does not exist, an authentication failure exception is thrown. If both keys exist, the logged-in user object is deserialized from the value corresponding to the second key and written to a thread-local variable (ThreadLocal) of the user context container for use by subsequent business logic (such as permission checks, operation log recording, etc.). Then, the system calls the physician information verification method provided by the clinic service to check if the current physician has been deleted; if deleted, the logout method is executed and an authentication exception is thrown. This user request interceptor also excludes endpoints that do not require login by using an address whitelist, including: API documentation tool addresses, error page addresses, website icon addresses, API documentation addresses, third-party callback addresses, login addresses, SMS sending addresses, etc. The signature verification interceptor reads the system signature and system timestamp from the HTTP request header. Using the key configured on the server, it calculates the digest value of the digest algorithm (timestamp + key) and compares the result with the system signature carried in the request in a case-insensitive manner. If the comparison is inconsistent, an authentication failure exception is thrown.

[0032] Furthermore, all three interceptors are registered via interceptor configuration classes, theoretically covering all requests (including static resources and health check endpoints). As mentioned earlier, the version verification interceptor allows requests with empty client identifiers directly; the user request interceptor does not perform authentication verification on requests from the excluded address whitelist. Therefore, static resources are naturally not intercepted by the three-layer authentication, and if health checks need to be skipped, their paths only need to be added to the excluded address whitelist. All three interceptors perform in-memory database existence checks or string comparison operations, with minimal overhead and do not constitute a performance bottleneck.

[0033] The interceptor chain in this implementation scheme supports flexible expansion. Adding a new interceptor (e.g., adding an address blacklist / whitelist filtering interceptor) requires no modification to any existing interceptor code, only two steps: First, add a component that implements the processor interceptor interface (e.g., the address filtering interceptor); second, register the new interceptor in the registration method of the interceptor configuration class, embedding it in any position by setting its sequence number (e.g., setting the sequence number to 0 allows insertion before the version verification interceptor, and setting the sequence number to 2 allows insertion between the user request interceptor and the signature verification interceptor). This approach conforms to the design principle of "open to extension, closed to modification," completely decoupling the new interceptor from the existing three components.

[0034] In this embodiment of the invention, a two-key structure is used to manage distributed sessions in an in-memory database (such as Redis). Access credentials are stored in the in-memory database using two keys: The first key is a "valid access credential identifier" prefixed with the access credential itself, used only to identify whether the access credential is valid; it is a very lightweight key (e.g., token:valid:{token}, a lightweight validity marker); the second key is a "cloud pharmacy access credential" prefixed with the access credential itself, storing the serialized complete logged-in user object (including user ID, username, role, permission list, physician information, etc.) (e.g., cloud:token:{token}), used to store the logged-in user information (the complete logged-in user object). The two keys are associated with the same credential identifier. The management of the two keys is divided into three phases: (1) Writing timing: After a user successfully logs in, two keys are created in the in-memory database (Redis) during the token issuance process: the first key is set to a simple valid token value (lightweight valid token), and the second key stores the serialized complete logged-in user object. Both keys are set to the same expiration time; the two keys are associated with the same credential identifier and are written in simultaneously upon successful login.

[0035] (2) Reading timing: When the user request interceptor verifies, it first checks whether the first key (access credential validity identifier key) exists—this operation is a constant-level (O(1)) Redis existence check, which is extremely efficient; only when the first key exists does it continue to check the existence of the second key (cloud pharmacy access credential key), and deserializes the logged-in user object from the second key and writes it to the thread-local variable of the user context container. The two-level short-circuit verification logic ensures that invalid credentials are rejected in the first step without loading the user object.

[0036] (3) Deletion timing: When actively logging out or being forcibly offline, the logout method deletes the first key, the second key, and all associated keys (such as the refresh certificate key, the authentication certificate key, etc.). There is no path to delete only one key. In addition, the doctor information verification method will also trigger the logout method when it finds that the doctor has been forcibly deleted or disabled, and will clear the first key and the second key together.

[0037] In the scenario of "administrator deleting doctor in the backend", the single-key solution (using only the second key to store complete user information) requires the complete user object to be deserialized before its status fields (such as whether it is disabled) can be read, and then it is necessary to determine whether to allow the deletion. This results in overhead for object loading, in-memory database reading, and network transmission. In contrast, the dual-key solution separates "whether it is valid" from "who it is": the first key is only used as a Boolean valid marker. When the administrator forces the user offline, they only need to delete this lightweight key. The next request will immediately become invalid at a constant level (O(1)) in the first step (existence check), without any need to load and deserialize the user object. Since the cloud pharmacy server may be deployed in a multi-instance manner, using in-memory database storage can avoid the problem of single-machine session sharing and support horizontal scaling.

[0038] Furthermore, the core value of the two-key structure lies in decoupling "credential validity" from "user identity information." In a single-key scheme (using only the second key to store complete user information), in a scenario like "administrator deleting a doctor in the backend," the complete user object must be deserialized before its status fields (such as whether it's disabled) can be read to determine whether to allow access, incurring overhead from object loading, Redis reads, and network transmission. This two-key scheme separates "validity" from "who it is": an administrator forcibly takes a doctor offline by deleting the lightweight first key (the access credential validity identifier key). Subsequent requests immediately become invalid at a constant level in the first step (existence check), completely eliminating the need to load and deserialize the user object. In high-concurrency scenarios, a large number of requests can be quickly allowed or denied simply by checking the existence of the lightweight key, avoiding the performance overhead of fetching and deserializing the complete user object each time. Since the cloud pharmacy server may be deployed in a multi-instance manner, using Redis to store session state avoids the problem of single-machine session sharing and supports horizontal scaling.

[0039] In this embodiment of the invention, a signature replay prevention mechanism is also included. In the signature verification interceptor, the signature is generated jointly by the timestamp and the key (Signature = DigestAlgorithm(timestamp + secret)), that is, the system signature equals the digest algorithm (system timestamp + key). The client request carries the system signature and system timestamp. The server recalculates the digest value and compares it with the signature carried in the request, ensuring that someone who does not know the key cannot forge a legitimate signature. While comparing the signature, the server can further perform window verification between the system timestamp and the current server time (e.g., the difference does not exceed a certain number of minutes) and introduce a random number (Nonce). The used random number is recorded through the existence setting command of the in-memory database or the bucket object of the distributed cooperative lock based on the in-memory database, preventing attackers from intercepting a valid signature and replaying it indefinitely. Time window verification and random number deduplication are used in conjunction: the time window limits the lifespan of the random number set to avoid the set from expanding indefinitely; the random number prevents replay within the window. The random number set is automatically recycled according to the lifespan set of the key-value bucket (equal to the time window length). If the in-memory database crashes and the random number set is lost, only a very small number of old signatures are temporarily allowed to be replayed within a time window after restarting. The attack window is strictly limited by the time window (not exceeding a few minutes), and constructing a new signature still requires a key, so the risk is controllable.

[0040] Based on this, the embodiments of the present invention also provide the following enhanced designs: Time window verification: The server obtains the system timestamp carried in the request and compares it with the current server time. If the difference exceeds a preset threshold (e.g., several minutes), the request is rejected directly. Legitimate client retries occurring within the time window belong to the same request (using random number deduplication to ensure idempotency). Attackers replaying old signatures are rejected due to expired timestamps.

[0041] Random number replay prevention: A nonce is introduced, with each client carrying a unique nonce in every request. The server uses an in-memory database to record the "used nonce → expiration time". If a nonce is reused within its validity period, the request is rejected. Time window validation and nonce deduplication work together: A time window limits the lifespan of the nonce set, preventing it from growing indefinitely; replay protection is implemented within the nonce window. The nonce set is automatically recycled according to the key-value bucket's set lifespan (equal to the time window length).

[0042] If the in-memory database crashes and the random number set is lost, only a very small number of old signatures are temporarily allowed to be replayed within a time window after restarting. The attack window is strictly limited by the time window (not exceeding a few minutes), and constructing a new signature still requires a key, so the risk is controllable.

[0043] Further, more robust enhancement solutions include: (1) replacing random number deduplication with a high-availability / cluster mode collaborative lock client (sentinel / cluster), or writing processed random numbers to a relational database / log for recovery after a crash; (2) also replacing pure memory random numbers with "sliding time window + processed request sequence number". In summary, the anti-replay mechanism is divided into three parts: "signature anti-forgery (implemented) + time window anti-expiration replay + random number anti-window replay (enhanced)", and a lifespan and high-availability deployment are set for the random number set to converge the risk of crash loss to a controlled time window. The three parts are "signature anti-forgery (implemented) + time window anti-expiration replay + random number anti-window replay (enhanced)", and a lifespan and high-availability deployment are set for the random number set to converge the risk of crash loss to a controlled time window.

[0044] like Figure 1 As shown in the embodiment of the present invention, a complete business process for a unified access and secure access control method for multi-source heterogeneous data in a cloud pharmacy includes the following steps: S1: The client (mini-program / web page) initiates a Hypertext Transfer Protocol (HTTP) request, carrying request header fields such as client identifier (e.g., Client-Type), server version (e.g., Server-Version), authorization fields (e.g., Authorization, containing the holder's access credentials), system signature (e.g., X-Sign), and system timestamp (e.g., X-Timestamp). Optionally, if enhanced replay protection is enabled, a random number (e.g., X-Nonce) is also carried.

[0045] S2: The version verification interceptor intercepts the request, queries the version information table based on the client identifier type, and verifies whether the server version number matches. If the client identifier is empty, the request is allowed directly. Specifically, when the client identifier is "Mini Program", the record in the version information table with version type 1, status 1, and matching service group is queried; when the client identifier is "Web", the record in the version information table with version type 2 is queried. If the server version number carried in the request is inconsistent with the version number published in the database, a version error exception is thrown, preventing expired clients from continuing to access the service. If the client identifier is empty (such as a static resource request), the request is allowed directly.

[0046] S3: The user request interceptor verifies the access credentials in the authorization field. It checks the existence of the first key (token:valid:{token}) and the second key (cloud:token:{token}) in the in-memory database. If they exist, the logged-in user object is deserialized from the second key and injected into the logged-in user context (ThreadLocal). If neither exists, an authentication failure exception is thrown. Then, it checks if the physician has been deleted. If deleted, it performs a logout and throws an authentication exception. Specifically, two in-memory database keys are constructed: the first key is prefixed with "valid access credential identifier" plus the access credential, and the second key is prefixed with "cloud pharmacy access credential" plus the access credential. First, it checks if the first key exists in the in-memory database, then it checks if the second key exists in the in-memory database; if neither exists, an authentication failure exception is thrown. If both keys exist, the logged-in user object is deserialized from the value corresponding to the second key and written to the thread-local variable of the user context container. Then, it calls the physician information verification method provided by the clinic service to check if the current physician has been deleted. If deleted, it performs a logout and throws an authentication exception. In addition, the user request interceptor also excludes endpoints that do not require login by excluding them from an address whitelist. Addresses in the whitelist are not subject to authentication verification.

[0047] S4: The signature verification interceptor verifies the system signature (by recalculating the digest value and performing a case-insensitive comparison with the signature carried in the request), and can add time window and random number anti-replay checks. Specifically, the signature verification interceptor reads the system signature and system timestamp from the request header, uses the key configured on the server to calculate the digest value of the digest algorithm (timestamp + key), and performs a case-insensitive comparison with the system signature. If the signatures do not match, an authentication failure exception is thrown. Optionally, further time window checks (comparing the system timestamp with the current server time; rejecting if the window is exceeded) and random number anti-replay checks (checking whether the random number has been used; if it has been used, rejecting; if not used, storing it in an in-memory database and setting an expiration date) are performed.

[0048] Current status (code implemented): In the signature verification interceptor, the system signature equals the digest algorithm (system timestamp + key). The request carries the system signature and system timestamp, and the server recalculates and compares them for consistency, ensuring that the key cannot be forged without knowledge of its identity.

[0049] Enhanced design – Time window verification: Compare the request system timestamp with the current server time (if the difference does not exceed a certain number of minutes), and reject the request directly if it exceeds the window. Legitimate client retries occurring within the window belong to the same request (using random number deduplication to ensure idempotency). Attackers replaying old signatures will be rejected due to expired timestamps.

[0050] Enhanced Design – Random Number Deduplication: Introduce random numbers, and the server uses an in-memory database existence setting command to record “used random number → effective expiration time” (this solution already has a similar paradigm: the collaborative lock client obtains the key-value bucket and calls the existence setting command with an expiration time), and duplicate random numbers in the window are directly rejected.

[0051] S5: After all three layers of interceptors pass verification, the request is routed to the corresponding data source (main data source / B2B data source / pharmacies inventory data source / appointment registration data source) based on its business domain, and the database operation is executed, ending the process. Specifically, data source routing is determined at the data access layer: the data source is used based on the business domain's mapper interface, regardless of the request address and without branching. Furthermore, this system establishes an independent configuration class for each data source, and each binds the "business domain mapper interface package" to its dedicated database session factory and data source through mapper scanning annotations. For example, the main business database (Internet hospital business) is bound to the data source and database session factory declared in the main data source configuration class; the B2B database (procurement business) is bound to the data source and database session factory declared in the B2B data source configuration class; the pharmacy inventory database is bound to the data source and database session factory declared in the pharmacy inventory data source configuration class; and the appointment registration database is bound to the data source and database session factory declared in the appointment registration data source configuration class. After a request enters the business controller, the controller calls the corresponding service layer method based on the business type. The service layer then performs database operations through the mapper interface of the corresponding business domain—the data source is determined by which package's mapper is called, and dependencies can be determined at compile time. Once the database operation is complete, the result is returned to the client, and the process ends.

[0052] In this embodiment of the invention, the three-layer interceptor chain can be merged into two layers or expanded to more layers. For example, version verification and identity authentication can be merged into one interceptor, or signature verification can be split into a timestamp verification interceptor and a random number verification interceptor. The order can also be adjusted according to business needs. For example, the signature verification interceptor can be placed before the user request interceptor.

[0053] Furthermore, multiple data source configurations can also employ dynamic data source routing (such as AbstractRoutingDataSource), dynamically switching based on the data source identifier in the thread context. This approach is suitable for scenarios with many reads and few writes, requiring dynamic data source selection based on requests. If dynamic routing is overlaid, the data source identifier in the thread-local variable is set at the request entry point by an interceptor (based on business domain / tenant / request header) or a custom data source identifier annotation. From a responsibility division perspective, it's more reasonable to set this identifier after the second layer (user request interceptor, i.e., after authentication and determination of the user's business domain)—because data source selection depends on the identified business domain / tenant, and there isn't sufficient context before authentication. When the mapper executes, the abstract route data source reads the identifier from the thread-local variable to select the data source, and the context is cleared after the business method execution.

[0054] For scenarios requiring simultaneous operations on two databases within a single business method (e.g., querying the B2B database first and then writing to the main database), static binding allows different business domain mappers to belong to different packages and each to its own dedicated data source. Calling mappers from different packages within the same method naturally enables multi-source operations without interference or runtime switching. In dynamic routing scenarios, data source identifiers can be explicitly specified at the method level using annotations, or programmatic switching can be employed (resetting thread-local variable identifiers before entering a certain logic segment and restoring them upon exit) to achieve cross-database operations within the method.

[0055] Regarding cross-database transactions, since strong consistency cannot be guaranteed by a single database transaction due to the heterogeneity of multiple sources, this solution adopts a strategy of local transactions at each source plus eventual consistency (such as message queues or compensation mechanisms). When necessary, idempotent design and retries are implemented for cross-database write operations, rather than forcing distributed transactions. The in-memory database distributed session can also be replaced with other caching systems that support distributed sharing (such as Memcached) or database session tables; the access credential structure can adopt a self-contained token form (such as JWT) to reduce the number of in-memory database queries, but additional design is required for access credential expiration and forced logout mechanisms (such as maintaining a blacklist).

[0056] Please see Figure 2 Based on the same inventive concept, embodiments of the present invention provide a unified access and secure access control system for multi-source heterogeneous data in cloud pharmacies, comprising: The multi-data source configuration module is used to configure independent data sources, database session factories, and transaction managers for multiple business domains in the cloud pharmacy server. It also binds the mapper interface package path of each business domain to the corresponding database session factory through mapper scanning annotation, so that the database operations of different business domains are bound to their respective exclusive data sources at compile time. The three-layer interceptor chain module is set at the cloud pharmacy server entry point. It includes a version verification interceptor, a user request interceptor, and a signature verification interceptor, which sequentially perform version verification, access credential authentication, and request signature verification on client requests. The data source routing module is used to route the database operation to the corresponding data source by calling the mapper interface of the corresponding business domain after the three-layer interceptor chain module has passed the verification.

[0057] In this embodiment of the invention, the data source routing is not hardcoded into the interceptor's branch judgment, but rather "bound to the persistence layer of the business domain (metadata-based mapping)". This system establishes an independent configuration class for each data source, and each binds the "business domain mapper interface package" to its dedicated database session factory and data source through mapper scanning annotations. Main business database (Internet hospital business) ← Main business database mapper package (main data source configuration class); B2B Library (Procurement Business) ← B2B Mapper Package (B2B Data Source Configuration Class); Pharmacy Inventory Management ← Pharmacy Inventory Mapper Package (Pharmacy Inventory Data Source Configuration Class); Appointment registration database ← Appointment registration mapper package (appointment registration data source configuration class).

[0058] Routing decisions occur at the data access layer: the data source is determined by which package's mapper is invoked, regardless of the request address and without requiring branching. Adding a new business domain only requires adding a mapper package and a data source configuration class, resulting in zero intrusion; changes in the request address do not affect routing, and dependencies can be determined at compile time.

[0059] Furthermore, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the present invention.

[0060] The optional embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the embodiments of the present invention are not limited to the specific details in the above embodiments. Within the scope of the technical concept of the embodiments of the present invention, various simple modifications can be made to the technical solutions of the embodiments of the present invention, and these simple modifications all fall within the protection scope of the embodiments of the present invention.

[0061] It should also be noted that the various specific technical features described in the above embodiments can be combined in any suitable manner without contradiction. To avoid unnecessary repetition, the embodiments of the present invention will not describe the various possible combinations separately.

[0062] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. This program is stored in a storage medium and includes several instructions to cause a microcontroller, chip, or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0063] Furthermore, various different implementations of the present invention can be combined arbitrarily, as long as they do not violate the spirit of the present invention, they should also be regarded as the content disclosed in the present invention.

Claims

1. A method for unified access and secure access control of multi-source heterogeneous data in a cloud pharmacy, characterized in that, include: Configure independent data sources for multiple business domains in the cloud pharmacy server. These multiple business domains include the Internet hospital business domain, the business domain for enterprise-to-enterprise procurement, the pharmacy inventory management business domain, and the appointment registration business domain. Configure a corresponding database session factory and transaction manager for each data source, and bind the mapper interface package path of each business domain to the corresponding database session factory through mapper scan annotation, so that the database operations of different business domains are bound to their respective exclusive data sources at compile time; A three-layer interceptor chain is set up at the cloud pharmacy server entry point to verify client requests in the following order: The first-level version verification interceptor reads the client identifier and server version number in the request header, queries the version information table based on the client identifier, and verifies whether the server version number carried in the request is consistent with the version number published in the database. If they are inconsistent, the request is blocked from continuing to access. The second-layer user request interceptor extracts access credentials from the authorization field of the request header, verifies whether the access credentials exist in the memory database, and if they exist, retrieves the login user information corresponding to the access credentials from the memory database and injects the login user information into the thread context. The third-layer signature verification interceptor reads the system signature and system timestamp from the request header, calculates the digest value of the timestamp and key using the key configured on the server, and compares it with the system signature. If the comparison is inconsistent, the request is blocked from continuing to access the system. After successful verification, database operations are performed by calling the mapper interface of the corresponding business domain according to the request, so that data from different business domains are stored in heterogeneous databases respectively.

2. The method according to claim 1, characterized in that, The step of configuring a corresponding database session factory and transaction manager for each of the data sources includes: In the main data source configuration class, declare three managed components: the main data source, the main database session factory, and the main transaction manager; In the enterprise-to-enterprise data source configuration class, declare the enterprise-to-enterprise data source, enterprise-to-enterprise database session factory, and enterprise-to-enterprise transaction manager; Each database session factory independently loads the mapper configuration file from the corresponding mapper package path.

3. The method according to claim 1, characterized in that, Also includes: Configure an independent pagination plugin for each data source based on the database type corresponding to each data source.

4. The method according to claim 1, characterized in that, In the user request interceptor, verifying whether the access credential exists in the in-memory database includes: Construct the first in-memory database key: add the access credential valid identifier prefix to the access credential; Construct a second in-memory database key: add the aforementioned access credential to the cloud pharmacy access credential prefix; First, check if the first memory database key exists in the memory database, then check if the second memory database key exists in the memory database; if either does not exist, an authentication failure exception is thrown.

5. The method according to claim 4, characterized in that, The step of retrieving the login user information corresponding to the access credential from the memory database includes: deserializing the login user object from the value corresponding to the key in the second memory database, and writing the login user object into the thread-local variable of the user context container.

6. The method according to claim 4, characterized in that, It also includes a logout step: when logging out voluntarily or being forcibly disconnected, the first memory database key, the second memory database key, and all associated keys are deleted simultaneously.

7. The method according to claim 1, characterized in that, The signature verification interceptor also includes time window verification: obtain the system timestamp carried in the request, compare it with the current server time, and if the difference exceeds a preset threshold, reject the request.

8. The method according to claim 7, characterized in that, The signature verification interceptor also includes random number anti-replay verification: obtain the random number carried in the request, query the memory database to see if the random number has been used, and if it has been used, reject the request; if it has not been used, store the random number in the memory database and set an expiration period.

9. The method according to claim 1, characterized in that, The three-layer interceptor chain is registered through the interceptor configuration class. The version verification interceptor, with sequence number 1, is executed first. The user request interceptor and the signature verification interceptor are executed sequentially according to the registration order. When a new interceptor is added, it is embedded at any position in the three-layer interceptor chain by setting its sequence number.

10. A unified access and secure access control system for multi-source heterogeneous data in a cloud pharmacy, characterized in that, include: The multi-data source configuration module is used to configure independent data sources, database session factories, and transaction managers for multiple business domains in the cloud pharmacy server. It also binds the mapper interface package path of each business domain to the corresponding database session factory through mapper scanning annotation, so that the database operations of different business domains are bound to their respective exclusive data sources at compile time. The three-layer interceptor chain module is set at the cloud pharmacy server entry point. It includes a version verification interceptor, a user request interceptor, and a signature verification interceptor, which sequentially perform version verification, access credential authentication, and request signature verification on client requests. The data source routing module is used to route the database operation to the corresponding data source by calling the mapper interface of the corresponding business domain after the three-layer interceptor chain module has passed the verification.