A long connection authentication method and system based on an interceptor chain
Patent Information
- Application Number
- CN202611174903.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-04
- Publication Date
- 2026-10-09
AI Technical Summary
旨在解决传统长连接鉴权方案存在的代码冗余、鉴权逻辑不一致、安全风险高以及可扩展性差等的问题
(1)在集中化管理方面,传统的嵌入式鉴权方案中,鉴权逻辑分散在各个业务模块中,每个业务模块都需要编写和维护自己的鉴权代码,这导致代码冗余严重,维护成本高。而基于拦截器链的鉴权方法将鉴权逻辑集中到拦截器框架中统一管理,业务模块只需关注自身的业务逻辑,无需关心鉴权细节。这不仅减少了代码量,提高了代码的可维护性,还使得鉴权策略的调整和更新更加方便快捷。在一个包含多个业务模块的系统中,传统方案可能需要在每个业务模块中修改鉴权代码,而基于拦截器链的方案只需在拦截器框架中进行一次修改,即可应用到所有相关业务模块。
Smart Images

Figure CN122891336A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of real-time long-connection communication technology, and more specifically to a long-connection authentication method and system based on an interceptor chain. Background Technology
[0002] In today's digital age, real-time data delivery plays a crucial role in the efficient operation of numerous fields. Long-connection communication protocols, as a key technology for achieving real-time data transmission, are widely used in scenarios such as financial transaction data updates, instant messaging, IoT device data reporting, and online game status synchronization. However, with the widespread application of long-connection communication, communication security issues have become increasingly prominent. Authentication, as a core component of ensuring communication security, effectively prevents unauthorized access and data leakage, ensuring that only legitimate users or devices can interact with data.
[0003] Traditional long-connection authentication schemes suffer from numerous drawbacks, such as code redundancy, inconsistent authentication logic, high security risks, and poor scalability. In contrast, the interceptor chain-based authentication method introduces a composable interceptor chain into the long-connection channel manager to intercept the three lifecycle stages of connection establishment, outbound messages, and inbound messages in a chain-like manner. This completely decouples the authentication logic from the business logic, achieving centralized management of the authentication logic. This approach not only eliminates code redundancy and improves code maintainability but also enhances authentication consistency and security, while possessing excellent scalability to flexibly address various complex security requirements.
[0004] Therefore, how to provide a long-connection authentication method and system based on interceptor chains that can effectively solve the problems of code redundancy, inconsistent authentication logic, high security risks and poor scalability of traditional long-connection authentication schemes is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0005] In view of this, this invention provides a long-connection authentication method and system based on an interceptor chain. It aims to solve the problems of code redundancy, inconsistent authentication logic, high security risks, and poor scalability inherent in traditional long-connection authentication schemes. In terms of architecture design, this invention introduces a composable interceptor chain, completely decoupling the authentication logic from the business code, achieving centralized management of the authentication logic, effectively reducing code coupling, and improving code maintainability and scalability. Regarding message processing, a message storage and replay mechanism is proposed to ensure that intercepted outbound messages are not lost and can be replayed in order after successful authentication, guaranteeing the integrity of message requests at the business layer. In terms of security strategies, it supports multi-interceptor combination extension, allowing flexible configuration of the interceptor chain according to different security requirements to implement channel authentication strategies with different security levels, greatly enhancing the system's security and adaptability.
[0006] To achieve the above objectives, the present invention adopts the following technical solution: A long-connection authentication method based on an interceptor chain includes: Step 1: Customize authentication strategies based on different interceptor combinations for different business channel types; where interceptor combination includes: the selected interceptors and the registration order of the selected interceptors; each interceptor contains three key interception methods: connection establishment interception, outbound message interception, and inbound message interception, corresponding to the three lifecycle stages of the long connection channel; Step 2: Based on the business channel type of the long connection channel, retrieve the authentication strategy of the corresponding interceptor combination, and instruct the selected interceptors to call the interception method corresponding to the current lifecycle stage of the long connection channel in the registration order to perform long connection authentication.
[0007] Optionally, in step 1, the three lifecycle stages are: connection establishment, outbound message sending, and inbound message receiving, which correspond to the three key interception methods: connection establishment interception, outbound message interception, and inbound message interception, respectively.
[0008] Optionally, in step 1, in the critical interception method, authentication fails when any interceptor returns to interception; authentication will only succeed when all interceptors under the current business channel type return to allow passage.
[0009] Optionally, in step 1, the key interception method also includes: a short-circuit mechanism, specifically: Once an interceptor with decision-making authority makes an interception decision, subsequent interceptors will not be executed unnecessarily.
[0010] Optionally, in step 1, the authentication process for outbound message interception also includes a message storage and replay mechanism, specifically: Message buffering mechanism: When an outbound message is intercepted by the interceptor, the channel maintains three message sets to manage the message status: the all message set records all outbound messages that need to be sent; the pending confirmation set records messages that have been submitted but have not yet received confirmation; and the confirmed set records messages that have received confirmation from the server. Retransmission trigger mechanism: When the interception condition is lifted, the interceptor triggers the re-evaluation and replay of the message. First, it checks the status of the entire message set. If it is empty, the long connection channel is disconnected. If the channel is not connected, a connection will be initiated. If the channel is connected, the message update method is called to re-evaluate and resend the messages in the unacknowledged set.
[0011] Optionally, the message update method mainly includes three key steps, specifically: First, invalid messages are cleaned up. Messages that are not in the total message set are removed from the unacknowledged set and the acknowledged set. Cancellation instructions for these messages are then sent to the server. Then, the outbound message interception method of the interceptor chain is called to determine whether there is an interception condition. If any interceptor returns an interception, the message sending is stopped. If all interceptors allow the message to pass, then iterate through the entire message set, skip messages that are already in the acknowledged and pending acknowledgement sets, send the remaining messages one by one, and add them to the pending acknowledgement set.
[0012] Optionally, in step 2, during the long connection authentication process, the following is also included: monitoring the status of the long connection channel, and when the connection status of the long connection channel changes, causing all interceptors corresponding to the business channel type to automatically reset their internal authentication status.
[0013] This invention also provides a long-connection authentication system based on an interceptor chain, utilizing a long-connection authentication method based on an interceptor chain, comprising: The authentication strategy customization module is used to customize authentication strategies based on different interceptor combinations for different business channel types. The interceptor combination includes the selected interceptors and their registration order. Each interceptor contains three key interception methods: connection establishment interception, outbound message interception, and inbound message interception, corresponding to the three lifecycle stages of a long connection channel. Long connection authentication module: It is used to retrieve the authentication strategy of the corresponding interceptor combination according to the business channel type of the long connection channel, and to make the selected interceptors call the interception method corresponding to the current life cycle stage of the long connection channel in the registration order to perform long connection authentication.
[0014] As can be seen from the above technical solution, compared with the prior art, the present invention discloses a long-connection authentication method and system based on an interceptor chain, achieving the following beneficial effects: (1) Regarding centralized management, in traditional embedded authentication schemes, authentication logic is scattered across various business modules. Each business module needs to write and maintain its own authentication code, resulting in severe code redundancy and high maintenance costs. In contrast, the interceptor chain-based authentication method centralizes the authentication logic within the interceptor framework for unified management. Business modules only need to focus on their own business logic and do not need to worry about authentication details. This not only reduces the amount of code and improves code maintainability but also makes adjusting and updating authentication strategies more convenient and faster. In a system containing multiple business modules, traditional solutions may require modifying the authentication code in each business module, while the interceptor chain-based solution only requires a single modification within the interceptor framework to be applied to all relevant business modules.
[0015] (2) Zero message loss is another important advantage of the interceptor chain-based authentication method. Traditional authentication schemes often cannot guarantee message integrity when messages are intercepted, which may lead to message loss. However, this invention adopts a message storage and replay mechanism. When an outbound message is intercepted, the message is temporarily stored in a queue to be sent. When the interception condition is lifted, the message is resent in order, ensuring that message requests from the business layer are not lost due to authentication delays. In financial transaction systems, the loss of any transaction message may lead to huge economic losses. The interceptor chain-based authentication method can effectively avoid this situation.
[0016] (3) Automated reconnection authentication is a major feature of this invention. In traditional solutions, manual intervention or complex manual operations are required to re-authenticate after a disconnection and reconnection, which is inconvenient for users and increases the complexity of the system. However, the authentication method based on the interceptor chain automatically resets the state of the interceptor and re-initiates the login process after a disconnection and reconnection. After successful login, the temporarily stored messages are automatically replayed. The entire process does not require any intervention from the business layer or the user, achieving a seamless disconnection recovery experience. In instant messaging systems, users can maintain a good communication experience even when the network is unstable, and communication will not be affected by disconnection and reconnection.
[0017] (4) The scalable strategy combination is a unique advantage of the interceptor chain-based authentication method. Traditional solutions often require extensive modifications to business code when facing new security requirements, such as adding two-factor authentication, IP whitelisting, and message encryption. This is labor-intensive and prone to errors. However, this invention, by registering different interceptor combinations, can flexibly implement channel authentication strategies with different security levels. When adding new security requirements, only the corresponding interceptor needs to be developed and registered to the target channel; no modification to existing code is required. In IoT platforms, as security requirements continuously change, the interceptor chain-based authentication method can adapt quickly, providing strong protection for secure communication of IoT devices. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0019] Figure 1 This is a schematic diagram of the method flow provided by the present invention. Detailed Implementation
[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] Example 1: Embodiment 1 of this invention discloses a long-connection authentication method based on an interceptor chain, such as... Figure 1 As shown, it includes: Step 1: Customize authentication strategies based on different interceptor combinations for different business channel types; where interceptor combination includes: the selected interceptors and the registration order of the selected interceptors; each interceptor contains three key interception methods (interceptor standard interface contract), corresponding to the three lifecycle stages of long connection channels.
[0022] The core design principle of the long-connection authentication method based on interceptor chains lies in completely decoupling complex authentication logic from business code, achieving centralized and unified management. In traditional long-connection authentication schemes, authentication logic is scattered across various business modules, leading to code redundancy, increased maintenance costs, and difficulty in unified management and control of authentication behavior. The interceptor chain design cleverly solves these problems. Business modules do not need to concern themselves with the specific implementation details of authentication; they can focus solely on their own business functions. Simultaneously, centralized and unified management of authentication logic greatly improves security and maintainability. When it is necessary to modify the authentication strategy or add new authentication steps, only corresponding adjustments need to be made to the interceptor chain, without requiring extensive modifications to the business code.
[0023] To meet diverse authentication needs, developers can customize authentication strategies based on different combinations of interceptors for different business channel types, according to business requirements and security policies.
[0024] For example, public channels do not require authentication and therefore do not need to register any authentication interceptors; private channels, however, require registration of login authentication interceptors to ensure that only authorized users can access them; specific business channels may register both login authentication interceptors and business-level permission interceptors simultaneously to achieve more granular access control. Through this flexible registration method, the system can tailor authentication strategies for each channel type according to different business scenarios and security requirements.
[0025] Typical examples of interceptors and combinations of interceptors: Login Interceptor: As the core authentication component in the interceptor chain, the login interceptor is responsible for verifying the user's identity and ensuring that the connection has been successfully logged in.
[0026] Permission Interceptor: As the core component of permission verification, it is responsible for verifying the access permissions of client message publishing and subscription operations, intercepting unauthorized message requests, and preventing unauthorized operations.
[0027] Topic Interceptor: Primarily intercepts and processes specific business messages to meet specific business needs.
[0028] Monitor Interceptors: Long-lived connection channels generate a large amount of link and message behavior data during operation. Link monitoring is fundamental for system maintenance and fault location. Monitor interceptors collect and report metrics such as channel connection status, message sending and receiving records, and various interception trigger logs, supporting system operation status observation and problem troubleshooting.
[0029] By combining these interceptors with different functions on the same channel to form an interceptor chain, comprehensive control over long-lived communication can be achieved. Each interceptor focuses on its own responsibility while working collaboratively to ensure the system's security, stability, and the correct execution of business logic.
[0030] The basic execution rule of the interceptor chain is that interceptors are executed in the order they are registered (the registration order during customization is the execution order). When registering interceptors, developers can arrange the registration order of interceptors reasonably according to business needs and security policies. Generally, the recommended registration order is: authentication interceptors → permission interceptors → business interceptors → monitoring interceptors. Interceptors registered earlier have higher priority because when the chained call engine executes the interceptor chain, it will call the corresponding methods of each interceptor in the order of registration. For example, in an authentication scenario, the authentication interceptor first authenticates the request. If authentication fails, it directly returns an interception signal, and the subsequent permission interceptors, business interceptors, and monitoring interceptors will not be executed. This mechanism ensures that illegal requests can be intercepted in the early stages of request processing, improving system security and processing efficiency.
[0031] Each interceptor focuses solely on its own responsibilities, unaware of the existence of other interceptors, demonstrating their independence. In an e-commerce system, a login authentication interceptor and an order processing interceptor form an interceptor chain. When a user is not logged in, the login authentication interceptor returns an interception signal, preventing the order processing interceptor from executing and avoiding the risk of unauthorized users performing order operations. When a user is logged in and performs an order operation, the login authentication interceptor allows the process, and the order processing interceptor handles the order-related messages, fulfilling its respective function. This independence and collaboration mechanism makes the interceptor chain highly scalable and flexible, allowing developers to easily add, delete, or modify interceptors as needed without affecting the normal operation of other interceptors.
[0032] The three lifecycle stages are: connection establishment, outbound message sending, and inbound message receiving, which correspond to three key interception methods: connection establishment interception, outbound message interception, and inbound message interception, respectively.
[0033] The connection establishment interception method, `intercept Connect(channel)` (bool), is called before a long-lived connection channel attempts to establish a connection. Its main function is to perform a pre-check on the connection request, determining whether to allow the connection to be established. The `channel` parameter provides context information about the current long-lived connection channel, such as channel type and path, which the interceptor can use to make decisions. Returning `true` indicates that the connection establishment is intercepted, preventing the channel from establishing a connection with the server; returning `false` indicates that the connection is allowed to be established normally. For example, in a login authentication interceptor, if it detects that the current user's authentication token is empty (i.e., the user is not logged in or their login status has expired), the `intercept Connect` method will return `true`, preventing the channel from establishing a connection and avoiding invalid connections consuming resources. This mechanism ensures effective control over illegal connections at the source of connection establishment, guaranteeing system security.
[0034] Outbound message interception method: `intercept Subscribe(channel) → bool`, called before sending outbound messages (such as subscription requests or business messages) on a long-connection channel. Interceptors can perform pre-processing operations in this method, such as sending login messages to complete the authentication process. Returning `true` indicates intercepting message sending, i.e., pausing the current message transmission; returning `false` indicates allowing the message to be sent normally. Taking a login authentication interceptor as an example, if a token is detected but login has not yet been initiated while authentication is incomplete, the interceptor will construct a login message and send it to the server, while simultaneously returning `true` to intercept the current outbound message until it receives a successful login confirmation from the server. This mechanism ensures that unauthenticated messages are not sent to the server, preventing security vulnerabilities.
[0035] The inbound message interception method, `intercept Message(channel, json)` (bool), is called after receiving an inbound message on the long-connection channel but before delivering it to the business processor. This method processes and evaluates the inbound message. Returning `true` indicates the message has been consumed by the interceptor and will not be passed to the business processor; returning `false` indicates the message is not of interest to the interceptor and will continue normal processing. The `json` parameter is the parsed message data, allowing the interceptor to perform corresponding operations based on the message content. For example, when a login authentication interceptor receives an inbound message, it checks if the message confirms successful login. If the condition is met, it determines successful login, updates its internal state, and consumes the message. This mechanism effectively filters and processes inbound messages, ensuring only legitimate messages enter the business processing stage.
[0036] In the critical interception method, authentication fails when any interceptor returns intercept (true). Authentication will only succeed when all interceptors under the current business channel type return allow (false).
[0037] Key interception methods also include: short-circuit mechanisms, specifically: Once an interceptor with decision-making authority makes an interception decision, subsequent interceptors will not be executed unnecessarily, thus improving processing efficiency. At the same time, the short-circuit mechanism also ensures the priority among interceptors; interceptors that register earlier have higher interception priority. For example, in authentication scenarios, if the first registered authentication interceptor determines that the request has failed authentication, it directly returns an interception signal, and subsequent business interceptors and monitoring interceptors will not be executed, avoiding unnecessary waste of computing resources and ensuring the strictness and effectiveness of authentication.
[0038] This sequential execution method allows each interceptor to focus on its own responsibilities while working together to achieve comprehensive control over long-connection authentication.
[0039] The authentication process for outbound message interception also includes a message storage and replay mechanism, which is a key mechanism to ensure the integrity and order of messages in long-connection communication. It manages message states by maintaining a message set through the channel and uses a replay trigger mechanism and message update logic to ensure that intercepted outbound messages can be replayed in order after the interception conditions are lifted. Specifically: Message buffering mechanism: When an outbound message is intercepted by the interceptor, the channel maintains three message sets to manage message status: the total message set (topics) records all outbound messages that need to be sent; the pending set (pending topics) records messages that have been submitted but have not yet received confirmation of sending. These messages are ready to be sent but have been temporarily intercepted for some reason (such as incomplete authentication); and the successful set (success topics) records messages that have received confirmation of sending from the server, indicating that these messages have been successfully sent and recognized by the server. Through the coordinated work of these three sets, the channel can clearly manage the different states of messages, providing a foundation for subsequent message processing.
[0040] Retransmission trigger mechanism: When the interception condition is lifted, such as after successful login, the interceptor will call channel.check() to trigger the re-evaluation and replay of messages. The check() method first checks the status of the entire message set. If it is empty, it means that there are no messages to send, and the long connection channel is disconnected to release resources. If the channel is not connected, a connection will be established to ensure that messages can be sent normally. If the channel is connected, the message update method update Topic is called to re-evaluate and send messages in the unacknowledged set.
[0041] The message update method `update Topic` mainly includes three key steps, specifically: First, invalid messages are cleaned up. Messages that are not in the total message set are removed from the pending confirmation set and the confirmed confirmation set. These messages may have been canceled by the business layer. Cancellation instructions for these messages are sent to the server to ensure that the state of the server and the client is consistent. Then, the outbound message interception method of the interceptor chain is called to determine whether there are interception conditions. If any interceptor returns an interception, it means that the login is not yet completed or there are other interception conditions, and message sending is stopped. If all interceptors allow the message to be sent, then the message can be sent. The entire message set is iterated through, skipping messages already in the acknowledged and pending acknowledgement sets, and the remaining messages are sent one by one, adding them to the pending acknowledgement set. This message update logic ensures that messages are replayed in the order they were added to the entire message set, maintaining the correctness of message timing and ensuring that message requests from the business layer are not lost due to authentication delays.
[0042] Step 2: Based on the business channel type of the long connection channel, retrieve the authentication strategy of the corresponding interceptor combination, and instruct the selected interceptors to call the interception method corresponding to the current lifecycle stage of the long connection channel in the registration order to perform long connection authentication.
[0043] The interceptor chain works based on the chain of responsibility pattern. In this pattern, a series of interceptors are chained together to form a chain-like structure. When a certain lifecycle stage of a long-lived connection occurs, the interceptor set corresponding to the current business channel type is retrieved, and the interceptor method corresponding to the current lifecycle stage is called in the registration order to perform long-lived connection authentication. For example, in the connection establishment stage, the set of interceptors associated with the current channel type is retrieved, and then each interceptor in the set is traversed in the registration order, calling its `intercept Connect` method. Connection establishment is only allowed when all interceptors return false (allow); if any interceptor returns true (block), the traversal stops immediately, and connection establishment is prevented.
[0044] The long-connection authentication process also includes: monitoring the status of the long-connection channel (using the Channel Status Listener interface, which is independent of the interceptor interface). When the connection status of the long-connection channel changes, all interceptors corresponding to the business channel type automatically reset their internal authentication status to ensure the continuity and correctness of the authentication process.
[0045] The Channel Status Listener interface for long-lived channels includes the `on ChannelStatus Changed(channel Type, connected) → void` method. This method is triggered whenever the connection status of a long-lived channel changes, whether the connection is established or closed. The `channel Type` parameter represents the channel type; `connected` is true if the connection is established, and false if the connection is closed. Through this interface, interceptors can detect changes in the connection status of long-lived channels in real time and take appropriate action.
[0046] Authentication State Reset Functionality: For interceptors that need to maintain authentication state when connection state changes, implementing the Channel Status Listener interface is crucial. Taking a login authentication interceptor as an example, when the channel connection is broken, the interceptor receives a notification and performs a series of operations to reset its internal state. It resets the authentication completion flag "login" to false, indicating that the current authentication state has expired; it also resets the login message sent flag "send Message" to false, returning to the unauthenticated state. Simultaneously, the channel itself clears the pending confirmation set and the confirmed confirmation set, because the server's subscription state has expired after the connection is broken. When the channel successfully reconnects, the "check()" method is triggered to re-evaluate message sending. At this time, the interceptor is in the unauthenticated state, and the outbound message interception method automatically initiates the login process, constructs and sends the login message, achieving automatic re-authentication without external intervention. This mechanism ensures that the authentication process can automatically adapt and run correctly even when the connection state is unstable, providing users with a seamless experience.
[0047] Example 2: Embodiment 2 of the present invention discloses a long-connection authentication system based on an interceptor chain, comprising: The authentication strategy customization module is used to customize authentication strategies based on different interceptor combinations for different business channel types. The interceptor combination includes the selected interceptors and their registration order. Each interceptor contains three key interception methods: connection establishment interception, outbound message interception, and inbound message interception, corresponding to the three lifecycle stages of a long connection channel. Long connection authentication module: It is used to retrieve the authentication strategy of the corresponding interceptor combination according to the business channel type of the long connection channel, and to make the selected interceptors call the interception method corresponding to the current life cycle stage of the long connection channel in the registration order to perform long connection authentication.
[0048] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.
[0049] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A long-connection authentication method based on an interceptor chain, characterized in that, include: Step 1: Customize authentication strategies based on different interceptor combinations for different business channel types; wherein, the interceptor combination includes: the selected interceptors and the registration order of the selected interceptors; each interceptor includes three key interception methods: connection establishment interception, outbound message interception, and inbound message interception, corresponding to the three lifecycle stages of the long connection channel; Step 2: Based on the service channel type of the long connection channel, retrieve the authentication strategy of the corresponding interceptor combination, and instruct the selected interceptor to call the interception method corresponding to the current lifecycle stage of the long connection channel for long connection authentication in accordance with the registration order.
2. The long-connection authentication method based on an interceptor chain according to claim 1, characterized in that, In step 1, the three lifecycle stages are: connection establishment, outbound message sending, and inbound message receiving, which correspond to three key interception methods: connection establishment interception, outbound message interception, and inbound message interception, respectively.
3. The long-connection authentication method based on an interceptor chain according to claim 1, characterized in that, In step 1, in the key interception method, authentication fails when any interceptor returns to interception; authentication only succeeds when all interceptors under the current service channel type return to allow passage.
4. The long-connection authentication method based on an interceptor chain according to claim 1, characterized in that, In step 1, the key interception method further includes a short-circuit mechanism, specifically: Once an interceptor with decision-making authority makes an interception decision, subsequent interceptors will not be executed unnecessarily.
5. The long-connection authentication method based on an interceptor chain according to claim 1, characterized in that, In step 1, the authentication process for outbound message interception also includes a message storage and replay mechanism, specifically: Message buffering mechanism: When an outbound message is intercepted by the interceptor, the channel maintains three message sets to manage the message status: the all message set records all outbound messages that need to be sent; the pending confirmation set records messages that have been submitted but have not yet received confirmation; and the confirmed set records messages that have received confirmation from the server. Retransmission trigger mechanism: When the interception condition is lifted, the interceptor triggers the re-evaluation and replay of the message. First, it checks the status of the entire message set. If it is empty, the long connection channel is disconnected. If the channel is not connected, a connection will be initiated. If the channel is connected, the message update method is called to re-evaluate and resend the messages in the unacknowledged set.
6. The long-connection authentication method based on an interceptor chain according to claim 5, characterized in that, The message update method mainly includes three key steps, specifically: First, invalid messages are cleaned up. Messages that are not in the total message set are removed from the unacknowledged set and the acknowledged set. Cancellation instructions for these messages are then sent to the server. Then, the outbound message interception method of the interceptor chain is called to determine whether there is an interception condition. If any interceptor returns an interception, the message sending is stopped. If all interceptors allow the message to pass, then iterate through the entire message set, skip messages that are already in the acknowledged and pending acknowledgement sets, send the remaining messages one by one, and add them to the pending acknowledgement set.
7. The long-connection authentication method based on an interceptor chain according to claim 1, characterized in that, In step 2, the long connection authentication process also includes: monitoring the status of the long connection channel, and when the connection status of the long connection channel changes, causing all interceptors corresponding to the service channel type to automatically reset their internal authentication status.
8. A long-connection authentication system based on an interceptor chain, utilizing the long-connection authentication method based on an interceptor chain as described in any one of claims 1-7, characterized in that, include: The authentication strategy customization module is used to customize authentication strategies based on different interceptor combinations for different business channel types. The interceptor combination includes the selected interceptors and the registration order of the selected interceptors. Each interceptor contains three key interception methods: connection establishment interception, outbound message interception, and inbound message interception, corresponding to the three lifecycle stages of the long connection channel. Long connection authentication module: It is used to retrieve the authentication strategy of the corresponding interceptor combination according to the service channel type of the long connection channel, and instruct the selected interceptor to call the interception method corresponding to the current life cycle stage of the long connection channel in the registration order to perform long connection authentication.