CN109376526A - Authority control method and device, electronic equipment and computer readable storage medium - Google Patents
Authority control method and device, electronic equipment and computer readable storage medium Download PDFInfo
- Publication number
- CN109376526A CN109376526A CN201811134085.7A CN201811134085A CN109376526A CN 109376526 A CN109376526 A CN 109376526A CN 201811134085 A CN201811134085 A CN 201811134085A CN 109376526 A CN109376526 A CN 109376526A
- Authority
- CN
- China
- Prior art keywords
- transaction
- authorization
- sub
- message
- authority
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/30—Authentication, i.e. establishing the identity or authorisation of security principals
- G06F21/45—Structures or tools for the administration of authentication
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/466—Transaction processing
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Computer Security & Cryptography (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer Hardware Design (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本公开实施例公开了一种权限控制方法、装置、电子设备及计算机可读存储介质,所述方法包括:接收分布式事务,并将所述分布式事务拆分为主事务和至少一个子事务;对所述主事务进行权限授权操作;当所述权限授权操作反馈权限授权成功时,采用消息中间件执行所述至少一个子事务的权限授权操作,直至权限授权成功。该方案能够结合多个维度进行业务服务的权限控制,提高权限控制的适用范围。
Embodiments of the present disclosure disclose an authority control method, apparatus, electronic device, and computer-readable storage medium. The method includes: receiving a distributed transaction, and splitting the distributed transaction into a main transaction and at least one sub-transaction ; Perform the authority authorization operation on the main transaction; when the authority authorization operation reports that the authority authorization is successful, the message middleware is used to execute the authority authorization operation of the at least one sub-transaction until the authority authorization is successful. The solution can combine multiple dimensions to control the authority of business services, and improve the scope of application of authority control.
Description
技术领域technical field
本公开涉及计算机的数据处理技术领域,具体涉及一种权限控制方法、装置、电子设备及计算机可读存储介质。The present disclosure relates to the technical field of computer data processing, and in particular, to an authority control method, an apparatus, an electronic device, and a computer-readable storage medium.
背景技术Background technique
随着经济发展,企业规模的不断扩大,企业处理数据量大幅提升,尤其对于跨地域的企业来说,采用异地多数据中心的方式来管理公司数据已成为趋势,根据业务的复杂性,需要用户访问多个数据中心进行业务处理,然而多数据中心管理容易造成业务处理混乱,权限管理滥用的情况发生。因此,权限系统应运而生,权限系统根据权限系统设置的安全规则或者安全策略,用户可以访问而且只能访问自己被授权的资源。With the economic development and the continuous expansion of the scale of enterprises, the amount of data processed by enterprises has greatly increased. Especially for cross-regional enterprises, it has become a trend to use multiple data centers in different places to manage company data. According to the complexity of the business, users are required to Access to multiple data centers for business processing, however, multi-data center management is likely to cause confusion in business processing and abuse of authority management. Therefore, the permission system came into being. According to the security rules or security policies set by the permission system, the user can access and only access the resources authorized by him.
目前,权限系统是一个几乎所有后台管理系统都会涉及的一个重要组成部分,主要目的是对整个后台系统数据进行权限控制。权限系统用于资源的权限控制,所谓资源就是一切可以授权的东西,例如,角色、页面或接口都可以是资源。当通过权限系统对用户进行授权时,如果用户申请的权限比较多,就会调用很多其他服务,就会涉及到分布式事务,在这种情况下就必须保证授权数据一致性,避免出现有些权限授权成功,有些权限授权失败的情况。一般采用的分布式事务的处理方式如下:一种为将分布式事务拆分成本地事务的方案,通过本地消息表保证数据一致性,该方案基本避免了分布式事务,但是,本地消息表是关系型数据库,而关系型数据库在吞吐量和性能方面存在瓶颈,频繁的读写消息会给关系型数据库造成压力,所以在高并发场景下,该方案会存在性能限制。一种为通过调用接口对涉及到分布式事务的业务服务(即上述的资源对应的业务)回滚的方案,在对业务服务授权失败后,对分布式事务对应的业务权限数据进行回滚,但是该方案一般按照串行的方式调用一系列业务服务的授权服务,在串行的服务较多时,回滚成本很高,并且很多授权服务很难直接回滚,所以非常有局限性。At present, the authority system is an important part involved in almost all background management systems, and the main purpose is to control the authority of the entire background system data. The permission system is used to control the permissions of resources. The so-called resources are everything that can be authorized. For example, roles, pages or interfaces can be resources. When authorizing users through the permission system, if the user applies for more permissions, many other services will be called, which will involve distributed transactions. In this case, the consistency of the authorization data must be guaranteed to avoid some permissions. The authorization is successful, and some authorization authorization fails. The generally adopted processing methods of distributed transactions are as follows: a scheme for splitting distributed transactions into local transactions, ensuring data consistency through the local message table, this scheme basically avoids distributed transactions, but the local message table is Relational databases, and relational databases have bottlenecks in throughput and performance. Frequent reading and writing messages will put pressure on relational databases. Therefore, in high concurrency scenarios, this solution will have performance limitations. A solution is to roll back a business service involving a distributed transaction (that is, the business corresponding to the above-mentioned resource) by calling an interface. After the authorization of the business service fails, the business authority data corresponding to the distributed transaction is rolled back, However, this scheme generally calls the authorization services of a series of business services in a serial manner. When there are many serial services, the rollback cost is high, and many authorization services are difficult to roll back directly, so they are very limited.
发明内容SUMMARY OF THE INVENTION
本公开实施例提供一种权限控制方法、装置、电子设备及计算机可读存储介质。Embodiments of the present disclosure provide an authority control method, an apparatus, an electronic device, and a computer-readable storage medium.
第一方面,本公开实施例中提供了一种权限控制方法。In a first aspect, an authority control method is provided in the embodiments of the present disclosure.
具体的,所述权限控制方法,包括:Specifically, the authority control method includes:
接收分布式事务,并将所述分布式事务拆分为主事务和至少一个子事务;receiving a distributed transaction, and splitting the distributed transaction into a main transaction and at least one sub-transaction;
对所述主事务进行权限授权操作;Perform a permission authorization operation on the main transaction;
当所述权限授权操作反馈权限授权成功时,采用消息中间件执行所述至少一个子事务的权限授权操作,直至权限授权成功。When the permission authorization operation reports that the permission authorization is successful, the message middleware is used to execute the permission authorization operation of the at least one sub-transaction until the permission authorization is successful.
结合第一方面,本公开在第一方面的第一种实现方式中,所述接收分布式事务,并将所述分布式事务拆分为主事务和至少一个子事务,包括:With reference to the first aspect, in a first implementation manner of the first aspect of the present disclosure, the receiving a distributed transaction and splitting the distributed transaction into a main transaction and at least one sub-transaction include:
接收所述分布式事务;receiving the distributed transaction;
获取所述分布式事务的内容数据;obtaining the content data of the distributed transaction;
根据所述内容数据,将所述分布式事务拆分为所述主事务和所述至少一个子事务。The distributed transaction is split into the main transaction and the at least one sub-transaction according to the content data.
结合第一方面和第一方面的第一种实现方式,本公开在第一方面的第二种实现方式中,所述当所述权限授权操作反馈权限授权成功时,采用消息中间件执行所述至少一个子事务的权限授权操作,直至权限授权成功,包括:In combination with the first aspect and the first implementation manner of the first aspect, in the second implementation manner of the first aspect of the present disclosure, when the permission authorization operation reports that permission authorization is successful, use message middleware to execute the The authorization authorization operation of at least one sub-transaction until the authorization is successful, including:
当所述权限授权操作反馈权限授权成功时,生成推送消息,所述推送消息中携带有所述至少一个子事务分别对应的权限授权标记;When the authority authorization operation reports that authority authorization is successful, a push message is generated, and the push message carries authority authorization tags corresponding to the at least one sub-transaction respectively;
通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务执行所述推送消息,进行所述至少一个子事务的权限授权操作,直至权限授权成功。Push the push message through the message middleware to trigger the at least one sub-transaction corresponding to the permission authorization flag to execute the push message, and perform the permission authorization operation of the at least one sub-transaction until the permission authorization is successful .
结合第一方面的第二种实现方式,本公开在第一方面的第三种实现方式中,还包括:In conjunction with the second implementation manner of the first aspect, in the third implementation manner of the first aspect, the present disclosure further includes:
记录所述至少一个子事务响应所述推送消息的状态,得到包含至少一个子事务对应的消息消费状态的消息消费状态表;Record the state of the at least one sub-transaction in response to the push message, and obtain a message consumption state table including the message consumption state corresponding to the at least one sub-transaction;
实时监听所述消息消费状态表,处理被重复消费的消息。Monitor the message consumption status table in real time, and process the repeatedly consumed messages.
结合第一方面的第二种实现方式和第一方面的第三种实现方式,本公开在第一方面的第四种实现方式中,所述通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务执行所述推送消息,进行所述至少一个子事务的权限授权操作,直至权限授权成功,包括:With reference to the second implementation manner of the first aspect and the third implementation manner of the first aspect, in the fourth implementation manner of the first aspect of the present disclosure, the push message is pushed through the message middleware to Triggering the at least one sub-transaction corresponding to the permission authorization mark to execute the push message, and performing the permission authorization operation of the at least one sub-transaction until the permission authorization is successful, including:
通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务各自响应所述推送消息;Pushing the push message through the message middleware, so as to trigger the at least one sub-transaction corresponding to the permission authorization tag to respectively respond to the push message;
采用本地事务方式对所述至少一个子事务进行权限授权操作;Perform a permission authorization operation on the at least one sub-transaction in a local transaction mode;
当所述权限授权操作反馈权限授权成功时,丢弃所述推送消息;When the permission authorization operation reports that permission authorization is successful, discarding the push message;
当所述权限授权操作反馈权限授权失败时,利用所述消息中间件重新获取所述推送消息,并将所述推送消息与所述消息消费状态表进行对比;When the permission authorization operation reports that permission authorization fails, use the message middleware to re-acquire the push message, and compare the push message with the message consumption status table;
当所述消息消费状态表中存在所述推送消息的消费状态信息,且所述消费状态信息为成功时,丢弃所述推送消息;When the consumption status information of the push message exists in the message consumption status table, and the consumption status information is successful, discarding the push message;
当所述消息消费状态表中存在所述推送消息的消费状态信息,且所述消费状态信息为失败时,重新执行所述推送消息,进行所述至少一个子事务中未权限授权成功的子事务的权限授权操作,直至权限授权成功。When the consumption status information of the push message exists in the message consumption status table, and the consumption status information is a failure, the push message is re-executed, and the sub-transaction of the at least one sub-transaction that has not been authorized successfully is executed. the authorization authorization operation until the authorization authorization succeeds.
结合第一方面、第一方面的第一种实现方式、第一方面的第二种实现方式、第一方面的第三种实现方式和第一方面的第四种实现方式,本公开在第一方面的第五种实现方式中,所述对所述主事务进行权限授权操作之后,还包括:In conjunction with the first aspect, the first implementation manner of the first aspect, the second implementation manner of the first aspect, the third implementation manner of the first aspect, and the fourth implementation manner of the first aspect, the present disclosure is described in the first In a fifth implementation manner of the aspect, after the authority authorization operation is performed on the main transaction, the method further includes:
当所述权限授权操作反馈权限授权失败时,对所述主事务进行回滚操作。When the permission authorization operation reports that permission authorization fails, a rollback operation is performed on the main transaction.
结合第一方面、第一方面的第一种实现方式、第一方面的第二种实现方式、第一方面的第三种实现方式、第一方面的第四种实现方式和第一方面的第五种实现方式,本公开在第一方面的第六种实现方式中,In combination with the first aspect, the first implementation manner of the first aspect, the second implementation manner of the first aspect, the third implementation manner of the first aspect, the fourth implementation manner of the first aspect, and the third implementation manner of the first aspect Five implementations, the present disclosure is in the sixth implementation of the first aspect,
所述分布式事务包括待授权事务和发起待授权事务的申请事务,所述主事务为所述申请事务,所述至少一个子事务为所述待授权事务。The distributed transaction includes a transaction to be authorized and an application transaction that initiates a transaction to be authorized, the main transaction is the application transaction, and the at least one sub-transaction is the transaction to be authorized.
结合第一方面、第一方面的第一种实现方式、第一方面的第二种实现方式、第一方面的第三种实现方式、第一方面的第四种实现方式、第一方面的第五种实现方式和第一方面的第六种实现方式,本公开在第一方面的第七种实现方式中,还包括:In combination with the first aspect, the first implementation manner of the first aspect, the second implementation manner of the first aspect, the third implementation manner of the first aspect, the fourth implementation manner of the first aspect, and the third implementation manner of the first aspect Five implementation manners and the sixth implementation manner of the first aspect, in the seventh implementation manner of the first aspect, the present disclosure further includes:
实时监听所述至少一个子事务的权限授权操作,记录异常权限授权信息,供重试权限授权操作时使用。The permission authorization operation of the at least one sub-transaction is monitored in real time, and abnormal permission authorization information is recorded for use when retrying the permission authorization operation.
第二方面,本公开实施例中提供了一种权限控制装置。In a second aspect, an embodiment of the present disclosure provides an authority control apparatus.
具体的,所述权限控制装置,包括:Specifically, the authority control device includes:
接收模块,被配置为接收分布式事务;a receiving module, configured to receive distributed transactions;
拆分模块,被配置为将所述分布式事务拆分为主事务和至少一个子事务;a splitting module configured to split the distributed transaction into a main transaction and at least one sub-transaction;
授权模块,被配置为对所述主事务进行权限授权操作,以及当所述权限授权操作反馈权限授权成功时,采用消息中间件执行所述至少一个子事务的权限授权操作,直至权限授权成功。The authorization module is configured to perform a permission authorization operation on the main transaction, and when the permission authorization operation reports that the permission authorization is successful, use the message middleware to perform the permission authorization operation of the at least one sub-transaction until the permission authorization is successful.
结合第二方面,本公开在第二方面的第一种实现方式中,所述拆分模块包括:In conjunction with the second aspect, in a first implementation manner of the second aspect of the present disclosure, the splitting module includes:
获取子模块,被配置为获取所述分布式事务的内容数据;an acquisition submodule, configured to acquire the content data of the distributed transaction;
拆分子模块,被配置为根据所述内容数据,将所述分布式事务拆分为所述主事务和所述至少一个子事务。A splitting sub-module is configured to split the distributed transaction into the main transaction and the at least one sub-transaction according to the content data.
结合第二方面和第二方面的第一种实现方式,本公开在第二方面的第二种实现方式中,所述授权模块包括:In combination with the second aspect and the first implementation manner of the second aspect, in a second implementation manner of the second aspect of the present disclosure, the authorization module includes:
生成子模块,被配置为当所述权限授权操作反馈权限授权成功时,生成推送消息,所述推送消息中携带有所述至少一个子事务分别对应的权限授权标记;A generating submodule, configured to generate a push message when the authority authorization operation reports that authority authorization is successful, and the push message carries the authority authorization mark corresponding to the at least one sub-transaction respectively;
授权子模块,被配置为通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务执行所述推送消息,进行所述至少一个子事务的权限授权操作,直至权限授权成功。An authorization submodule, configured to push the push message through the message middleware, so as to trigger the at least one sub-transaction corresponding to the authority authorization mark to execute the push message, and to execute the authority of the at least one sub-transaction Authorize the operation until the authorization is successful.
结合第二方面的第二种实现方式,本公开在第二方面的第三种实现方式中,所述权限控制装置还包括:With reference to the second implementation manner of the second aspect, in a third implementation manner of the second aspect of the present disclosure, the authority control apparatus further includes:
记录监听模块,被配置为记录所述至少一个子事务响应所述推送消息的状态,得到包含至少一个子事务对应的消息消费状态的消息消费状态表;及实时监听所述消息消费状态表,处理被重复消费的消息。a recording monitoring module, configured to record the state of the at least one sub-transaction in response to the push message, and obtain a message consumption status table including the message consumption status corresponding to the at least one sub-transaction; and monitor the message consumption status table in real time, and process Messages that are repeatedly consumed.
结合第二方面的第二种实现方式和第二方面的第三种实现方式,本公开在第二方面的第四种实现方式中,所述授权子模块包括:In combination with the second implementation manner of the second aspect and the third implementation manner of the second aspect, in a fourth implementation manner of the second aspect of the present disclosure, the authorization submodule includes:
推送子模块,被配置为通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务各自响应所述推送消息;a push submodule, configured to push the push message through the message middleware, so as to trigger the at least one sub-transaction corresponding to the permission authorization tag to respectively respond to the push message;
授权子模块,被配置为采用本地事务方式对所述至少一个子事务进行权限授权操作;an authorization sub-module, configured to perform a permission authorization operation on the at least one sub-transaction in a local transaction mode;
丢弃子模块,被配置为当所述权限授权操作反馈权限授权成功时,丢弃所述推送消息;A discarding submodule, configured to discard the push message when the permission authorization operation reports that the permission authorization is successful;
获取子模块,被配置为当所述权限授权操作反馈权限授权失败时,利用所述消息中间件重新获取所述推送消息;an acquisition sub-module, configured to re-acquire the push message by using the message middleware when the authorization authorization operation reports that authorization authorization fails;
对比子模块,被配置为将所述推送消息与所述消息消费状态表进行对比;a comparison submodule, configured to compare the push message with the message consumption status table;
所述丢弃子模块,还被配置为当所述消息消费状态表中存在所述推送消息的消费状态信息,且所述消费状态信息为成功时,丢弃所述推送消息;The discarding submodule is further configured to discard the push message when there is consumption status information of the push message in the message consumption status table and the consumption status information is successful;
所述授权子模块,还被配置为当所述消息消费状态表中存在所述推送消息的消费状态信息,且所述消费状态信息为失败时,重新执行所述推送消息,进行所述至少一个子事务中未权限授权成功的子事务的权限授权操作,直至权限授权成功。The authorization sub-module is further configured to re-execute the push message when the consumption status information of the push message exists in the message consumption status table and the consumption status information is failed, and perform the at least one Permission authorization operations of sub-transactions that are not authorized successfully in sub-transactions, until the authorization is successful.
结合第二方面、第二方面的第一种实现方式、第二方面的第二种实现方式、第二方面的第三种实现方式和第二方面的第四种实现方式,本公开在第二方面的第五种实现方式中,所述权限控制装置还包括:In conjunction with the second aspect, the first implementation manner of the second aspect, the second implementation manner of the second aspect, the third implementation manner of the second aspect, and the fourth implementation manner of the second aspect, the present disclosure is described in the second In a fifth implementation manner of the aspect, the authority control device further includes:
回滚模块,被配置为所述对所述主事务进行权限授权操作之后,当所述权限授权操作反馈权限授权失败时,对所述主事务进行回滚操作。The rollback module is configured to perform a rollback operation on the main transaction after the authority authorization operation is performed on the main transaction, when the authority authorization operation reports that authority authorization fails.
结合第二方面、第二方面的第一种实现方式、第二方面的第二种实现方式、第二方面的第三种实现方式、第二方面的第四种实现方式和第二方面的第五种实现方式,本公开在第二方面的第六种实现方式中,Combining the second aspect, the first implementation manner of the second aspect, the second implementation manner of the second aspect, the third implementation manner of the second aspect, the fourth implementation manner of the second aspect, and the third implementation manner of the second aspect Five implementations, the present disclosure is in the sixth implementation of the second aspect,
所述分布式事务包括待授权事务和发起待授权事务的申请事务,所述主事务为所述申请事务,所述至少一个子事务为所述待授权事务。The distributed transaction includes a transaction to be authorized and an application transaction that initiates a transaction to be authorized, the main transaction is the application transaction, and the at least one sub-transaction is the transaction to be authorized.
结合第二方面、第二方面的第一种实现方式、第二方面的第二种实现方式、第二方面的第三种实现方式、第二方面的第四种实现方式、第二方面的第五种实现方式和第二方面的第六种实现方式,本公开在第二方面的第七种实现方式中,In combination with the second aspect, the first implementation manner of the second aspect, the second implementation manner of the second aspect, the third implementation manner of the second aspect, the fourth implementation manner of the second aspect, and the third implementation manner of the second aspect Five implementations and the sixth implementation of the second aspect, the present disclosure is in the seventh implementation of the second aspect,
所述权限控制装置还包括:The authority control device further includes:
记录监听模块,被配置为实时监听所述至少一个子事务的权限授权操作,记录异常权限授权信息,供重试权限授权操作时使用。The record monitoring module is configured to monitor the authority authorization operation of the at least one sub-transaction in real time, and record abnormal authority authorization information for use when retrying the authority authorization operation.
第三方面,本公开实施例提供了一种电子设备,包括存储器和处理器,所述存储器用于存储一条或多条支持权限控制装置执行上述第一方面中权限控制方法的计算机指令,所述处理器被配置为用于执行所述存储器中存储的计算机指令。所述权限控制装置还可以包括通信接口,用于权限控制装置与其他设备或通信网络通信。In a third aspect, an embodiment of the present disclosure provides an electronic device, including a memory and a processor, where the memory is configured to store one or more computer instructions that support the permission control apparatus to execute the permission control method in the first aspect, the The processor is configured to execute computer instructions stored in the memory. The authority control apparatus may further include a communication interface for the authority control apparatus to communicate with other devices or a communication network.
第四方面,本公开实施例提供了一种计算机可读存储介质,用于存储权限控制装置所用的计算机指令,其包含用于执行上述第一方面中权限控制方法为权限控制装置所涉及的计算机指令。In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium for storing computer instructions used by an authority control apparatus, which includes a computer used for executing the authority control method in the above-mentioned first aspect as the authority control apparatus. instruction.
本公开实施例提供的技术方案可以包括以下有益效果:The technical solutions provided by the embodiments of the present disclosure may include the following beneficial effects:
上述技术方案,通过将分布式事务进行拆分,对拆分的主事务和至少一个子事务进行不同的权限授权处理,实现了结合多个维度进行业务服务的权限控制,提高权限控制的适用范围。The above technical solution, by splitting the distributed transaction, and performing different authorization processing on the split main transaction and at least one sub-transaction, realizes the authority control of business services in combination with multiple dimensions, and improves the scope of application of the authority control. .
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本公开。It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure.
附图说明Description of drawings
结合附图,通过以下非限制性实施方式的详细描述,本公开的其它特征、目的和优点将变得更加明显。在附图中:Other features, objects and advantages of the present disclosure will become more apparent from the following detailed description of non-limiting embodiments, taken in conjunction with the accompanying drawings. In the attached image:
图1示出根据本公开一实施方式的权限控制方法的流程图;FIG. 1 shows a flowchart of an authority control method according to an embodiment of the present disclosure;
图2示出根据图1所示实施方式的权限控制方法的步骤S101的流程图;Fig. 2 shows a flowchart of step S101 of the authority control method according to the embodiment shown in Fig. 1;
图3示出根据图1所示实施方式的权限控制方法的步骤S103的流程图;FIG. 3 shows a flowchart of step S103 of the authority control method according to the embodiment shown in FIG. 1;
图4示出根据本公开另一实施方式的权限控制方法的流程图;FIG. 4 shows a flowchart of a permission control method according to another embodiment of the present disclosure;
图5示出根据本公开又一实施方式的权限控制方法的流程图;FIG. 5 shows a flowchart of a permission control method according to yet another embodiment of the present disclosure;
图6示出根据本公开一实施方式的权限控制装置的结构框图;FIG. 6 shows a structural block diagram of an authority control apparatus according to an embodiment of the present disclosure;
图7示出根据图6所示实施方式的权限控制装置的拆分模块602的结构框图;FIG. 7 shows a structural block diagram of the splitting module 602 of the authority control apparatus according to the embodiment shown in FIG. 6;
图8示出根据图6所示实施方式的权限控制装置的授权模块603的结构框图;Fig. 8 shows a structural block diagram of the authorization module 603 of the authority control apparatus according to the embodiment shown in Fig. 6;
图9示出根据本公开另一实施方式的权限控制装置的结构框图;FIG. 9 shows a structural block diagram of an authority control apparatus according to another embodiment of the present disclosure;
图10示出根据图8所示实施方式的权限控制装置的授权子模块802的结构框图;Fig. 10 shows a structural block diagram of the authorization sub-module 802 of the authority control apparatus according to the embodiment shown in Fig. 8;
图11示出根据本公开又一实施方式的权限控制装置的结构框图;FIG. 11 shows a structural block diagram of an authority control apparatus according to still another embodiment of the present disclosure;
图12示出根据本公开一实施方式的电子设备的结构框图;FIG. 12 shows a structural block diagram of an electronic device according to an embodiment of the present disclosure;
图13是适于用来实现根据本公开一实施方式的权限控制方法的计算机系统的结构示意图。FIG. 13 is a schematic structural diagram of a computer system suitable for implementing the authority control method according to an embodiment of the present disclosure.
具体实施方式Detailed ways
下文中,将参考附图详细描述本公开的示例性实施方式,以使本领域技术人员可容易地实现它们。此外,为了清楚起见,在附图中省略了与描述示例性实施方式无关的部分。Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings so that those skilled in the art can easily implement them. Also, for the sake of clarity, parts unrelated to describing the exemplary embodiments are omitted from the drawings.
在本公开中,应理解,诸如“包括”或“具有”等的术语旨在指示本说明书中所公开的特征、数字、步骤、行为、部件、部分或其组合的存在,并且不欲排除一个或多个其他特征、数字、步骤、行为、部件、部分或其组合存在或被添加的可能性。In the present disclosure, it should be understood that terms such as "comprising" or "having" are intended to indicate the presence of features, numbers, steps, acts, components, parts, or combinations thereof disclosed in this specification, and are not intended to exclude a or multiple other features, numbers, steps, acts, components, parts, or combinations thereof may exist or be added.
另外还需要说明的是,在不冲突的情况下,本公开中的实施例及实施例中的特征可以相互组合。下面将参考附图并结合实施例来详细说明本公开。In addition, it should be noted that the embodiments of the present disclosure and the features of the embodiments may be combined with each other under the condition of no conflict. The present disclosure will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
本公开实施例提供的技术方案通过将分布式事务进行拆分,对拆分的主事务和至少一个子事务进行不同的权限授权处理,实现了结合多个维度进行业务服务的权限控制,提高权限控制的适用范围。The technical solution provided by the embodiment of the present disclosure realizes the authority control of business services in combination with multiple dimensions by splitting the distributed transaction, and performing different authority authorization processing on the split main transaction and at least one sub-transaction, thereby improving authority Scope of control.
图1示出根据本公开一实施方式的权限控制方法的流程图。如图1所示,所述权限控制方法包括以下步骤S101-S103:FIG. 1 shows a flowchart of an authority control method according to an embodiment of the present disclosure. As shown in FIG. 1, the permission control method includes the following steps S101-S103:
在步骤S101中,接收分布式事务,并将所述分布式事务拆分为主事务和至少一个子事务;In step S101, a distributed transaction is received, and the distributed transaction is split into a main transaction and at least one sub-transaction;
在步骤S102中,对所述主事务进行权限授权操作;In step S102, a permission authorization operation is performed on the main transaction;
在步骤S103中,当所述权限授权操作反馈权限授权成功时,采用消息中间件执行所述至少一个子事务的权限授权操作,直至权限授权成功。In step S103, when the authority authorization operation reports that the authority authorization is successful, the message middleware is used to execute the authority authorization operation of the at least one sub-transaction until the authority authorization is successful.
上文提及,权限系统是一个几乎所有后台管理系统都会涉及的一个重要组成部分,主要目的是对整个后台系统数据进行权限控制。当通过权限系统对用户进行授权时,如果用户申请的权限比较多,就会调用很多其他服务,就会涉及到分布式事务,在这种情况下就必须保证授权数据一致性,避免出现有些权限授权成功,有些权限授权失败的情况。一般采用的分布式事务的处理方式一种为将分布式事务拆分成本地事务的方案,通过本地消息表保证数据一致性,该方案基本避免了分布式事务;另一种为通过调用接口对涉及到分布式事务的业务服务(即上述的资源对应的业务)回滚的方案,在对业务服务授权失败后,对分布式事务对应的业务权限数据进行回滚。但是,本地消息表是关系型数据库,而关系型数据库在吞吐量和性能方面存在瓶颈,频繁的读写消息会给关系型数据库造成压力,所以在高并发场景下,该方案会存在性能限制。而且回滚的方案一般按照串行的方式调用一系列业务服务的授权服务,在串行的服务较多时,回滚成本很高,并且很多授权服务很难直接回滚,所以非常有局限性。As mentioned above, the authority system is an important part of almost all background management systems. The main purpose is to control the authority of the entire background system data. When authorizing users through the permission system, if the user applies for more permissions, many other services will be called, which will involve distributed transactions. In this case, the consistency of the authorization data must be guaranteed to avoid some permissions. The authorization is successful, and some authorization authorization fails. One of the commonly used processing methods of distributed transactions is to split distributed transactions into local transactions, and ensure data consistency through the local message table, which basically avoids distributed transactions; In the scheme of rolling back the business service (that is, the business corresponding to the above-mentioned resource) involving the distributed transaction, after the authorization of the business service fails, the business authority data corresponding to the distributed transaction is rolled back. However, the local message table is a relational database, and the relational database has bottlenecks in throughput and performance. Frequent reading and writing messages will put pressure on the relational database. Therefore, in high concurrency scenarios, this solution will have performance limitations. Moreover, the rollback scheme generally calls the authorization services of a series of business services in a serial manner. When there are many serial services, the rollback cost is high, and many authorization services are difficult to roll back directly, so they are very limited.
考虑到上述缺陷,在该实施方式中,提出一种权限控制方法,该方法通过将分布式事务进行拆分,对拆分的主事务和至少一个子事务进行不同的权限授权处理,实现了结合多个维度进行业务服务的权限控制,提高权限控制的适用范围。Considering the above-mentioned defects, in this embodiment, an authority control method is proposed. The method divides the distributed transaction and performs different authority authorization processing on the split main transaction and at least one sub-transaction, so as to realize the combination of Permission control of business services is carried out in multiple dimensions to improve the scope of application of permission control.
其中,分布式事务就是指事务的参与者、支持事务的服务器、资源服务器以及事务管理器(即权限控制装置)分别位于不同的分布式系统的不同节点之上。分布式事务包括待授权事务和发起待授权事务的申请事务,主事务为申请事务,至少一个子事务为所述待授权事务。The distributed transaction means that the participants of the transaction, the server supporting the transaction, the resource server, and the transaction manager (ie, the authority control device) are located on different nodes of different distributed systems, respectively. The distributed transaction includes a transaction to be authorized and an application transaction that initiates the transaction to be authorized. The main transaction is the application transaction, and at least one sub-transaction is the transaction to be authorized.
其中,权限控制装置可以为用户可以操作的用于设置员工或用户权限的入口,在本实施方式中,权限控制装置可以与有可视化显示装置(例如显示器)的终端的权限控制客户端进行通信,这样,用户就可以通过对终端中的可视化显示装置进行操作,实现员工或用户的权限的设定。例如,用户通过在终端上的操作,选中角色、页面、以及打印等权限为员工1进行权限授权,那么在用户选完权限范围内的功能选项(即上述的角色、页面以及打印等功能)后,通过触发确认申请功能按键,将上述操作信息发送至权限控制装置,触发权限申请,开始进行上述功能选项的权限授权操作,而整个权限设定的操作称为分布式事务,功能选项的权限授权操作称为待授权事务,触发权限申请的操作称为发起待授权事务的申请事务。在本实施方式中,由于功能选项选中的功能可以是多个,因此,待授权事务可能是多个或一个,即在本实施方式中的在权限授权的过程中,可以触发至少一个待授权事务产生,在本实施方式中不限制同时进行权限授权时待授权事务的数量。Wherein, the authority control device may be a user-operable portal for setting employee or user authority. In this embodiment, the authority control device may communicate with the authority control client of the terminal having a visual display device (such as a display), In this way, the user can set the authority of the employee or the user by operating the visual display device in the terminal. For example, the user selects roles, pages, and print permissions to authorize employee 1 through operations on the terminal, then after the user selects the functional options within the scope of permissions (that is, the above-mentioned roles, pages, and print functions) , by triggering the confirmation application function button, the above operation information is sent to the authority control device, the authority application is triggered, and the authority authorization operation of the above function options is started, and the entire authority setting operation is called a distributed transaction, and the authority authorization of the function options The operation is called the transaction to be authorized, and the operation that triggers the permission application is called the application transaction that initiates the transaction to be authorized. In this embodiment, since there can be multiple functions selected by the function option, there may be multiple or one transactions to be authorized, that is, in the process of authorization in this embodiment, at least one transaction to be authorized can be triggered Generated, in this embodiment, the number of transactions to be authorized when authorization authorization is performed at the same time is not limited.
其中,权限控制有基于资源的权限控制,也有基于角色的权限控制。在基于资源的权限控制装置中,资源指一切可以授权的东西,一个页面,一条数据,一个接口都是资源。在基于角色的权限控制装置中,一般采用基于角色的权限访问控制(RBAC,Role-BasedAccess Control),在RBAC中,权限与角色相关联,用户通过成为适当角色的成员而得到这些角色的权限,从而极大地简化了权限的管理。在一个组织中,角色是为了完成各种工作而创造,用户则依据它的责任和资格来被指派相应的角色,用户可以很容易地从一个角色被指派到另一个角色。角色可依新的需求和系统的合并而赋予新的权限,而权限也可根据需要而从某角色中回收。Among them, permission control includes resource-based permission control and role-based permission control. In the resource-based permission control device, resources refer to everything that can be authorized, and a page, a piece of data, and an interface are all resources. In role-based permission control devices, role-based permission access control (RBAC, Role-Based Access Control) is generally used. In RBAC, permissions are associated with roles, and users get the permissions of these roles by becoming members of appropriate roles. This greatly simplifies the management of permissions. In an organization, roles are created to accomplish various tasks, and users are assigned corresponding roles according to their responsibilities and qualifications. Users can easily be assigned from one role to another. Roles can be given new permissions according to new requirements and system integration, and permissions can also be withdrawn from a role as needed.
在本实施例的一个可选实现方式中,权限控制装置在接收到了通过用户操作触发的分布式事务之后,将该分布式事务拆分为主事务和至少一个子事务,该权限控制装置是先对主事务进行权限授权操作的,并且是采用本地事务方式对主事务进行权限授权操作的,权限授权操作可以是成功的,也可以是失败的,而当权限授权操作反馈权限授权成功时,表征主事务授权操作成功,那么就可以开始进行具体的至少一个子事务的权限授权操作了,这里,权限控制装置可以采用消息中间件执行至少一个子事务的权限授权操作,直至权限授权成功。In an optional implementation manner of this embodiment, after receiving the distributed transaction triggered by the user operation, the authority control apparatus splits the distributed transaction into a main transaction and at least one sub-transaction, and the authority control apparatus first The authorization operation is performed on the main transaction, and the authorization authorization operation is performed on the main transaction in the local transaction mode. The authorization authorization operation can be successful or failed. When the authorization authorization operation reports that the authorization authorization is successful, it indicates that the authorization operation is successful. If the main transaction authorization operation is successful, then the authorization authorization operation of the specific at least one sub-transaction can be started. Here, the authorization control device can use the message middleware to perform the authorization authorization operation of the at least one sub-transaction until the authorization authorization is successful.
其中,权限控制装置采用本地事务方式对主事务进行权限授权操作具体实现可以为通过本地数据库进行业务编排和异步恢复实现。Wherein, the authority control device uses the local transaction mode to perform authority authorization operation on the main transaction. The specific implementation may be business arrangement and asynchronous recovery through a local database.
在本实施例的一个可选实现方式中,如图2所示,所述步骤S101,即接收分布式事务,并将分布式事务拆分为主事务和至少一个子事务的步骤,包括步骤S201-S203:In an optional implementation manner of this embodiment, as shown in FIG. 2 , the step S101, that is, the step of receiving a distributed transaction and splitting the distributed transaction into a main transaction and at least one sub-transaction includes step S201 -S203:
在步骤S201中,接收所述分布式事务;In step S201, the distributed transaction is received;
在步骤S202中,获取所述分布式事务的内容数据;In step S202, obtain the content data of the distributed transaction;
在步骤S203中,根据所述内容数据,将所述分布式事务拆分为所述主事务和所述至少一个子事务。In step S203, according to the content data, the distributed transaction is split into the main transaction and the at least one sub-transaction.
在本实施方式中,权限控制装置可以通过对分布式事务基于业务内容的不同进行拆分,先对主事务进行权限授权操作,再对至少一个子事务进行权限授权操作,并且采用不同的权限授权操作实现一个不同的事务权限授权操作,提高了处理事务的灵活性和多样性。In this embodiment, the authority control device can split the distributed transaction based on the difference of the business content, first perform the authority authorization operation on the main transaction, and then perform the authority authorization operation on at least one sub-transaction, and use different authority authorizations The operation implements a different transaction authorization authorization operation, which improves the flexibility and diversity of transaction processing.
其中,权限控制装置在接收分布式事务后,可以通过分布式事务的触发操作获取分布式事务的内容数据;其中,内容数据为业务对应的内容;这样,该权限控制装置就可以根据内容数据,将分布式事务拆分为至少一个子事务,即待授权事务,以及发起待授权事务的申请事务(即主事务)。Wherein, after receiving the distributed transaction, the authority control device can obtain the content data of the distributed transaction through the trigger operation of the distributed transaction; wherein, the content data is the content corresponding to the business; in this way, the authority control device can, according to the content data, The distributed transaction is split into at least one sub-transaction, that is, a transaction to be authorized, and an application transaction that initiates the transaction to be authorized (that is, a main transaction).
在本实施方式中,权限控制装置可以为申请者提供不同业务(即功能选项)的权限,而不同的业务可能需要调用不同的业务服务器实现,因此才会接收到分布式事务。In this embodiment, the authority control device may provide the applicant with authority for different services (ie, functional options), and different services may need to be implemented by calling different service servers, so that distributed transactions are received.
其中,内容数据可以理解为业务功能的类型,例如,邮件业务、打印业务,数据处理业务,角色分配等。The content data can be understood as the type of business function, for example, mail business, printing business, data processing business, role assignment, and so on.
在本实施例的一个可选实现方式中,如图3所示,所述步骤S103,即当权限授权操作反馈权限授权成功时,采用消息中间件执行至少一个子事务的权限授权操作,直至权限授权成功的步骤,包括步骤S301-S302:In an optional implementation manner of this embodiment, as shown in FIG. 3 , the step S103, that is, when the permission authorization operation reports that the permission authorization is successful, the message middleware is used to perform the permission authorization operation of at least one sub-transaction until the permission is granted. The steps of successful authorization include steps S301-S302:
在步骤S301中,当权限授权操作反馈权限授权成功时,生成推送消息,所述推送消息中携带有至少一个子事务分别对应的权限授权标记;In step S301, when the authority authorization operation reports that the authority authorization is successful, a push message is generated, and the push message carries the authority authorization mark corresponding to at least one sub-transaction respectively;
在步骤S302中,通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务执行所述推送消息,进行所述至少一个子事务的权限授权操作,直至权限授权成功。In step S302, the push message is pushed through the message middleware to trigger the at least one sub-transaction corresponding to the permission authorization mark to execute the push message, and the permission authorization operation of the at least one sub-transaction is performed , until the authorization is successful.
在本实施方式中,权限控制装置是采用消息中间件进行至少一个子事务的权限授权操作的,而消息中间件利用的持久化消息功能和重试功能成功实现至少一个子事务的权限授权,提高了权限授权的成功率。In this embodiment, the authority control device uses the message middleware to perform the authority authorization operation of at least one sub-transaction, and the persistent message function and the retry function utilized by the message middleware successfully realize the authority authorization of at least one sub-transaction, improving the The success rate of authorization authorization.
其中,消息中间件适用于需要可靠的数据传送的分布式环境中。采用消息中间件的权限控制装置中,不同的事务之间通过传递消息来激活对方的事件,完成相应的操作。当权限授权操作反馈权限授权成功时,生成推送消息,于是将推送消息发送给消息服务器,消息服务器将消息存放在若干队列中,再将推送消息转发给至少一个子事务对应的业务服务器进行权限授权操作。消息中间件能在不同平台之间通信,它常被用来屏蔽掉各种平台及协议之间的特性,实现应用程序之间的协同,其优点在于能够在客户和服务器之间提供同步和异步的连接,并且在任何时刻都可以将消息进行传送或者存储转发。Among them, message middleware is suitable for distributed environments that require reliable data transmission. In the authority control device using message middleware, different transactions activate each other's events by transmitting messages to complete corresponding operations. When the permission authorization operation reports that the permission authorization is successful, a push message is generated, and then the push message is sent to the message server. The message server stores the message in several queues, and then forwards the push message to the business server corresponding to at least one sub-transaction for permission authorization. operate. Message middleware can communicate between different platforms. It is often used to shield the characteristics between various platforms and protocols, and realize collaboration between applications. Its advantage is that it can provide synchronization and asynchronous between clients and servers. connection, and can transmit or store and forward messages at any time.
在本实施方式中,当权限授权操作反馈权限授权成功时,权限控制装置触发生成推送消息,其中,该推送消息中携带有至少一个子事务分别对应的权限授权标记,表征开始进行至少一个子事务的权限授权操作;这时,权限控制装置通过消息中间件推送推送消息,以触发与权限授权标记对应的至少一个子事务分别执行该推送消息,进行至少一个子事务的权限授权操作,利用消息中间件的持久化消息功能和重试功能直至权限授权成功。In this embodiment, when the authority authorization operation reports that authority authorization is successful, the authority control device triggers the generation of a push message, wherein the push message carries authority authorization marks corresponding to at least one sub-transaction, indicating that at least one sub-transaction starts to be performed At this time, the authority control device pushes the push message through the message middleware, so as to trigger at least one sub-transaction corresponding to the authority authorization mark to execute the push message respectively, perform the authority authorization operation of at least one sub-transaction, and use the message middle The persistent message function and retry function of the file are used until the authorization is successful.
其中,权限控制装置通过消息中间件推送推送消息,以触发与授权标记对应的至少一个子事务各自响应该推送消息,采用本地事务方式对每个子事务进行授权操作,通过调用每个子事务对应的业务服务,实现与每个子事务对应的业务服务接口的权限赋值,授权成功。Wherein, the authority control device pushes the push message through the message middleware, so as to trigger at least one sub-transaction corresponding to the authorization tag to respond to the push message, and use the local transaction mode to perform the authorization operation on each sub-transaction, by calling the service corresponding to each sub-transaction. Service, implement the permission assignment of the business service interface corresponding to each sub-transaction, and the authorization is successful.
其中,授权标记为至少一个子事务中的每个子事务与推送消息对应的标记,可以理解为该推送消息的订阅标识,消息中间件可以通过订阅关系向业务服务器接口进行消息推送,即消息中间件根据授权标记推送推送消息给至少一个子事务对应的业务服务器接口,以实现根据推送消息,进行至少一个子事务权限授权的操作。Among them, the authorization mark is the mark corresponding to each sub-transaction in the at least one sub-transaction and the push message, which can be understood as the subscription identification of the push message. The message middleware can push the message to the service server interface through the subscription relationship, that is, the message middleware The push message is pushed to the service server interface corresponding to the at least one sub-transaction according to the authorization mark, so as to implement the operation of authorizing the authority of the at least one sub-transaction according to the push message.
其中,针对订阅的理解为:消息生产者(发布)将消息发布到topic中,同时有多个消息消费者(订阅)消费该消息,发布到topic的消息会被所有订阅者消费。也即是说,特定的一条消息可以被多个消费者(这里指至少一个子事务)所接收,只要消费者订阅了某个主题。消息生产者(发布者)将消息发送到某个称为主题(topic)的虚拟通道中,topic可以被多个消费者订阅。Among them, the understanding of subscription is: a message producer (publishing) publishes a message to a topic, and multiple message consumers (subscribing) consume the message at the same time, and the message published to the topic will be consumed by all subscribers. That is to say, a specific message can be received by multiple consumers (here, at least one sub-transaction), as long as the consumers subscribe to a topic. Message producers (publishers) send messages to a virtual channel called a topic, which can be subscribed to by multiple consumers.
在本实施例的一个可选实现方式中,如图4所示,所述方法还包括根据至少一个子事务响应推送消息的状态,处理被重复消费的消息的步骤,即如图4所示,所述方法包括步骤S401-S402:In an optional implementation manner of this embodiment, as shown in FIG. 4 , the method further includes the step of processing the repeatedly consumed messages according to the status of at least one sub-transaction response to the push message, that is, as shown in FIG. 4 , The method includes steps S401-S402:
在步骤S401中,记录所述至少一个子事务响应所述推送消息的状态,得到包含至少一个子事务对应的消息消费状态的消息消费状态表;In step S401, record the state of the at least one sub-transaction in response to the push message, and obtain a message consumption state table including the message consumption state corresponding to the at least one sub-transaction;
在步骤S402中,实时监听所述消息消费状态表,处理被重复消费的消息。In step S402, the message consumption status table is monitored in real time, and the repeatedly consumed messages are processed.
在本实施方式中,权限控制装置在通过推送消息进行至少一个子事务的过程中,权限控制装置还通过一个消息消费状态表来记录消息的消费情况,避免消息被重复消费,重复授权的问题,提高了授权过程中的效率,减少了数据处理的冗余。In this embodiment, in the process of performing at least one sub-transaction by pushing messages, the authority control device also records the consumption of messages through a message consumption status table, so as to avoid the problems of repeated consumption and repeated authorization of messages. The efficiency in the authorization process is improved, and the redundancy of data processing is reduced.
其中,消息消费状态表可以是在本地建立的,用于记录本地消息的消费状态的数据结构。在本实施方式中,权限控制装置执行推送消息,实现对至少一个子事务进行权限授权的时候,权限授权成功与否都是需要进行记录,即记录消息消费,这样,当相同的推送消息再次产生,想要进行相同用户的同一个子事务的再次授权时,就可以通过消息消费状态表中的相同消息的消费情况,从而拒绝重复进行相同用户的相同子事务的授权。The message consumption state table may be a data structure established locally and used to record the consumption state of local messages. In this embodiment, when the authority control device executes the push message and implements authority authorization for at least one sub-transaction, it is necessary to record whether the authority authorization is successful or not, that is, record message consumption. In this way, when the same push message is generated again , when you want to re-authorize the same sub-transaction of the same user, you can refuse to repeat the authorization of the same sub-transaction of the same user through the consumption of the same message in the message consumption status table.
在本实施方式中,消息消费状态表在记录推送消息的时候,还可以同时记录是针对哪个用户的哪个子事务的权限授权操作的。In this embodiment, when recording the push message, the message consumption status table may also record the authority authorization operation for which user and which sub-transaction.
在本实施方式中,只要权限控制装置进行至少一个子事务的权限授权的过程中,实时记录至少一个子事务响应推送消息的状态,并且还实时监听消息消费状态表,以获知消息消费状态表中的变化,找出被重复消费的消息,并中止执行被重复消费的消息,丢弃被重复消费的消息。In this embodiment, as long as the authority control device performs authority authorization of at least one sub-transaction, it records the status of at least one sub-transaction in real time in response to the push message, and also monitors the message consumption status table in real time to know the information in the message consumption status table. , find out the repeated consumption of the message, and abort the execution of the repeated consumption of the message, discard the repeated consumption of the message.
其中,消息消费状态表可以使用nosql数据库实现,以提高数据读取速度。Among them, the message consumption status table can be implemented using the nosql database to improve the data reading speed.
进一步地,在本实施例的一个可选实现方式中,步骤S302,即通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务执行所述推送消息,进行所述至少一个子事务的权限授权操作,直至权限授权成功的步骤,包括以下步骤:Further, in an optional implementation manner of this embodiment, step S302 is to push the push message through the message middleware to trigger the at least one sub-transaction corresponding to the permission authorization mark to execute the The steps of pushing the message and performing the permission authorization operation of the at least one sub-transaction until the permission authorization succeeds include the following steps:
通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务各自响应所述推送消息;Pushing the push message through the message middleware, so as to trigger the at least one sub-transaction corresponding to the permission authorization tag to respectively respond to the push message;
采用本地事务方式对所述至少一个子事务进行权限授权操作;Perform a permission authorization operation on the at least one sub-transaction in a local transaction mode;
当所述权限授权操作反馈权限授权成功时,丢弃所述推送消息;When the permission authorization operation reports that permission authorization is successful, discarding the push message;
当所述权限授权操作反馈权限授权失败时,利用所述消息中间件重新获取所述推送消息,并将所述推送消息与所述消息消费状态表进行对比;When the permission authorization operation reports that permission authorization fails, use the message middleware to re-acquire the push message, and compare the push message with the message consumption status table;
当所述消息消费状态表中存在所述推送消息的消费状态信息,且所述消费状态信息为成功时,丢弃所述推送消息;When the consumption status information of the push message exists in the message consumption status table, and the consumption status information is successful, discarding the push message;
当所述消息消费状态表中存在所述推送消息的消费状态信息,且所述消费状态信息为失败时,重新执行所述推送消息,进行所述至少一个子事务中未权限授权成功的子事务的权限授权操作,直至权限授权成功。When the consumption status information of the push message exists in the message consumption status table, and the consumption status information is a failure, the push message is re-executed, and the sub-transaction of the at least one sub-transaction that has not been authorized successfully is executed. the authorization authorization operation until the authorization authorization succeeds.
其中,权限控制装置在获取到推送消息后,开始根据该推送消息采用本地事务方式对至少一个子事务中的每个子事务进行权限授权操作,并将推送消息与每个子事务的对应关系写在消息消费状态表中,待执行完一个子事务的本地事务后,如果执行成功,就丢弃该子事务对应的推送消息,并更新该子事务的推送消息在消息消费状态表中的消费状态信息为成功。而如果一个子事务的权限授权失败,那么,则利用消息中间件消息持久化功能和重试功能,重新获取该一个子事务对应的推送消息,并将其与本地消息消费状态表中的该一个子事务的消费状态信息做对比,如果该推送消息在消息消费状态表中为成功,则停止执行本地事务,该一个子事务不执行,并丢弃该条推送消息,否则,执行该一个子事务对应的本地事务直至执行成功,做到授权服务的等幂性,最终达到业务数据的一致性。Wherein, after acquiring the push message, the authority control device starts to perform authority authorization operation on each sub-transaction in the at least one sub-transaction in a local transaction mode according to the push message, and writes the corresponding relationship between the push message and each sub-transaction in the message In the consumption status table, after the local transaction of a sub-transaction is executed, if the execution is successful, the push message corresponding to the sub-transaction is discarded, and the consumption status information of the push message of the sub-transaction in the message consumption status table is updated as successful. . If the authorization authorization of a sub-transaction fails, then the message persistence function and retry function of the message middleware are used to re-acquire the push message corresponding to the sub-transaction, and compare it with the one in the local message consumption status table. Compare the consumption status information of the sub-transactions. If the push message is successful in the message consumption status table, stop executing the local transaction, the sub-transaction is not executed, and the push message is discarded. Otherwise, the sub-transaction corresponding to the execution is executed. The local transaction is executed successfully, so as to achieve the idempotency of the authorization service, and finally achieve the consistency of the business data.
其中,等幂性指对于同一个操作的用户多次提交,接口只进行一次操作,即针对一个用户的一个子事务至进行一次权限授权操作。一致性是指在分布式系统中,指多个节点的数据一致。这里指进行权限授权操作时,要么全部成功,要么全部失败。Among them, idempotency means that for users who submit the same operation multiple times, the interface only performs one operation, that is, for a sub-transaction of a user, until a permission authorization operation is performed. Consistency means that in a distributed system, the data of multiple nodes is consistent. This means that when the authorization authorization operation is performed, either all of them succeed or all of them fail.
在本实施例的一个可选实现方式中,如图5所示,所述步骤S102之后,即对所述主事务进行权限授权操作的步骤之后,所述方法还包括步骤S501:In an optional implementation manner of this embodiment, as shown in FIG. 5 , after the step S102, that is, after the step of performing a permission authorization operation on the main transaction, the method further includes step S501:
在步骤S501中,当所述权限授权操作反馈权限授权失败时,对所述主事务进行回滚操作。In step S501, when the authority authorization operation reports that authority authorization fails, a rollback operation is performed on the main transaction.
在本实施方式中,在权限控制装置在进行了主事务的权限授权操作之后,可能存在权限授权操作反馈权限授权成功和权限授权操作反馈权限授权失败两种结果,当权限授权操作反馈权限授权失败时,权限控制装置对主事务进行回滚操作,就不继续进行后续的至少一个子事务的权限授权操作了,只在主事务权限授权操作之后才可能进行回滚,在其他权限控制方法中的实施过程中并不采用回滚方式实现,提高了权限控制的效率。In this embodiment, after the authority control device performs the authority authorization operation of the main transaction, there may be two results of the authority authorization operation feedback authority authorization success and authority authorization operation feedback authority authorization failure, when the authority authorization operation feedback authority authorization failure When the authorization control device performs a rollback operation on the main transaction, it will not continue to perform the authorization authorization operation of at least one subsequent sub-transaction. It is only possible to perform the rollback after the authorization operation of the main transaction authorization. In other authorization control methods In the implementation process, the rollback method is not used, which improves the efficiency of permission control.
在本实施例的一个可选实现方式中,所述方法还包括:In an optional implementation manner of this embodiment, the method further includes:
实时监听所述至少一个子事务的权限授权操作,记录异常权限授权信息,供重试权限授权操作时使用。The permission authorization operation of the at least one sub-transaction is monitored in real time, and abnormal permission authorization information is recorded for use when retrying the permission authorization operation.
在本实施方式中,在整个权限控制方法中可以实时的对至少一个子事务的权限授权操作进行监控,记录权限授权操作过程中发生的数据和操作,就会异常权限授权信息,供重试权限授权操作时使用,这样可以监控到消息的处理能力和状况,及时的进行调整,提高了服务的可用性和可伸缩性。In this embodiment, in the entire authority control method, the authority authorization operation of at least one sub-transaction can be monitored in real time, the data and operations occurring during the authority authorization operation are recorded, and abnormal authority authorization information is generated for retrying the authority. It is used during authorized operations, so that the processing capability and status of messages can be monitored, and adjustments can be made in a timely manner, which improves the availability and scalability of services.
其中,异常权限授权信息可以包括异常的消息消费状态,异常的数据和异常的消息处理能力等。The abnormal authority authorization information may include abnormal message consumption status, abnormal data, abnormal message processing capability, and the like.
下述为本公开装置实施例,可以用于执行本公开方法实施例。The following are the apparatus embodiments of the present disclosure, which can be used to execute the method embodiments of the present disclosure.
图6示出根据本公开一实施方式的权限控制装置的结构框图,该装置可以通过软件、硬件或者两者的结合实现成为电子设备的部分或者全部。如图6所示,所述权限控制装置包括:FIG. 6 shows a structural block diagram of an authority control apparatus according to an embodiment of the present disclosure. The apparatus may be implemented by software, hardware, or a combination of the two to become part or all of an electronic device. As shown in Figure 6, the authority control device includes:
接收模块601,被配置为接收分布式事务;A receiving module 601, configured to receive distributed transactions;
拆分模块602,被配置为将所述分布式事务拆分为主事务和至少一个子事务;A splitting module 602, configured to split the distributed transaction into a main transaction and at least one sub-transaction;
授权模块603,被配置为对所述主事务进行权限授权操作,以及当所述权限授权操作反馈权限授权成功时,采用消息中间件执行所述至少一个子事务的权限授权操作,直至权限授权成功。The authorization module 603 is configured to perform a permission authorization operation on the main transaction, and when the permission authorization operation reports that the permission authorization is successful, use the message middleware to perform the permission authorization operation of the at least one sub-transaction until the permission authorization succeeds .
上文提及,权限系统是一个几乎所有后台管理系统都会涉及的一个重要组成部分,主要目的是对整个后台系统数据进行权限控制。当通过权限系统对用户进行授权时,如果用户申请的权限比较多,就会调用很多其他服务,就会涉及到分布式事务,在这种情况下就必须保证授权数据一致性,避免出现有些权限授权成功,有些权限授权失败的情况。一般采用的分布式事务的处理方式一种为将分布式事务拆分成本地事务的方案,通过本地消息表保证数据一致性,该方案基本避免了分布式事务;另一种为通过调用接口对涉及到分布式事务的业务服务(即上述的资源对应的业务)回滚的方案,在对业务服务授权失败后,对分布式事务对应的业务权限数据进行回滚。但是,本地消息表是关系型数据库,而关系型数据库在吞吐量和性能方面存在瓶颈,频繁的读写消息会给关系型数据库造成压力,所以在高并发场景下,该方案会存在性能限制。而且回滚的方案一般按照串行的方式调用一系列业务服务的授权服务,在串行的服务较多时,回滚成本很高,并且很多授权服务很难直接回滚,所以非常有局限性。As mentioned above, the authority system is an important part of almost all background management systems. The main purpose is to control the authority of the entire background system data. When authorizing users through the permission system, if the user applies for more permissions, many other services will be called, which will involve distributed transactions. In this case, the consistency of the authorization data must be guaranteed to avoid some permissions. The authorization is successful, and some authorization authorization fails. One of the commonly used processing methods of distributed transactions is to split distributed transactions into local transactions, and ensure data consistency through the local message table, which basically avoids distributed transactions; In the scheme of rolling back the business service (that is, the business corresponding to the above-mentioned resource) involving the distributed transaction, after the authorization of the business service fails, the business authority data corresponding to the distributed transaction is rolled back. However, the local message table is a relational database, and the relational database has bottlenecks in throughput and performance. Frequent reading and writing messages will put pressure on the relational database. Therefore, in high concurrency scenarios, this solution will have performance limitations. Moreover, the rollback scheme generally calls the authorization services of a series of business services in a serial manner. When there are many serial services, the rollback cost is high, and many authorization services are difficult to roll back directly, so they are very limited.
考虑到上述缺陷,在该实施方式中,提出一种权限控制装置,该装置通过将分布式事务进行拆分,对拆分的主事务和至少一个子事务进行不同的权限授权处理,实现了结合多个维度进行业务服务的权限控制,提高权限控制的适用范围。Considering the above-mentioned defects, in this embodiment, an authority control device is proposed. The device divides the distributed transaction and performs different authority authorization processing on the split main transaction and at least one sub-transaction, so as to realize the combination of Permission control of business services is carried out in multiple dimensions to improve the scope of application of permission control.
其中,分布式事务就是指事务的参与者、支持事务的服务器、资源服务器以及事务管理器(即权限控制装置)分别位于不同的分布式系统的不同节点之上。The distributed transaction means that the participants of the transaction, the server supporting the transaction, the resource server, and the transaction manager (ie, the authority control device) are located on different nodes of different distributed systems, respectively.
在本实施例的一个可选实现方式中,所述分布式事务包括待授权事务和发起待授权事务的申请事务,所述主事务为所述申请事务,所述至少一个子事务为所述待授权事务。In an optional implementation of this embodiment, the distributed transaction includes a transaction to be authorized and an application transaction that initiates a transaction to be authorized, the main transaction is the application transaction, and the at least one sub-transaction is the transaction to be authorized Authorize transactions.
其中,权限控制装置可以为用户可以操作的用于设置员工或用户权限的入口,在本实施方式中,权限控制装置可以与有可视化显示装置(例如显示器)的终端的权限控制客户端进行通信,这样,用户就可以通过对终端中的可视化显示装置进行操作,实现员工或用户的权限的设定。例如,用户通过在终端上的操作,选中角色、页面、以及打印等权限为员工1进行权限授权,那么在用户选完权限范围内的功能选项(即上述的角色、页面以及打印等功能)后,通过触发确认申请功能按键,将上述操作信息发送至权限控制装置,触发权限申请,开始进行上述功能选项的权限授权操作,而整个权限设定的操作称为分布式事务,功能选项的权限授权操作称为待授权事务,触发权限申请的操作称为发起待授权事务的申请事务。在本实施方式中,由于功能选项选中的功能可以是多个,因此,待授权事务可能是多个或一个,即在本实施方式中的在权限授权的过程中,可以触发至少一个待授权事务产生,在本实施方式中不限制同时进行权限授权时待授权事务的数量。Wherein, the authority control device may be a user-operable portal for setting employee or user authority. In this embodiment, the authority control device may communicate with the authority control client of the terminal having a visual display device (such as a display), In this way, the user can set the authority of the employee or the user by operating the visual display device in the terminal. For example, the user selects roles, pages, and print permissions to authorize employee 1 through operations on the terminal, then after the user selects the functional options within the scope of permissions (that is, the above-mentioned roles, pages, and print functions) , by triggering the confirmation application function button, the above operation information is sent to the authority control device, the authority application is triggered, and the authority authorization operation of the above function options is started, and the entire authority setting operation is called a distributed transaction, and the authority authorization of the function options The operation is called the transaction to be authorized, and the operation that triggers the permission application is called the application transaction that initiates the transaction to be authorized. In this embodiment, since there can be multiple functions selected by the function option, there may be multiple or one transactions to be authorized, that is, in the process of authorization in this embodiment, at least one transaction to be authorized can be triggered Generated, in this embodiment, the number of transactions to be authorized when authorization authorization is performed at the same time is not limited.
其中,权限控制有基于资源的权限控制,也有基于角色的权限控制。在基于资源的权限控制装置中,资源指一切可以授权的东西,一个页面,一条数据,一个接口都是资源。在基于角色的权限控制装置中,一般采用基于角色的权限访问控制(RBAC,Role-BasedAccess Control),在RBAC中,权限与角色相关联,用户通过成为适当角色的成员而得到这些角色的权限,从而极大地简化了权限的管理。在一个组织中,角色是为了完成各种工作而创造,用户则依据它的责任和资格来被指派相应的角色,用户可以很容易地从一个角色被指派到另一个角色。角色可依新的需求和系统的合并而赋予新的权限,而权限也可根据需要而从某角色中回收。Among them, permission control includes resource-based permission control and role-based permission control. In the resource-based permission control device, resources refer to everything that can be authorized, and a page, a piece of data, and an interface are all resources. In role-based permission control devices, role-based permission access control (RBAC, Role-Based Access Control) is generally used. In RBAC, permissions are associated with roles, and users get the permissions of these roles by becoming members of appropriate roles. This greatly simplifies the management of permissions. In an organization, roles are created to accomplish various tasks, and users are assigned corresponding roles according to their responsibilities and qualifications. Users can easily be assigned from one role to another. Roles can be given new permissions according to new requirements and system integration, and permissions can also be withdrawn from a role as needed.
在本实施例的一个可选实现方式中,在接收到了通过用户操作触发的分布式事务之后,将该分布式事务拆分为主事务和至少一个子事务,先对主事务进行权限授权操作的,并且是采用本地事务方式对主事务进行权限授权操作的,权限授权操作可以是成功的,也可以是失败的,而当权限授权操作反馈权限授权成功时,表征主事务授权操作成功,那么就可以开始进行具体的至少一个子事务的权限授权操作了,这里,可以采用消息中间件执行至少一个子事务的权限授权操作,直至权限授权成功。In an optional implementation manner of this embodiment, after receiving a distributed transaction triggered by a user operation, the distributed transaction is split into a main transaction and at least one sub-transaction, and a permission authorization operation is first performed on the main transaction. , and the local transaction method is used to perform the authorization authorization operation on the main transaction. The authorization authorization operation can be successful or failed. When the authorization authorization operation reports that the authorization authorization is successful, it indicates that the authorization operation of the main transaction is successful. The permission authorization operation of the specific at least one sub-transaction can be started. Here, the message middleware can be used to perform the permission authorization operation of the at least one sub-transaction until the permission authorization is successful.
其中,采用本地事务方式对主事务进行权限授权操作具体实现可以为通过本地数据库进行业务编排和异步恢复实现。The specific implementation of the authorization authorization operation for the main transaction in the local transaction mode may be the implementation of business orchestration and asynchronous recovery through the local database.
在本实施例的一个可选实现方式中,如图7所示,所述拆分模块602包括:In an optional implementation manner of this embodiment, as shown in FIG. 7 , the splitting module 602 includes:
获取子模块701,被配置为获取所述分布式事务的内容数据;Obtaining sub-module 701, configured to obtain the content data of the distributed transaction;
拆分子模块702,被配置为根据所述内容数据,将所述分布式事务拆分为所述主事务和所述至少一个子事务。The splitting sub-module 702 is configured to split the distributed transaction into the main transaction and the at least one sub-transaction according to the content data.
在本实施方式中,可以通过对分布式事务基于业务内容的不同进行拆分,先对主事务进行权限授权操作,再对至少一个子事务进行权限授权操作,并且采用不同的权限授权操作实现一个不同的事务权限授权操作,提高了处理事务的灵活性和多样性。In this embodiment, the distributed transaction can be split based on the difference of the business content, firstly performing the authority authorization operation on the main transaction, and then performing the authority authorization operation on at least one sub-transaction, and using different authority authorization operations to realize a Different transaction permissions authorize operations to improve the flexibility and diversity of transaction processing.
其中,在接收分布式事务后,可以通过分布式事务的触发操作获取分布式事务的内容数据;其中,内容数据为业务对应的内容;这样,该就可以根据内容数据,将分布式事务拆分为至少一个子事务,即待授权事务,以及发起待授权事务的申请事务(即主事务)。Among them, after receiving the distributed transaction, the content data of the distributed transaction can be obtained through the trigger operation of the distributed transaction; wherein, the content data is the content corresponding to the business; in this way, the distributed transaction can be split according to the content data. It is at least one sub-transaction, that is, the transaction to be authorized, and the application transaction that initiates the transaction to be authorized (that is, the main transaction).
在本实施方式中,可以为申请者提供不同业务(即功能选项)的权限,而不同的业务可能需要调用不同的业务服务器实现,因此才会接收到分布式事务。In this embodiment, the applicant can be provided with permissions for different services (ie, functional options), and different services may need to be implemented by invoking different service servers, so that distributed transactions are received.
其中,内容数据可以理解为业务功能的类型,例如,邮件业务、打印业务,数据处理业务,角色分配等。The content data can be understood as the type of business function, for example, mail business, printing business, data processing business, role assignment, and so on.
在本实施例的一个可选实现方式中,如图8所示,所述授权模块603包括:In an optional implementation manner of this embodiment, as shown in FIG. 8 , the authorization module 603 includes:
生成子模块801,被配置为当所述权限授权操作反馈权限授权成功时,生成推送消息,所述推送消息中携带有所述至少一个子事务分别对应的权限授权标记;The generating submodule 801 is configured to generate a push message when the authority authorization operation reports that authority authorization is successful, and the push message carries the authority authorization mark corresponding to the at least one sub-transaction respectively;
授权子模块802,被配置为通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务执行所述推送消息,进行所述至少一个子事务的权限授权操作,直至权限授权成功。The authorization sub-module 802 is configured to push the push message through the message middleware, so as to trigger the at least one sub-transaction corresponding to the permission authorization mark to execute the push message, and perform the at least one sub-transaction. Permission authorization operation until the permission authorization is successful.
在本实施方式中,是采用消息中间件进行至少一个子事务的权限授权操作的,而消息中间件利用的持久化消息功能和重试功能成功实现至少一个子事务的权限授权,提高了权限授权的成功率。In this embodiment, the message middleware is used to perform the authorization authorization operation of at least one sub-transaction, and the persistent message function and the retry function utilized by the message middleware successfully realize the authorization of at least one sub-transaction, which improves the authorization of authorization. success rate.
其中,消息中间件适用于需要可靠的数据传送的分布式环境中。采用消息中间件的权限控制装置中,不同的事务之间通过传递消息来激活对方的事件,完成相应的操作。当权限授权操作反馈权限授权成功时,生成推送消息,于是将推送消息发送给消息服务器,消息服务器将消息存放在若干队列中,再将推送消息转发给至少一个子事务对应的业务服务器进行权限授权操作。消息中间件能在不同平台之间通信,它常被用来屏蔽掉各种平台及协议之间的特性,实现应用程序之间的协同,其优点在于能够在客户和服务器之间提供同步和异步的连接,并且在任何时刻都可以将消息进行传送或者存储转发。Among them, message middleware is suitable for distributed environments that require reliable data transmission. In the authority control device using message middleware, different transactions activate each other's events by transmitting messages to complete corresponding operations. When the permission authorization operation reports that the permission authorization is successful, a push message is generated, and then the push message is sent to the message server. The message server stores the message in several queues, and then forwards the push message to the business server corresponding to at least one sub-transaction for permission authorization. operate. Message middleware can communicate between different platforms. It is often used to shield the characteristics between various platforms and protocols, and realize collaboration between applications. Its advantage is that it can provide synchronization and asynchronous between clients and servers. connection, and can transmit or store and forward messages at any time.
在本实施方式中,当权限授权操作反馈权限授权成功时,触发生成推送消息,其中,该推送消息中携带有至少一个子事务分别对应的权限授权标记,表征开始进行至少一个子事务的权限授权操作;这时,通过消息中间件推送推送消息,以触发与权限授权标记对应的至少一个子事务分别执行该推送消息,进行至少一个子事务的权限授权操作,利用消息中间件的持久化消息功能和重试功能直至权限授权成功。In this embodiment, when the authority authorization operation reports that authority authorization is successful, the generation of a push message is triggered, wherein the push message carries authority authorization marks corresponding to at least one sub-transaction, indicating that authority authorization for at least one sub-transaction starts. At this time, push the push message through the message middleware to trigger at least one sub-transaction corresponding to the permission authorization tag to execute the push message respectively, perform the permission authorization operation of at least one sub-transaction, and use the persistent message function of the message middleware and retry the function until the authorization is successful.
其中,通过消息中间件推送推送消息,以触发与授权标记对应的至少一个子事务各自响应该推送消息,采用本地事务方式对每个子事务进行授权操作,通过调用每个子事务对应的业务服务,实现与每个子事务对应的业务服务接口的权限赋值,授权成功。The push message is pushed through the message middleware to trigger at least one sub-transaction corresponding to the authorization tag to respectively respond to the push message, and the authorization operation is performed on each sub-transaction in a local transaction mode, and the business service corresponding to each sub-transaction is invoked to achieve The permission assignment of the business service interface corresponding to each sub-transaction indicates that the authorization is successful.
其中,授权标记为至少一个子事务中的每个子事务与推送消息对应的标记,可以理解为该推送消息的订阅标识,消息中间件可以通过订阅关系向业务服务器接口进行消息推送,即消息中间件根据授权标记推送推送消息给至少一个子事务对应的业务服务器接口,以实现根据推送消息,进行至少一个子事务权限授权的操作。Among them, the authorization mark is the mark corresponding to each sub-transaction in the at least one sub-transaction and the push message, which can be understood as the subscription identification of the push message. The message middleware can push the message to the service server interface through the subscription relationship, that is, the message middleware The push message is pushed to the service server interface corresponding to the at least one sub-transaction according to the authorization mark, so as to implement the operation of authorizing the authority of the at least one sub-transaction according to the push message.
其中,针对订阅的理解为:消息生产者(发布)将消息发布到topic中,同时有多个消息消费者(订阅)消费该消息,发布到topic的消息会被所有订阅者消费。也即是说,特定的一条消息可以被多个消费者(这里指至少一个子事务)所接收,只要消费者订阅了某个主题。消息生产者(发布者)将消息发送到某个称为主题(topic)的虚拟通道中,topic可以被多个消费者订阅。Among them, the understanding of subscription is: a message producer (publishing) publishes a message to a topic, and multiple message consumers (subscribing) consume the message at the same time, and the message published to the topic will be consumed by all subscribers. That is to say, a specific message can be received by multiple consumers (here, at least one sub-transaction), as long as the consumers subscribe to a topic. Message producers (publishers) send messages to a virtual channel called a topic, which can be subscribed to by multiple consumers.
在本实施例的一个可选实现方式中,如图9所示,所述权限控制装置还包括:In an optional implementation manner of this embodiment, as shown in FIG. 9 , the authority control apparatus further includes:
记录监听模块901,被配置为记录所述至少一个子事务响应所述推送消息的状态,得到包含至少一个子事务对应的消息消费状态的消息消费状态表;及实时监听所述消息消费状态表,处理被重复消费的消息。The recording and monitoring module 901 is configured to record the state of the at least one sub-transaction responding to the push message, and obtain a message consumption state table including the message consumption state corresponding to the at least one sub-transaction; and monitor the message consumption state table in real time, Handle re-consumed messages.
在本实施方式中,在通过推送消息进行至少一个子事务的过程中,还可以通过一个消息消费状态表来记录消息的消费情况,避免消息被重复消费,重复授权的问题,提高了授权过程中的效率,减少了数据处理的冗余。In this embodiment, in the process of performing at least one sub-transaction by pushing a message, a message consumption status table can also be used to record the consumption of the message, so as to avoid the problem of repeated consumption and repeated authorization of the message, and improve the authorization process. efficiency, reducing the redundancy of data processing.
其中,消息消费状态表可以是在本地建立的,用于记录本地消息的消费状态的数据结构。在本实施方式中,执行推送消息,实现对至少一个子事务进行权限授权的时候,权限授权成功与否都是需要进行记录,即记录消息消费,这样,当相同的推送消息再次产生,想要进行相同用户的同一个子事务的再次授权时,就可以通过消息消费状态表中的相同消息的消费情况,从而拒绝重复进行相同用户的相同子事务的授权。The message consumption state table may be a data structure established locally and used to record the consumption state of local messages. In this embodiment, when a push message is executed to implement authority authorization for at least one sub-transaction, it is necessary to record whether the authority authorization is successful or not, that is, record message consumption. When re-authorizing the same sub-transaction of the same user, it is possible to refuse to repeat the authorization of the same sub-transaction of the same user through the consumption of the same message in the message consumption status table.
在本实施方式中,消息消费状态表在记录推送消息的时候,还可以同时记录是针对哪个用户的哪个子事务的权限授权操作的。In this embodiment, when recording the push message, the message consumption status table may also record the authority authorization operation for which user and which sub-transaction.
在本实施方式中,进行至少一个子事务的权限授权的过程中,实时记录至少一个子事务响应推送消息的状态,并且还实时监听消息消费状态表,以获知消息消费状态表中的变化,找出被重复消费的消息,并中止执行被重复消费的消息,丢弃被重复消费的消息。In this embodiment, in the process of authorization of at least one sub-transaction, the status of at least one sub-transaction responding to the push message is recorded in real time, and the message consumption status table is also monitored in real time to learn the changes in the message consumption status table, find out The message that is repeatedly consumed is output, the execution of the message that is repeatedly consumed is aborted, and the message that is repeatedly consumed is discarded.
其中,消息消费状态表可以使用nosql数据库实现,以提高数据读取速度。Among them, the message consumption status table can be implemented using the nosql database to improve the data reading speed.
在本实施例的一个可选实现方式中,如图10所示,所述授权子模块802包括:In an optional implementation manner of this embodiment, as shown in FIG. 10 , the authorization sub-module 802 includes:
推送子模块1001,被配置为通过所述消息中间件推送所述推送消息,以触发与所述权限授权标记对应的所述至少一个子事务各自响应所述推送消息;Pushing sub-module 1001, configured to push the push message through the message middleware, so as to trigger the at least one sub-transaction corresponding to the permission authorization mark to respond to the push message respectively;
授权子模块1002,被配置为采用本地事务方式对所述至少一个子事务进行权限授权操作;Authorization sub-module 1002, configured to perform a permission authorization operation on the at least one sub-transaction in a local transaction mode;
丢弃子模块1003,被配置为当所述权限授权操作反馈权限授权成功时,丢弃所述推送消息;Discarding sub-module 1003, configured to discard the push message when the permission authorization operation reports that permission authorization is successful;
获取子模块1004,被配置为当所述权限授权操作反馈权限授权失败时,利用所述消息中间件重新获取所述推送消息;Obtaining sub-module 1004, configured to use the message middleware to re-acquire the push message when the permission authorization operation feedbacks that permission authorization fails;
对比子模块1005,被配置为将所述推送消息与所述消息消费状态表进行对比;A comparison sub-module 1005 is configured to compare the push message with the message consumption status table;
所述丢弃子模块1003,还被配置为当所述消息消费状态表中存在所述推送消息的消费状态信息,且所述消费状态信息为成功时,丢弃所述推送消息;The discarding sub-module 1003 is further configured to discard the push message when there is consumption status information of the push message in the message consumption status table and the consumption status information is successful;
所述授权子模块1002,还被配置为当所述消息消费状态表中存在所述推送消息的消费状态信息,且所述消费状态信息为失败时,重新执行所述推送消息,进行所述至少一个子事务中未权限授权成功的子事务的权限授权操作,直至权限授权成功。The authorization sub-module 1002 is further configured to re-execute the push message when the consumption status information of the push message exists in the message consumption status table, and the consumption status information is failed, and perform the at least The authorization authorization operation of the sub-transaction that is not authorized successfully in a sub-transaction until the authorization is successful.
其中,在获取到推送消息后,开始根据该推送消息采用本地事务方式对至少一个子事务中的每个子事务进行权限授权操作,并将推送消息与每个子事务的对应关系写在消息消费状态表中,待执行完一个子事务的本地事务后,如果执行成功,就丢弃该子事务对应的推送消息,并更新该子事务的推送消息在消息消费状态表中的消费状态信息为成功。而如果一个子事务的权限授权失败,那么,则利用消息中间件消息持久化功能和重试功能,重新获取该一个子事务对应的推送消息,并将其与本地消息消费状态表中的该一个子事务的消费状态信息做对比,如果该推送消息在消息消费状态表中为成功,则停止执行本地事务,该一个子事务不执行,并丢弃该条推送消息,否则,执行该一个子事务对应的本地事务直至执行成功,做到授权服务的等幂性,最终达到业务数据的一致性。Wherein, after the push message is obtained, the authority authorization operation is performed on each sub-transaction in the at least one sub-transaction in a local transaction mode according to the push message, and the corresponding relationship between the push message and each sub-transaction is written in the message consumption status table , after the local transaction of a sub-transaction is executed, if the execution is successful, the push message corresponding to the sub-transaction is discarded, and the consumption status information of the push message of the sub-transaction in the message consumption status table is updated to be successful. If the authorization authorization of a sub-transaction fails, then the message persistence function and retry function of the message middleware are used to re-acquire the push message corresponding to the sub-transaction, and compare it with the one in the local message consumption status table. Compare the consumption status information of the sub-transactions. If the push message is successful in the message consumption status table, stop executing the local transaction, the sub-transaction is not executed, and the push message is discarded. Otherwise, the sub-transaction corresponding to the execution is executed. The local transaction is executed successfully, so as to achieve the idempotency of the authorization service, and finally achieve the consistency of the business data.
其中,等幂性指对于同一个操作的用户多次提交,接口只进行一次操作,即针对一个用户的一个子事务至进行一次权限授权操作。一致性是指在分布式系统中,指多个节点的数据一致。这里指进行权限授权操作时,要么全部成功,要么全部失败。Among them, idempotency means that for users who submit the same operation multiple times, the interface only performs one operation, that is, for a sub-transaction of a user, until a permission authorization operation is performed. Consistency means that in a distributed system, the data of multiple nodes is consistent. This means that when the authorization authorization operation is performed, either all of them succeed or all of them fail.
在本实施例的一个可选实现方式中,如图11所示,所述权限控制装置还包括:In an optional implementation manner of this embodiment, as shown in FIG. 11 , the authority control apparatus further includes:
回滚模块1101,被配置为所述对所述主事务进行权限授权操作之后,当所述权限授权操作反馈权限授权失败时,对所述主事务进行回滚操作。The rollback module 1101 is configured to perform a rollback operation on the main transaction after the authorization authorization operation is performed on the main transaction, when the authorization authorization operation reports that authorization authorization fails.
在本实施方式中,在进行了主事务的权限授权操作之后,可能存在权限授权操作反馈权限授权成功和权限授权操作反馈权限授权失败两种结果,当权限授权操作反馈权限授权失败时,对主事务进行回滚操作,就不继续进行后续的至少一个子事务的权限授权操作了,只在主事务权限授权操作之后才可能进行回滚,并不是任意过程都采用回滚方式实现,从而提高了权限控制的效率。In this embodiment, after the authority authorization operation of the main transaction is performed, there may be two results of the authority authorization operation feedback authority authorization success and authority authorization operation feedback authority authorization failure. When the transaction is rolled back, it will not continue to perform the authorization authorization operation of at least one subsequent sub-transaction. It is only possible to perform the rollback after the authorization operation of the main transaction authorization. Efficiency of access control.
在本实施例的一个可选实现方式中,所述记录监听模块,被配置为实时监听所述至少一个子事务的权限授权操作,记录异常权限授权信息,供重试权限授权操作时使用。In an optional implementation manner of this embodiment, the recording and monitoring module is configured to monitor the authority authorization operation of the at least one sub-transaction in real time, and record abnormal authority authorization information for use when retrying the authority authorization operation.
在本实施方式中,可以实时的对至少一个子事务的权限授权操作进行监控,记录权限授权操作过程中发生的数据和操作,就会异常权限授权信息,供重试权限授权操作时使用,这样可以监控到消息的处理能力和状况,及时的进行调整,提高了服务的可用性和可伸缩性。In this embodiment, the authority authorization operation of at least one sub-transaction can be monitored in real time, the data and operations that occur during the authority authorization operation are recorded, and the authority authorization information is abnormal, which is used when retrying the authority authorization operation. The processing capability and status of messages can be monitored, and adjustments can be made in a timely manner, which improves the availability and scalability of services.
其中,异常权限授权信息可以包括异常的消息消费状态,异常的数据和异常的消息处理能力等。The abnormal authority authorization information may include abnormal message consumption status, abnormal data, abnormal message processing capability, and the like.
本公开还公开了一种电子设备,图12示出根据本公开一实施方式的电子设备的结构框图,如图12所示,所述电子设备1200包括存储器1201和处理器1202;其中,The present disclosure also discloses an electronic device. FIG. 12 shows a structural block diagram of an electronic device according to an embodiment of the present disclosure. As shown in FIG. 12 , the electronic device 1200 includes a memory 1201 and a processor 1202; wherein,
所述存储器1201用于存储一条或多条计算机指令,其中,所述一条或多条计算机指令被所述处理器1202执行以实现上述任一方法步骤。The memory 1201 is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor 1202 to implement any of the above method steps.
图13适于用来实现根据本公开实施方式的权限控制方法的计算机系统的结构示意图。FIG. 13 is a schematic structural diagram of a computer system suitable for implementing the authority control method according to an embodiment of the present disclosure.
如图13所示,计算机系统1300包括中央处理单元(CPU)1301,其可以根据存储在只读存储器(ROM)1302中的程序或者从存储部分1308加载到随机访问存储器(RAM)1303中的程序而执行上述实施方式中的各种处理。在RAM1303中,还存储有系统1300操作所需的各种程序和数据。CPU1301、ROM1302以及RAM1303通过总线1304彼此相连。输入/输出(I/O)接口1305也连接至总线1304。As shown in FIG. 13, a computer system 1300 includes a central processing unit (CPU) 1301, which can be loaded into a random access memory (RAM) 1303 according to a program stored in a read only memory (ROM) 1302 or a program from a storage section 1308 Instead, various processes in the above-described embodiments are executed. In the RAM 1303, various programs and data necessary for the operation of the system 1300 are also stored. The CPU 1301 , the ROM 1302 , and the RAM 1303 are connected to each other through a bus 1304 . An input/output (I/O) interface 1305 is also connected to bus 1304 .
以下部件连接至I/O接口1305:包括键盘、鼠标等的输入部分1306;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分1307;包括硬盘等的存储部分1308;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分1309。通信部分1309经由诸如因特网的网络执行通信处理。驱动器1310也根据需要连接至I/O接口1305。可拆卸介质1311,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器1310上,以便于从其上读出的计算机程序根据需要被安装入存储部分1308。The following components are connected to the I/O interface 1305: an input section 1306 including a keyboard, a mouse, etc.; an output section 1307 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1308 including a hard disk, etc. ; and a communication section 1309 including a network interface card such as a LAN card, a modem, and the like. The communication section 1309 performs communication processing via a network such as the Internet. Drivers 1310 are also connected to I/O interface 1305 as needed. A removable medium 1311, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 1310 as needed so that a computer program read therefrom is installed into the storage section 1308 as needed.
特别地,根据本公开的实施方式,上文描述的方法可以被实现为计算机软件程序。例如,本公开的实施方式包括一种计算机程序产品,其包括有形地包含在及其可读介质上的计算机程序,所述计算机程序包含用于执行所述权限控制方法的程序代码。在这样的实施方式中,该计算机程序可以通过通信部分1309从网络上被下载和安装,和/或从可拆卸介质1311被安装。In particular, according to embodiments of the present disclosure, the methods described above may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product including a computer program tangibly embodied on a readable medium thereof, the computer program including program code for executing the rights control method. In such an embodiment, the computer program may be downloaded and installed from the network via the communication portion 1309, and/or installed from the removable medium 1311.
附图中的流程图和框图,图示了按照本公开各种实施方式的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,路程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,所述模块、程序段或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the diagram or block diagram may represent a module, segment, or portion of code that contains one or more functions for implementing the specified logical function. executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented in dedicated hardware-based systems that perform the specified functions or operations , or can be implemented in a combination of dedicated hardware and computer instructions.
描述于本公开实施方式中所涉及到的单元或模块可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的单元或模块也可以设置在处理器中,这些单元或模块的名称在某种情况下并不构成对该单元或模块本身的限定。The units or modules involved in the embodiments of the present disclosure can be implemented in software or hardware. The described units or modules may also be provided in the processor, and the names of these units or modules do not constitute a limitation on the units or modules themselves in certain circumstances.
作为另一方面,本公开还提供了一种计算机可读存储介质,该计算机可读存储介质可以是上述实施方式中所述装置中所包含的计算机可读存储介质;也可以是单独存在,未装配入设备中的计算机可读存储介质。计算机可读存储介质存储有一个或者一个以上程序,所述程序被一个或者一个以上的处理器用来执行描述于本公开的方法。As another aspect, the present disclosure also provides a computer-readable storage medium, and the computer-readable storage medium may be a computer-readable storage medium included in the apparatus described in the foregoing embodiments; A computer-readable storage medium that fits into a device. The computer-readable storage medium stores one or more programs used by one or more processors to perform the methods described in the present disclosure.
以上描述仅为本公开的较佳实施例以及对所运用技术原理的说明。本领域技术人员应当理解,本公开中所涉及的发明范围,并不限于上述技术特征的特定组合而成的技术方案,同时也应涵盖在不脱离所述发明构思的情况下,由上述技术特征或其等同特征进行任意组合而形成的其它技术方案。例如上述特征与本公开中公开的(但不限于)具有类似功能的技术特征进行互相替换而形成的技术方案。The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, and should also cover the above-mentioned technical features without departing from the inventive concept. Other technical solutions formed by any combination of its equivalent features. For example, a technical solution is formed by replacing the above features with the technical features disclosed in the present disclosure (but not limited to) with similar functions.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811134085.7A CN109376526A (en) | 2018-09-27 | 2018-09-27 | Authority control method and device, electronic equipment and computer readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811134085.7A CN109376526A (en) | 2018-09-27 | 2018-09-27 | Authority control method and device, electronic equipment and computer readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109376526A true CN109376526A (en) | 2019-02-22 |
Family
ID=65402108
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811134085.7A Pending CN109376526A (en) | 2018-09-27 | 2018-09-27 | Authority control method and device, electronic equipment and computer readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109376526A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112202819A (en) * | 2020-12-02 | 2021-01-08 | 成都掌控者网络科技有限公司 | Distributed control authority method and device, computer equipment and storage medium |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20010021928A1 (en) * | 2000-01-07 | 2001-09-13 | Ludwig Heiko H. | Method for inter-enterprise role-based authorization |
CN103312549A (en) * | 2013-06-26 | 2013-09-18 | 华为技术有限公司 | Transaction management method, device and system |
CN105824842A (en) * | 2015-01-07 | 2016-08-03 | 阿里巴巴集团控股有限公司 | Distributed transaction processing method and system |
CN106383737A (en) * | 2016-09-09 | 2017-02-08 | 浪潮软件股份有限公司 | Distributed transaction processing method |
CN106775959A (en) * | 2016-12-06 | 2017-05-31 | 上海亿账通互联网科技有限公司 | Distributed transaction processing method and system |
CN107426169A (en) * | 2017-05-24 | 2017-12-01 | 阿里巴巴集团控股有限公司 | A kind of method for processing business and device based on authority |
CN108519918A (en) * | 2018-03-14 | 2018-09-11 | 广东能龙教育股份有限公司 | Distributed transaction processing method based on transaction chain |
-
2018
- 2018-09-27 CN CN201811134085.7A patent/CN109376526A/en active Pending
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20010021928A1 (en) * | 2000-01-07 | 2001-09-13 | Ludwig Heiko H. | Method for inter-enterprise role-based authorization |
CN103312549A (en) * | 2013-06-26 | 2013-09-18 | 华为技术有限公司 | Transaction management method, device and system |
CN105824842A (en) * | 2015-01-07 | 2016-08-03 | 阿里巴巴集团控股有限公司 | Distributed transaction processing method and system |
CN106383737A (en) * | 2016-09-09 | 2017-02-08 | 浪潮软件股份有限公司 | Distributed transaction processing method |
CN106775959A (en) * | 2016-12-06 | 2017-05-31 | 上海亿账通互联网科技有限公司 | Distributed transaction processing method and system |
CN107426169A (en) * | 2017-05-24 | 2017-12-01 | 阿里巴巴集团控股有限公司 | A kind of method for processing business and device based on authority |
CN108519918A (en) * | 2018-03-14 | 2018-09-11 | 广东能龙教育股份有限公司 | Distributed transaction processing method based on transaction chain |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112202819A (en) * | 2020-12-02 | 2021-01-08 | 成都掌控者网络科技有限公司 | Distributed control authority method and device, computer equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110968586B (en) | Distributed transaction processing method and device | |
US7454751B2 (en) | Fault-tolerant system and methods with trusted message acknowledgement | |
US8250132B2 (en) | Managing messages related to workflows | |
JP4144897B2 (en) | Optimal server in common work queue environment | |
CN106874334B (en) | Data processing method and device and information processing system | |
CN107437222B (en) | Processing method and system of online business data based on front end of bank counter | |
CN110727507B (en) | Message processing method and device, computer equipment and storage medium | |
CN112825525B (en) | Method and apparatus for processing transactions | |
US20080155140A1 (en) | System and program for buffering work requests | |
US7870557B2 (en) | Apparatus, system, and method for autonomously maintaining a single system image in a parallel systems complex | |
CN111240940B (en) | Real-time service monitoring method and device, electronic equipment and storage medium | |
CN112822091A (en) | Message processing method and device | |
US10942818B1 (en) | Common backup and recovery solution for diverse cloud-based services in a productivity suite | |
US8418191B2 (en) | Application flow control apparatus | |
US20060212518A1 (en) | Copying chat data from a chat session already active | |
CN111679892A (en) | Distributed transaction processing method, device, equipment and medium | |
US7640263B2 (en) | Queued system event notification and maintenance | |
CN115525449B (en) | Micro-service data transmission system, method and storage medium | |
CN116382943A (en) | Sequential message processing method, bus system, computer device, and storage medium | |
CN113645260A (en) | Service retry method, device, storage medium and electronic equipment | |
CN109376526A (en) | Authority control method and device, electronic equipment and computer readable storage medium | |
US20050172288A1 (en) | Method, system, and program for system recovery | |
US8171495B2 (en) | Queue dispatch using deferred acknowledgement | |
US20160306983A1 (en) | Managing Keys Used for Encrypting Data | |
US10728323B2 (en) | Method and apparatus for operating infrastructure layer in cloud computing architecture |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20190222 |
|
RJ01 | Rejection of invention patent application after publication |