Session management method and device, computer equipment and readable storage medium
By using the service identity header in the browser to query the cookie name and create a session, the problem of conflict between multiple front-end service sessions on the same browser is solved, seamless identity switching is achieved, and user experience and operation efficiency is improved.
Patent Information
- Application Number
- CN202411777559.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-12-05
AI Technical Summary
Session conflict issues with multiple front-end services on the same browser cause users to log out of the current session and log in again to switch to different identities, reducing user experience and increasing operational complexity.
By receiving the login request for the front-end service in the browser, using the service identification header to query the corresponding cookie name in the configuration center, create the corresponding session, and generate response information feedback to the browser. This method allows users to access the same backend service through multiple frontend services in the same browser without having to exit the session and create a new session.
It realizes the function of seamlessly switching different identities in the same browser, improves user experience and operation efficiency, and solves the problem of conflicts between multiple front-end service sessions.
Smart Images

Figure CN119484609A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network communication technology, and in particular to a session management method, apparatus, computer equipment, and computer-readable storage medium. Background Art
[0002] Currently, due to the uniqueness of the domain attribute of browser cookies, there will be conflicts between cookies with the same name under the same domain name or IP (network address). The default session cookie name of the Shiro framework is JsessionId. If multiple services using Shiro to manage sessions are deployed on the same site, or the same backend service provides multiple front-end pages, there will be session conflicts between them.
[0003] In traditional network frameworks, users usually access backend services through a single front-end interface. When users need to access the same backend service with different identities, they usually need to log out of the current session and log in again. This method reduces the user experience and increases operational complexity. Summary of the invention
[0004] Based on this, it is necessary to provide a session management method, apparatus, computer device and computer-readable storage medium to address the above technical problems, which can solve the session conflict problem of multiple front-end services on the same browser.
[0005] In a first aspect, the present application provides a session management method, comprising:
[0006] Receive a login request for a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service;
[0007] According to the service identification header, query the corresponding cookie name in the configuration center;
[0008] Create a corresponding session based on the cookie name;
[0009] Generate response information based on the cookie name and feed the response information back to the browser.
[0010] In one embodiment, the login request also carries login information; after creating a corresponding session according to the cookie name, the method further includes:
[0011] Perform identity authentication based on login information;
[0012] After identity authentication, access to resources is authorized;
[0013] Associate the authorization information for accessing resources with the cookie name and store the authorization information in the session.
[0014] In one embodiment, the method further comprises:
[0015] Receive an access request from the second front-end service; the access request carries a target service identification header and a target cookie name obtained by a browser query;
[0016] Verify the target cookie name based on the target service identification header;
[0017] After verification, the corresponding target session is determined based on the target cookie name;
[0018] Processes the access request according to the target session and returns the corresponding processing data.
[0019] In one embodiment, after verifying the target cookie name according to the target service identification header, the method further includes:
[0020] If the verification fails, a prompt message indicating access failure is returned to the browser.
[0021] In one embodiment, the method further comprises:
[0022] During the running of each session, the session data of each session is stored in the Redis cluster according to the cookie name of each session.
[0023] In one embodiment, the method further comprises:
[0024] If it is detected that the current session has ended, the corresponding session data is deleted from the Redis cluster according to the cookie name of the current session, and the current session is ended.
[0025] In one embodiment, the method further comprises:
[0026] During the backend service upgrade process, obtain the cookie name of the created session;
[0027] Determine the service identification header of each created session according to the front-end service corresponding to each created session;
[0028] According to the cookie name and service identification header of each created session, the correspondence between the cookie name and the service identification header is updated in the configuration center.
[0029] In a second aspect, the present application also provides a session management device, including:
[0030] A receiving module, configured to receive a login request of a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service;
[0031] The query module is used to query the corresponding cookie name in the configuration center according to the service identification header;
[0032] Create a module to create a corresponding session based on the cookie name;
[0033] The response module is used to generate response information based on the cookie name and feed the response information back to the browser.
[0034] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the method described in the first aspect above are implemented.
[0035] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the method described in the first aspect above are implemented.
[0036] The above-mentioned session management method, apparatus, computer equipment and computer-readable storage medium receive a login request from a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service; according to the service identification header, the corresponding cookie name is queried in the configuration center; according to the cookie name, a corresponding session is created; according to the cookie name, a response message is generated, and the response message is fed back to the browser. Through the above-mentioned method, different cookie names are assigned to each front-end service running on the same browser, allowing users to access the same back-end service through multiple front-end services in the same browser, and can seamlessly switch between different identities without exiting the session and creating a new session, thereby improving user experience and operating efficiency; through the service identification header of each front-end service, the cookie name of the session is assigned, which can solve the session conflict problem of multiple front-end services on the same browser. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0038] FIG1 is an application environment diagram of a session management method in one embodiment;
[0039] FIG2 is a flow chart of a session management method in one embodiment;
[0040] FIG3 is a flow chart of a session management method in another embodiment;
[0041] FIG4 is a schematic diagram of the interaction between a browser and a backend service in one embodiment;
[0042] FIG5 is a block diagram of a session management device in one embodiment;
[0043] FIG. 6 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0045] It is understood that the terms "first", "second", etc. used in this application may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish a first element from another element. For example, without departing from the scope of this application, a first front-end service may be referred to as a second front-end service, and similarly, a second front-end service may be referred to as a first front-end service. Both the first front-end service and the second front-end service are front-end services, and may be the same front-end service or different front-end services.
[0046] The session management method provided in the embodiment of the present application can be applied to the application environment shown in FIG. 1. The browser 102 communicates with the back-end server 104 through the network. The data storage system can store the data that the back-end server 104 needs to process. The data storage system can be integrated on the back-end server 104, or it can be placed on the cloud or other network servers. At least one front-end service is running on the browser 102, and each front-end service is connected to the back-end service running on the back-end server 104. The back-end server 104 allocates sessions to each front-end service to access the back-end service. The browser 102 runs on a terminal, and the terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The head-mounted device can be a virtual reality (VR) device, an augmented reality (AR) device, smart glasses, etc. The backend server 104 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0047] In order to facilitate understanding of the embodiments provided in this application, some terms that appear in the specific description process are introduced below:
[0048] A session refers to the process of multiple requests and responses between a browser and a server. The multiple requests and responses generated from the time the browser accesses the server to the end of the access to the server (that is, until the browser is closed) are called a session between the browser and the server. It can be understood that a user opens a browser, clicks on multiple hyperlinks to access the server's network (web) resources, and then closes the browser. The entire process is called a session. A session not only includes the opening of a new window or a new tab, but also counts as a session as long as the user clicks on multiple links, whether in the same window or a newly opened window or tab. Session data is stored between the browser and the server and is used to track and record information about the user's interaction with the website.
[0049] A cookie is a small text file, data stored on the user's local terminal (Client Side) by some websites in order to identify the user, usually encrypted. The purpose of setting cookies is to allow the website to recognize the user and conduct session tracking, so as to remember the user's specific information, such as the location of the last visit, the time spent, or user preferences (such as style sheets). Cookies can be stored in the browser's random access memory (RAM) or on the computer's hard drive so that the information can be retained after the user exits the website or network server.
[0050] Shiro, or Apache Shiro, is a powerful and easy-to-use Java security framework that provides authentication, authorization, encryption, and session management functions. For any application, Shiro can provide comprehensive security management services.
[0051] In an exemplary embodiment, as shown in FIG. 2 , a session management method is provided, which is described by taking the method applied to the backend server 104 in FIG. 1 as an example, including:
[0052] Step 202, receiving a login request of a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service.
[0053] When the front-end service sends a request, each service identification header is added to facilitate the back-end server to identify and distinguish it. Optionally, the service identification header is added through nginx reverse proxy or other methods. The service identification header can be the credential information configured by the developer for each application.
[0054] The login request received by the backend server carries a service identification header. It is understandable that the backend server is connected to at least one front-end service running by the browser, and can synchronously or asynchronously process requests from different front-end services, and each request carries a service identification header of the front-end service that issued the request. In this way, sessions of multiple front-end services can be distinguished, making it easier for users to access the backend server through multiple front-end services.
[0055] Step 204: query the corresponding cookie name in the configuration center according to the service identification header.
[0056] Among them, after receiving the login request, the backend service running on the backend server first checks the service identification header in the login request to determine which front-end service the login request belongs to, and searches the configuration center for the corresponding cookie name based on the service identification header. The configuration center is configured with the service identification header of each front-end service and the corresponding session cookie name, which is convenient and flexible to modify. The configuration center can use Nacos, which is not limited in this embodiment. After receiving the login request, the backend server queries the configuration center based on the service identification header carried in the login request to determine the configured cookie name.
[0057] It is understandable that the configuration center assigns different cookie names to different service identification headers in advance to avoid session conflicts. In an optional implementation, the backend server uses the Shiro framework, customizes the ShiroSessionManager class to inherit the framework's DefaultWebSessionManager class to flexibly manage sessions; rewrites the onStart method, modifies the storeSessionId method called therein to a customized new method; through the customized storeSessionId method, assigns a specific cookie name to the request according to the specific Header identification of the request. The correspondence between different Headers and cookie names is stored in the Nacos configuration center.
[0058] Step 206: Create a corresponding session based on the cookie name.
[0059] Step 208, generating response information according to the cookie name, and feeding back the response information to the browser.
[0060] The backend server uses the cookie name to create a new session. Optionally, a custom ShiroSessionManager class is used to create and manage sessions, wherein the custom storeSessionId method stores the newly created session ID in the response cookie and sends it back to the browser. The name of the cookie is the cookie name queried in step 204.
[0061] In an optional implementation, after receiving a session creation request (carrying a service identification header), if the same session name exists, the session name corresponding to the service identification header is searched from the configuration center, and a new session is created using the new session name.
[0062] In an optional implementation, when a user switches between different front-end services, the back-end service uses the corresponding cookie name to read and update the session according to the service identification header in the request, thereby realizing the use of multiple sessions.
[0063] In this embodiment, the relationship between the cookie name and the header identifier is managed by the configuration center, which improves the flexibility and maintainability of session management. Users can use multiple front-end services in the same browser, access with different identities, and quickly switch between different identities, reducing the number of steps for users to switch between different identities. Identity switching is controlled by the back-end service, which improves the security of the system.
[0064] It is understandable that the following example illustrates the application scenario of the session management method provided by the present application: In a low-code development platform, developers build and publish applications that share the same backend service. Developers can configure specific credential information for each application and carry this information in user requests through custom code to achieve multi-user login.
[0065] In the above session management method, a login request of the first front-end service is received; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service; according to the service identification header, the corresponding cookie name is queried in the configuration center; according to the cookie name, a corresponding session is created; according to the cookie name, a response message is generated, and the response message is fed back to the browser. Through the above method, different cookie names are assigned to each front-end service running on the same browser, allowing users to access the same back-end service through multiple front-end services in the same browser, and can seamlessly switch between different identities without exiting the session and creating a new session, thereby improving user experience and operating efficiency; through the service identification header of each front-end service, the cookie name of the session is assigned, which can solve the session conflict problem of multiple front-end services on the same browser.
[0066] In an exemplary embodiment, after the login request also carries the login information step 206, the method further includes: performing identity authentication based on the login information; after the identity authentication is passed, authorizing access to resources; associating the authorization information for accessing the resources with the cookie name, and storing the authorization information in the session.
[0067] The user initiates a login request through the interface of the first front-end service on the browser, enters login information (such as user name and password), and the first front-end service sends the user's login information and service identification header to the back-end service. The back-end service authenticates the user's login information, such as looking up the password of the user name and judging whether it is consistent with the password entered by the user. If the authentication is successful, the user is authorized to access the corresponding resources; the authorization information is stored in the created session and associated with a specific cookie name.
[0068] In an exemplary embodiment, as shown in FIG3 , the method further includes:
[0069] Step 302, receiving an access request from the second front-end service; the access request carries a target service identification header and a target cookie name obtained by the browser query.
[0070] The second front-end service and the first front-end service run in the same browser, and may be the same front-end service or different front-end services, which is not limited in this embodiment. It is understandable that after the user successfully logs in through the second front-end service, the browser stores the target cookie name associated with the session of the second front-end service according to the response information fed back by the back-end service. When the user initiates a subsequent access request to the back-end service, the browser automatically carries the target cookie name and the target service identification header of the second front-end service.
[0071] Step 304: Verify the target cookie name according to the target service identification header.
[0072] Among them, the backend service searches for the corresponding cookie name from the configuration center according to the target service identification header; if the found cookie name is consistent with the target cookie name, the verification passes; if the found cookie name is inconsistent with the target cookie name, the verification fails.
[0073] Step 306, after verification is passed, determine the corresponding target session according to the target cookie name.
[0074] Among them, the backend service is based on the Shiro framework and uses a customized getSessionId method to read the session using a new session name based on the target cookie name in the request.
[0075] Step 308: Process the access request according to the target session and return corresponding processing data.
[0076] The backend service processes the user's access request based on the target session and returns corresponding processing data to the second frontend service.
[0077] In this embodiment, by carrying the service identification header and cookie name when accessing the backend service, the backend service can implement cookie name verification and quickly obtain the session, thereby improving the security of backend service access.
[0078] In an exemplary embodiment, after step 304, the method further includes: if the verification fails, returning a prompt message indicating access failure to the browser.
[0079] If the cookie name found is inconsistent with the target cookie name, the verification fails, indicating that the backend service has created a new session for the second frontend service, but the browser has not updated the relevant cookie name in time; in order to avoid information conflicts, a prompt message indicating access failure is returned to the browser. After receiving the response information containing the new cookie name, the browser resends the access request based on the updated cookie name, and the backend service provides services for it based on the newly created session.
[0080] In an exemplary embodiment, the method further includes: during the running of each session, storing the session data of each session in a Redis cluster according to the cookie name of each session.
[0081] During the entire session of the user, the backend service will update the session data according to the operation status, such as the user's behavior log, permission changes, etc., and store the session data in the Redis cluster according to the session cookie name, ensuring the consistency and high availability of session data in the distributed system.
[0082] In an exemplary embodiment, the method further includes: if it is detected that the current session has ended, deleting the corresponding session data from the Redis cluster according to the cookie name of the current session, and ending the current session.
[0083] Among them, when the user logs out or the session expires, the backend service searches the configuration center for the corresponding cookie name according to the service identification header in the request, detects that the current session corresponding to the cookie name has ended, deletes the corresponding session data from the Redis cluster according to the cookie name of the current session, ends the current session, and deletes the session.
[0084] In an exemplary embodiment, the method also includes: during the backend service upgrade process, obtaining the cookie name of the created session; determining the service identification header of each created session based on the front-end service corresponding to each created session; and updating the correspondence between the cookie name and the service identification header in the configuration center based on the cookie name and the service identification header of each created session.
[0085] It is understandable that when the backend server upgrades the function corresponding to the session management method provided by this application by the initial processing logic, for the created session, according to the cookie name and service identification header of the created session, the corresponding relationship between the cookie name and the service identification header is updated in the configuration center, and a smooth transition can be achieved without restarting the service. The service identification header can be input by the developer when the backend service is upgraded, or it can be obtained by the backend service through interaction with the front-end service, and this embodiment does not limit this.
[0086] In an optional implementation, referring to FIG4 , front-end service A, front-end service B and front-end service C are running on the browser, and different ports of the same IP address correspond to different front-end services. In the traditional way, the same cookie name is set for the same IP address, resulting in session conflicts. In the session management method provided by the present application, when the front-end service accesses the back-end service, the back-end service distinguishes requests from different front-end services by adding their own service identification headers (Header), and provides sessions with different cookie names for different front-end services, thereby providing services to front-end A, front-end B and front-end C at the same time.
[0087] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0088] Based on the same inventive concept, the embodiment of the present application also provides a session management device for implementing the above-mentioned session management method. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above-mentioned method, so the specific limitations in one or more session management device embodiments provided below can refer to the limitations on the session management method above, and will not be repeated here.
[0089] In an exemplary embodiment, as shown in FIG5 , a session management device is provided, including:
[0090] The receiving module 502 is used to receive a login request of a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service.
[0091] The query module 504 is used to query the corresponding cookie name in the configuration center according to the service identification header.
[0092] The creation module 506 is used to create a corresponding session according to the cookie name.
[0093] The response module 508 is used to generate response information according to the cookie name and feed the response information back to the browser.
[0094] In the above session management device, a login request of the first front-end service is received; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service; according to the service identification header, the corresponding cookie name is queried in the configuration center; according to the cookie name, a corresponding session is created; according to the cookie name, a response message is generated, and the response message is fed back to the browser. Through the above method, different cookie names are assigned to each front-end service running on the same browser, allowing users to access the same back-end service through multiple front-end services in the same browser, and can seamlessly switch between different identities without exiting the session and creating a new session, thereby improving user experience and operating efficiency; through the service identification header of each front-end service, the cookie name of the session is assigned, which can solve the session conflict problem of multiple front-end services on the same browser.
[0095] In an exemplary embodiment, the session management device also includes an authorization module, and the login request also carries login information; the authorization module is used to perform identity authentication based on the login information; after the identity authentication is passed, access to resources is authorized; the authorization information for accessing resources is associated with the cookie name, and the authorization information is stored in the session.
[0096] In an exemplary embodiment, the session management device also includes a processing module; the processing module is used to receive an access request from a second front-end service; the access request carries a target service identification header and a target cookie name obtained by a browser query; the target cookie name is verified according to the target service identification header; after the verification is passed, the corresponding target session is determined according to the target cookie name; the access request is processed according to the target session, and corresponding processing data is returned.
[0097] In an exemplary embodiment, the processing module is further configured to return a prompt message indicating access failure to the browser if the verification fails.
[0098] In an exemplary embodiment, the session management device further includes a storage module; the storage module is used to store the session data of each session in a Redis cluster according to the cookie name of each session during the operation of each session.
[0099] In an exemplary embodiment, the storage module is also used to delete the corresponding session data from the Redis cluster according to the cookie name of the current session and end the current session if it is detected that the current session has ended.
[0100] In an exemplary embodiment, the session management device also includes an update module; the update module is used to obtain the cookie name of the created session during the backend service upgrade process; determine the service identification header of each created session based on the front-end service corresponding to each created session; and update the correspondence between the cookie name and the service identification header in the configuration center based on the cookie name and the service identification header of each created session.
[0101] Each module in the above session management device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0102] In an exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG6. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a session management method is implemented.
[0103] Those skilled in the art will understand that the structure shown in FIG. 6 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0104] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the following steps when executing the computer program: receiving a login request for a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service; according to the service identification header, querying a corresponding cookie name in a configuration center; according to the cookie name, creating a corresponding session; generating response information according to the cookie name, and feeding the response information back to the browser.
[0105] In one embodiment, when the processor executes the computer program, the following steps are also implemented: identity authentication is performed according to the login information; after the identity authentication is passed, access to resources is authorized; the authorization information for accessing resources is associated with the cookie name, and the authorization information is stored in the session.
[0106] In one embodiment, when the processor executes the computer program, the following steps are also implemented: receiving an access request from a second front-end service; the access request carries a target service identification header and a target cookie name obtained by a browser query; based on the target service identification header, the target cookie name is verified; after the verification is passed, the corresponding target session is determined based on the target cookie name; the access request is processed based on the target session, and corresponding processing data is returned.
[0107] In one embodiment, when the processor executes the computer program, the following steps are also implemented: if the verification fails, a prompt message indicating access failure is returned to the browser.
[0108] In one embodiment, when the processor executes the computer program, the following steps are also implemented: during the running of each session, the session data of each session is stored in the Redis cluster according to the cookie name of each session.
[0109] In one embodiment, when the processor executes the computer program, the following steps are also implemented: if it is detected that the current session has ended, the corresponding session data is deleted from the Redis cluster according to the cookie name of the current session, and the current session is ended.
[0110] In one embodiment, when the processor executes the computer program, the following steps are also implemented: during the backend service upgrade process, the cookie name of the created session is obtained; based on the front-end service corresponding to each created session, the service identification header of each created session is determined; based on the cookie name and the service identification header of each created session, the correspondence between the cookie name and the service identification header is updated in the configuration center.
[0111] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented: receiving a login request for a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service; according to the service identification header, querying the corresponding cookie name in the configuration center; according to the cookie name, creating a corresponding session; generating response information according to the cookie name, and feeding the response information back to the browser.
[0112] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: identity authentication is performed based on the login information; after the identity authentication is passed, access to resources is authorized; the authorization information for accessing the resources is associated with the cookie name, and the authorization information is stored in the session.
[0113] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: receiving an access request from a second front-end service; the access request carries a target service identification header and a target cookie name obtained by a browser query; verifying the target cookie name based on the target service identification header; after the verification is passed, determining the corresponding target session based on the target cookie name; processing the access request based on the target session, and returning corresponding processing data.
[0114] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: if the verification fails, a prompt message indicating access failure is returned to the browser.
[0115] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: during the running of each session, the session data of each session is stored in the Redis cluster according to the cookie name of each session.
[0116] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: if it is detected that the current session has ended, the corresponding session data is deleted from the Redis cluster according to the cookie name of the current session, and the current session is ended.
[0117] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: during the backend service upgrade process, the cookie name of the created session is obtained; based on the front-end service corresponding to each created session, the service identification header of each created session is determined; based on the cookie name and the service identification header of each created session, the correspondence between the cookie name and the service identification header is updated in the configuration center.
[0118] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0119] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the memory, database or other medium mentioned in each embodiment provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0120] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0121] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A session management method, characterized in that: The method comprises: Receive a login request for a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service; According to the service identification header, query the corresponding cookie name in the configuration center; According to the cookie name, create a corresponding session; Response information is generated according to the cookie name, and the response information is fed back to the browser.
2. The method according to claim 1, characterized in that The login request also carries login information; after creating a corresponding session according to the cookie name, the method further includes: Perform identity authentication according to the login information; After identity authentication is passed, access to resources is authorized; The authorization information for accessing the resource is associated with the cookie name, and the authorization information is stored in the session.
3. The method according to claim 2, characterized in that The method further comprises: Receive an access request for a second front-end service; the access request carries a target service identification header and a target cookie name obtained by the browser query; Verifying the target cookie name according to the target service identification header; After the verification is passed, the corresponding target session is determined according to the target cookie name; The access request is processed according to the target session, and corresponding processing data is returned.
4. The method according to claim 3, characterized in that After verifying the target cookie name according to the target service identification header, the method further includes: If the verification fails, a prompt message indicating access failure is returned to the browser.
5. The method according to claim 1, characterized in that The method further comprises: During the running of each session, the session data of each session is stored in the Redis cluster according to the cookie name of each session.
6. The method according to claim 5, characterized in that The method further comprises: If it is detected that the current session has ended, the corresponding session data is deleted from the Redis cluster according to the cookie name of the current session, and the current session is ended.
7. The method according to any one of claims 1 to 6, characterized in that The method further comprises: During the backend service upgrade process, obtain the cookie name of the created session; Determine the service identification header of each created session according to the front-end service corresponding to each created session; According to the cookie name and service identification header of each created session, the correspondence between the cookie name and the service identification header is updated in the configuration center.
8. A session management device, characterized in that: The device comprises: A receiving module, configured to receive a login request of a first front-end service; the login request carries a service identification header; the first front-end service runs in a browser, and the browser runs at least one front-end service; A query module, used to query the corresponding cookie name in the configuration center according to the service identification header; A creation module, used to create a corresponding session according to the cookie name; The response module is used to generate response information according to the cookie name and feed the response information back to the browser.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method, media server and terminal device for identifying service request type
CN103181140A
Service background recognition method, proxy server and computer storage medium
CN107483565A
Web session detection method and device, computer equipment and storage medium
CN115208617A
Distributed training system based on containerization and construction method thereof
CN115344356A
Dynamic joint debugging method and system for front end and rear end of micro-service system
CN116185471A