Unified authentication and log recording method of cloud platform
By defining the main project and Gateway project in smart TV technology, using the Token mechanism and asynchronous logging, the problems of slow efficiency, security vulnerabilities and inflexible logging in traditional methods are solved, and efficient and secure unified authentication and logging are achieved. Recording improves system efficiency and user experience.
Patent Information
- Application Number
- CN202410991106.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-26
AI Technical Summary
Traditional methods have problems such as slow efficiency, security vulnerabilities and inflexible logging in smart TV technology, especially when each request requires a security verification project, and logging requires a lot of annotations, which affects the normal operation of the business system.
By defining the main project and Gateway project, using global filters to implement request interception, using Token mechanism and whitelist configuration to reduce unnecessary verification, using Redis storage key and RabbitMQ to implement asynchronous logging, separating logging from business logic, and improving System efficiency and security.
It improves system response speed, enhances security, simplifies development and maintenance, improves user experience, and realizes real-time logging and monitoring, improving the maintainability and scalability of the system.
Smart Images

Figure CN119030861A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of smart televisions, and in particular to a unified authentication and log recording method for a cloud platform. Background Art
[0002] With the increase in projects, creating a unified background verification and log recording has become the key. The conventional practice is to establish a security verification project and a common package with aspect capabilities. After the business project references the common package, when the front-end accesses the background, it calls the security verification project for authentication through the aop function. This results in the need to request the security verification project for each request, which is extremely inefficient. If the security project or the common package is upgraded, it will also lead to a large number of adjustments to business functions. For unified logs, the common method is to use annotations and aspects, which requires a large number of annotations to be added for access. How to record logs without paying too much attention to the business system needs to be solved urgently.
[0003] In summary, the traditional methods have the following main defects:
[0004] Efficiency issues: Each request needs to request a security verification project, resulting in extremely low efficiency; Security issues: Security verification requires requesting a security verification project, but this method may have security vulnerabilities or be attacked maliciously; Logging issues: Traditional logging methods usually require annotations to be added to each business interface, and require too much attention from the business system, which is not flexible enough. Summary of the invention
[0005] In order to solve the problems existing in the prior art, the purpose of the present invention is to provide a unified authentication and logging method for a cloud platform, which simplifies the development and maintenance process and improves the maintainability and scalability of the system.
[0006] To achieve the above purpose, the technical solution adopted by the present invention is: a unified authentication and log recording method for a cloud platform, comprising the following steps:
[0007] Step 1: Define the main project to unify user login and integrate various sub-business projects;
[0008] Step 2: Create a Gateway project and use the global filter GlobalFilter to implement unified interception and processing of requests. All requests are mapped to the Gateway project through nginx and then forwarded to the corresponding business project through OpenFeign.
[0009] Step 3: When the user logs in, the Gateway project forwards the request to the main project. The main project uses Shiro to verify the user. After the verification, a Java Web Token is generated and stored in Redis. The login interface is whitelisted, and subsequent requests carry the Token for verification.
[0010] Step 4: Generate a symmetric key when logging in to the page and store it in Redis. When requesting, carry the encrypted value of the URL path, and the backend uses the key in Redis to decrypt it.
[0011] Step 5: Configure the login interface in the whitelist to be released directly; verify the Token carried by the front end to determine whether the Token exists, and obtain it together with a Redis in the Gateway project;
[0012] Step 6: Use RabbitMQ to implement asynchronous logging and send it to the specified queue. The main project is responsible for receiving it and persisting it in the database.
[0013] Step 7: When adding a new business project, add configuration and corresponding routes through the background, and implement unified authentication and logging through Gateway.
[0014] As a further improvement of the present invention, in step 1, the main project includes menus, roles and user information.
[0015] As a further improvement of the present invention, in step 1 and in step 2, the main project and all business projects are registered in the same namespace on nacos.
[0016] As a further improvement of the present invention, in step 1, in step 4, if the decryption fails, the key in the database is used to decrypt and compare whether it is the current URL path, and if successful, the latest Redis key is returned.
[0017] As a further improvement of the present invention, in step 1, in step 6, if the RabbitMQ message consumption fails, it enters the dead letter queue, and after a period of time, it is consumed again in the queue.
[0018] As a further improvement of the present invention, in step 1, in order to prevent the token from expiring frequently, after the verification is passed, the expiration time of the Token is reset and put back into Redis.
[0019] The present invention uses the Token mechanism and whitelist configuration to reduce unnecessary verification, and uses Gateway for unified routing and filtering, which significantly improves access efficiency; uses the Token mechanism and dynamic key management mechanism to ensure access security and improve system security; uses the asynchronous logging mechanism to separate logging from business logic, realizes unified logging, and does not affect the normal operation of the business system.
[0020] The beneficial effects of the present invention are:
[0021] 1. Improve system efficiency: By reducing unnecessary security verification requests and optimizing log recording methods, the system's response speed and overall efficiency are effectively improved, and users can obtain the required services and information more quickly.
[0022] 2. Enhanced system security: The introduction of Token mechanism and dynamic key management has enhanced the security of the system, effectively prevented unauthorized access and malicious attacks, and protected the information security of the system and users.
[0023] 3. Simplify development and maintenance: Through unified authentication and logging methods, the workload of developers for permission management and logging is reduced, the development cost and maintenance difficulty are reduced, and the maintainability and scalability of the system are improved.
[0024] 4. Improve user experience: As the efficiency and security of the system have been improved, users can use system functions more smoothly and get a better user experience, thereby enhancing user satisfaction.
[0025] 5. Real-time logging and monitoring: The asynchronous logging mechanism can record the user's operation behavior and the system's operating status in real time, providing system administrators with more comprehensive and accurate log information, helping them to discover and solve problems in a timely manner, and improving the stability and reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 is an access logic flow chart of an embodiment of the present invention;
[0027] Figure 2 Schematic diagram of the authentication and unified log process in an embodiment of the present invention. DETAILED DESCRIPTION
[0028] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0029] Example 1
[0030] like Figure 1 and Figure 2 As shown, a unified authentication and logging method for a cloud platform includes the following steps:
[0031] Step S100: define a main project with menus, roles, and users. This project is mainly used to unify user login, integrate various sub-business projects, and return the user's menu, login token, etc.
[0032] Step S200: Create a gateway project and define the global filter GlobalFilter. When accessed from the front end, all business interfaces are mapped to the gateway project through nginx, and then forwarded to the corresponding business project through openFeign via the route configured in the gateway project. It is worth noting that the main project and all business projects must be registered in the same namespace on nacos.
[0033] Step S300: When the page logs in, it is forwarded to the main project by the gateway project. After the shiro login verification is passed, a java web Token object is created, and the jwt Token information is stored in redis, and the token information is returned. Since the login interface has been whitelisted, it can be released directly.
[0034] Step S400: When the page is logged in, a symmetric key is generated at the same time, and the key is placed in redis (the key is generated by a background timer task and has an expiration time. The expired key is stored in the database, and a maximum of n keys are retained, which is reasonably set according to the expiration time). It is returned to the front end, and the encrypted value of the URL path is carried when requesting. The back end first uses the key in redis for decryption. If the decryption fails, the key in the database is used to decrypt and compare whether it is the current URL path. If successful, the latest redis key is returned to maintain the validity of the key without the user's perception.
[0035] Step S500: When other interfaces are accessed, first determine whether the interface path is in the whitelist. If so, it is directly released without verification. Otherwise, verification is required.
[0036] Step S600: Verify the token carried by the front end to determine whether the token exists. It should be noted that the token is generated by the main project and placed in redis. The gateway needs to obtain it together with a redis, so there is no need to request the main project again, reducing the access frequency and improving the access response.
[0037] Step S700: To prevent the token from expiring frequently, after verification, the expiration time of the token needs to be reset and put back into redis.
[0038] Step S800: The asynchronous thread sends the user name, IP, request address, request parameters, time consumed, operation, etc. to the designated queue through RabbitMQ. The main project is responsible for receiving queue messages and persisting them in the database. The front-end page can display the message log in real time.
[0039] Step S900: If the rabbitmq message consumption fails, it enters the dead letter queue. After half an hour, it is consumed again in the queue.
[0040] Step S1000: It is worth noting that each business project corresponds to a page menu. When adding a new project, you only need to add the configuration and corresponding routes in the background. The front-end access is forwarded to the gateway through nginx, and the gateway forwards according to the configured route. The sub-business does not need to do any other operations to complete unified authentication and logging. When subsequent authentication or logging needs to be iterated, it will not affect the sub-business. You only need to modify the gateway project and go back online.
[0041] Example 2
[0042] A unified authentication and log recording method for a cloud platform, comprising:
[0043] Define the main project: Create a main project that contains information such as users, roles, menus, etc. for unified user login and permission management.
[0044] Create a Gateway project: Create a Gateway project and use the global filter GlobalFilter to implement unified interception and processing of requests. All requests are mapped to the Gateway project through nginx and then forwarded to the corresponding business project through OpenFeign.
[0045] Token mechanism: When the user logs in, the main project uses Shiro to verify the user. After the verification, a Java Web Token is generated and stored in Redis, which is returned to the front end. Subsequent requests carry the Token for verification, avoiding the problem of needing to access the security verification project for each request.
[0046] Dynamic key management: A symmetric key is generated and stored in Redis when the page logs in. The encrypted value of the URL path is carried during the request. The backend uses the key in Redis for decryption to maintain the validity of the key and improve security.
[0047] Whitelist configuration: The interfaces in the whitelist are directly released without verification, which reduces unnecessary verification process and improves access efficiency.
[0048] Asynchronous logging: RabbitMQ is used to implement asynchronous logging, and information such as user name, IP, request address, parameters, and time consumption are sent to the specified queue. The main project is responsible for receiving and persisting the information in the database to achieve real-time logging and display.
[0049] Flexible configuration and scalability: When adding a new business project, you only need to add configuration and corresponding routes in the background, and perform unified authentication and logging through Gateway. Subsequent iterations will not affect sub-businesses. You only need to modify the Gateway project to achieve flexible configuration and scalability.
[0050] The above-mentioned embodiments only express the specific implementation of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.
Claims
1. A unified authentication and log recording method for a cloud platform, characterized in that: The following steps are involved: Step 1: Define the main project to unify user login and integrate various sub-business projects; Step 2: Create a Gateway project and use the global filter GlobalFilter to implement unified interception and processing of requests. All requests are mapped to the Gateway project through nginx and then forwarded to the corresponding business project through OpenFeign. Step 3: When the user logs in, the Gateway project forwards the request to the main project. The main project uses Shiro to verify the user. After the verification, a Java Web Token is generated and stored in Redis. The login interface is whitelisted, and subsequent requests carry the Token for verification. Step 4: Generate a symmetric key when logging in to the page and store it in Redis. When requesting, carry the encrypted value of the URL path, and the backend uses the key in Redis to decrypt it. Step 5: Configure the login interface in the whitelist to be released directly; verify through the Token carried by the front end to determine whether the Token exists, and obtain it together with a Redis in the Gateway project; Step 6: Use RabbitMQ to implement asynchronous logging and send it to the specified queue. The main project is responsible for receiving it and persisting it in the database. Step 7: When adding a new business project, add configuration and corresponding routes through the background, and implement unified authentication and logging through Gateway.
2. The unified authentication and logging method for a cloud platform according to claim 1, characterized in that: In step 1, the main project includes menus, roles and user information.
3. The unified authentication and logging method for a cloud platform according to claim 1, characterized in that: In step 1 and step 2, the main project and all business projects are registered in the same namespace on nacos.
4. The unified authentication and logging method for a cloud platform according to claim 1, characterized in that: In step 1, in step 4, if the decryption fails, the key in the database is used to decrypt and compare whether it is the current URL path. If successful, the latest Redis key is returned.
5. The unified authentication and logging method for a cloud platform according to claim 1, characterized in that: In step 1 and step 6, if the RabbitMQ message consumption fails, it enters the dead letter queue and is consumed again in the queue after a period of time.
6. The unified authentication and logging method for a cloud platform according to claim 1, characterized in that: In step 1, in order to prevent the token from expiring frequently, after the verification is passed, the expiration time of the Token is reset and put back into Redis.
