Access permission control module and method for database and electronic equipment

By using a modular access control architecture to intercept and process database access requests, flexible control of database access permissions is achieved, solving the problem of high coupling in existing technologies, reducing maintenance costs and improving readability and maintainability.

CN119004503APending Publication Date: 2024-11-22广域铭岛数字科技有限公司 +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411051196.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

In existing technologies, database access control methods suffer from high coupling, resulting in high maintenance costs and difficulty in adapting to rapidly changing business needs.

Method used

It adopts a modular architecture consisting of a permission configuration layer, a statement interception layer, a permission control layer, and a statement execution layer. By intercepting the execution of the original access statement through the driver layer, it performs matching and condition weaving based on the permission configuration information to control database access permissions.

Benefits of technology

It reduces the maintenance cost of access control, improves the readability and maintainability of access control, and avoids dependence on business code and persistence layer framework.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119004503A_ABST
    Figure CN119004503A_ABST
Patent Text Reader

Abstract

The invention relates to the field of database access, and discloses an access authority control module and method for a database and electronic equipment. According to the application, an original access statement is executed by intercepting a driving layer, matching is performed from the intercepted original access statement according to an access range in permission configuration information to obtain a target statement, an access condition in the permission configuration information is woven into the target statement, and then the target statement is executed through the driving layer to access a target database. According to the method, the database access request is directly intercepted and processed in the driving layer, and the intercepted original access statement is modified through the access range and the access condition of centralized management, so that access authority control aiming at the database is realized, authority control depending on a service code or a persistent layer framework is avoided, and the access efficiency is improved. The authority control logic is extracted from the service logic, so that the readability and maintainability of access authority control are improved, the user maintenance is facilitated, and the maintenance cost of authority control is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database access, and in particular to an access permission control module, method and electronic device for a database. Background Art

[0002] With the rapid development of information technology, the complexity of applications and the growth of data volume have put forward more stringent and diversified requirements for database access control. In today's enterprise environment, data is not only the core asset of enterprise operations, but also the key to enterprise competitiveness. Therefore, ensuring the security, privacy and compliance of data has become an important link that cannot be ignored in the system development process. In order to achieve the above goals, the industry has begun to explore more efficient, flexible and maintainable permission control mechanisms. These new mechanisms are designed to decouple permission control logic from business code and achieve fine-grained control of database access through a unified permission management framework or middleware. At the same time, these mechanisms also support permission determination based on multiple attributes, such as user identity, department affiliation, role definition, and superior-subordinate relationships, to meet complex and changing business needs.

[0003] However, it is not easy to implement such a permission control mechanism. Traditional permission control methods are powerless in the face of complex and ever-changing business needs. These methods often rely on hard-coded SQL query statements or permission checks deeply embedded in business logic, resulting in rigid system architecture and difficulty in adapting to rapidly changing needs. Specifically, by writing the acquisition of user permission information into business methods for permission management, this not only increases the complexity of the code, but also makes the permission control logic tightly coupled with the business logic, making it difficult to maintain and expand. In addition, if the SQL statement is managed with the help of the persistence layer framework, it also faces the problem of high coupling with the database access system. When the database access layer or persistence layer framework changes, such as version upgrades or technology stack migrations, the original permission control logic may need to be re-implemented or modified in large quantities, which not only increases development costs, but also may introduce new security vulnerabilities.

[0004] In summary, the permission management method for accessing the database has a high degree of coupling, which leads to high maintenance costs for permission control. Summary of the invention

[0005] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.

[0006] In view of the above-mentioned shortcomings of the prior art, the present application discloses an access permission control module, method and electronic device for a database to reduce the maintenance cost of permission control.

[0007] The present application discloses an access permission control module for a database, comprising: a permission configuration layer, used to obtain permission configuration information, wherein the permission configuration information includes an access scope and / or an access condition; a statement interception layer, used to intercept a driver layer to execute an original access statement, wherein the original access statement is used to access a target database; a permission control layer, used to match the intercepted original access statement according to the access scope to obtain a target statement, and if the access condition does not exist in the target statement, weave the access condition into the target statement; and a statement execution layer, used to execute the target statement through the driver layer to access the target database.

[0008] In one embodiment of the present application, the permission configuration layer obtains permission configuration information in the following manner: obtaining a permission configuration structure, wherein the permission configuration structure includes relevant information fields and rule fields, and the rule fields include row rule fields and / or column rule fields; generating permission configuration information corresponding to the target database according to the permission configuration structure, wherein the relevant information fields are used to carry a database identifier and / or a user identifier, the row rule field is used to carry an access scope and / or access condition corresponding to any row in the target database, and the column rule field is used to carry an access scope and / or access condition corresponding to any column in the target database.

[0009] In one embodiment of the present application, the permission configuration layer generates permission configuration information corresponding to the target database according to the permission configuration structure in the following manner, including: obtaining project-related users corresponding to the current project, and obtaining multiple project levels corresponding to the current project, and permission templates corresponding to each of the project levels, wherein the target database stores project data of the current project; obtaining historical work tables corresponding to each of the project-related users, wherein the historical work tables include multiple work tasks, and at least a part of the work tasks are project tasks corresponding to the current project; determining the project contribution rate corresponding to each of the project-related users according to the proportion between the project tasks and the work tasks, and clustering the project contribution rates according to the number of project levels to obtain contribution rate clusters corresponding to each of the project levels; determining the user level corresponding to each of the project-related users from the project level according to the correspondence between the contribution rate clusters and the project-related users, and filling the permission templates corresponding to the user level into the permission configuration structure to obtain permission configuration information.

[0010] In one embodiment of the present application, the permission configuration layer determines the project contribution rate corresponding to each of the project-related users according to the proportion between the project task and the work task in the following manner: determine any historical worksheet as a target worksheet, determine the work task in the target worksheet as a first task, and determine the project task in the target worksheet as a second task; obtain the task weights corresponding to the work tasks respectively; calculate according to the task weight corresponding to the first task to obtain a first total score; count the proportion of important tasks in the second task according to preset important figures, and count the proportion of repeated tasks in the second task; calculate according to the task weight corresponding to the second task, the proportion of important tasks, and the proportion of repeated tasks to obtain a second total score, wherein the proportion of important tasks is positively correlated with the second total score, and the proportion of repeated tasks is positively correlated with the second total score; determine the ratio of the second total score to the first total score as the project contribution rate corresponding to the target worksheet.

[0011] In one embodiment of the present application, the permission control layer matches the intercepted original access statement according to the access scope to obtain the target statement in the following manner: parse the intercepted original access statement to obtain the original grammatical structure; determine the unit to be accessed in the target database according to the original grammatical structure, wherein the unit to be accessed includes at least one of a table, a row and a column; determine whether the current user corresponding to the original access statement has database access rights to the target database according to the access scope; if the current user has database access rights to the target database, determine the accessible unit in the target database according to the access scope; update the original grammatical structure according to the matching result between the accessible unit and the unit to be accessed to obtain the target grammatical structure, so as to construct the target statement according to the target grammatical structure.

[0012] In one embodiment of the present application, the permission control layer weaves the access condition into the target statement if the access condition does not exist in the target statement in the following manner: if the access condition exists in the permission configuration information, it is determined whether the access condition exists in the target grammatical structure; if the access condition does not exist in the target grammatical structure, the access condition is weaved into the target grammatical structure to construct the target statement according to the target grammatical structure.

[0013] In one embodiment of the present application, the statement interception layer intercepts the driver layer from executing the original access statement in the following manner: obtaining an interface agent corresponding to an interactive interface, wherein the driver layer is used to access the target database through the interactive interface, and the interface agent is used to implement the interactive interface; intercepting the driver layer from executing the original access statement through the interface agent.

[0014] In one embodiment of the present application, the interface agent includes at least one of the following: a driver agent, which depends on a connection agent, and the driver agent is used to implement the java.sql.Driver interface in the interaction interface; the connection agent, which depends on a grammar agent and a preprocessing agent, and the connection agent is used to implement the java.sql.Connection interface in the interaction interface; the grammar agent is used to implement the java.sql.Statement interface in the interaction interface; the preprocessing agent inherits the grammar agent, and the preprocessing agent is used to implement the java.sql.PreparedStatement interface in the interaction interface.

[0015] The present application discloses an access permission control method for a database, comprising: obtaining permission configuration information, wherein the permission configuration information includes an access scope and / or an access condition; intercepting a driver layer to execute an original access statement, wherein the original access statement is used to access a target database; matching the intercepted original access statements according to the access scope to obtain a target statement, and if the access condition does not exist in the target statement, weaving the access condition into the target statement; executing the target statement through the driver layer to access the target database.

[0016] The present application discloses an electronic device, comprising: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the above method.

[0017] Beneficial effects of this application:

[0018] By intercepting the original access statement executed by the driver layer, matching the intercepted original access statement according to the access scope in the permission configuration information, obtaining the target statement, weaving the access conditions in the permission configuration information into the target statement, and then executing the target statement through the driver layer to access the target database. In this way, the database access request is directly intercepted and processed at the driver layer, and the intercepted original access statement is modified through the centrally managed access scope and access conditions, realizing access permission control for the database, avoiding dependence on business code or persistence layer framework for permission control, extracting permission control logic from business logic, improving the readability and maintainability of access permission control, facilitating user maintenance, and thus reducing the maintenance cost of permission control. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 It is a structural diagram of a system framework with an access authority control module in an embodiment of the present invention;

[0020] Figure 2 It is a schematic diagram of the structure of an access permission control module for a database in an embodiment of the present invention;

[0021] Figure 3 is a schematic diagram of the structure of an interface agent in an embodiment of the present invention;

[0022] Figure 4 is a flow chart of a method for generating a target sentence in an embodiment of the present invention;

[0023] Figure 5 It is a flowchart of a method for controlling access rights of a database in an embodiment of the present invention;

[0024] Figure 6 is a flow chart of another method for controlling access rights of a database in an embodiment of the present invention;

[0025] Figure 7 It is a schematic diagram of the structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION

[0026] The following describes the embodiments of the present invention through specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and sub-samples in the embodiments can be combined with each other without conflict.

[0027] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0028] In the following description, numerous details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.

[0029] The terms "first", "second", etc. in the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.

[0030] Unless otherwise stated, the term "plurality" means two or more.

[0031] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.

[0032] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.

[0033] Combination Figure 1 As shown, an embodiment of the present disclosure provides a system framework with an access permission control module, including a code layer, an interface layer, a driver layer, a database and an access permission control module, wherein the system framework is established based on the JDBC (Java Database Connectivity) protocol.

[0034] The code layer (Application Code) includes persistence layer frameworks such as Mybatis and Hibernate. The code layer is used to provide codes for operating the database.

[0035] The interface layer (JDBC API) includes the protocol interface provided by the JDBC protocol. The application generates SQL statements through the protocol interface in the interface layer.

[0036] The driver layer (JDBC DB Driver) includes the underlying implementation drivers of the JDBC protocol for different databases. The driver layer is used to execute SQL (Structured Query Language) statements through the JDBC protocol to complete the access operation to the database.

[0037] Databases include MySQL database, PostGres database, Oracle database, etc.

[0038] The access permission control module is located between the interface layer and the driver layer, and is used to obtain permission configuration information, wherein the permission configuration information includes access scope and / or access condition; intercept the driver layer to execute the original access statement, wherein the original access statement is used to access the target database; match the intercepted original access statement according to the access scope to obtain the target statement, and if the access condition does not exist in the target statement, the access condition is woven into the target statement; execute the target statement through the driver layer to access the target database.

[0039] Combination Figure 2 As shown, the embodiment of the present disclosure provides an access permission control module for a database, including a permission configuration layer 201 , a statement interception layer 202 , a permission control layer 203 and a statement execution layer 204 .

[0040] The permission configuration layer 201 is used to obtain permission configuration information, wherein the permission configuration information includes access scope and / or access condition.

[0041] The statement interception layer 202 is used to intercept the execution of the original access statement by the driver layer, wherein the original access statement is used to access the target database.

[0042] The authority control layer 203 is used to match the intercepted original access statements according to the access scope to obtain the target statement, and if the access condition does not exist in the target statement, the access condition is woven into the target statement.

[0043] The statement execution layer 204 is used to execute the target statement through the driver layer to access the target database.

[0044] The access permission control module for a database provided by the embodiment of the present disclosure is adopted, and the original access statement is executed by intercepting the driver layer, and the target statement is obtained by matching the intercepted original access statement according to the access scope in the permission configuration information, and the access condition in the permission configuration information is woven into the target statement, and then the target statement is executed through the driver layer to access the target database. In this way, the database access request is directly intercepted and processed at the driver layer, and the intercepted original access statement is modified through the centrally managed access scope and access condition, so as to realize the access permission control for the database, avoid relying on the business code or the persistence layer framework for permission control, extract the permission control logic from the business logic, improve the readability and maintainability of the access permission control, facilitate user maintenance, and thus reduce the maintenance cost of the permission control.

[0045] Optionally, the permission configuration layer obtains the permission configuration information in the following manner: obtaining a permission configuration structure, wherein the permission configuration structure includes relevant information fields and rule fields, and the rule fields include row rule fields and / or column rule fields; generating permission configuration information corresponding to the target database according to the permission configuration structure, wherein the relevant information fields are used to carry the database identifier and / or user identifier, the row rule field is used to carry the access scope and / or access condition corresponding to any row in the target database, and the column rule field is used to carry the access scope and / or access condition corresponding to any column in the target database.

[0046] In some embodiments, the permission configuration layer obtains the permission configuration information of the current user for the target database from a local configuration file or a remote management system, wherein the permission configuration information is established based on a permission configuration structure, which is {"context":{related information fields},"rules":{"table name":"rows":"row rule fields","columns":"column name":["column rule fields"]}}.

[0047] Optionally, the permission configuration layer generates permission configuration information corresponding to the target database according to the permission configuration structure in the following manner, including: obtaining project-related users corresponding to the current project, and obtaining multiple project levels corresponding to the current project, and permission templates corresponding to each project level, wherein the target database stores project data of the current project; obtaining historical work sheets corresponding to each project-related user, wherein the historical work sheets include multiple work tasks, and at least a portion of the work tasks are project tasks corresponding to the current project; determining the project contribution rate corresponding to each project-related user according to the ratio between project tasks and work tasks, and clustering the project contribution rates according to the number of project levels to obtain contribution rate clusters corresponding to each project level; determining the user level corresponding to each project-related user from the project level according to the correspondence between the contribution rate clusters and the project-related users, and filling the permission templates corresponding to the user level into the permission configuration structure to obtain permission configuration information.

[0048] In some embodiments, the ID (Identity) and project data of the current project, including the project name, project level list, etc., are queried through the target database; based on the project ID, all users participating in the project (project-related users) are queried to obtain their user IDs and basic information; based on the project level list, the permission template corresponding to each level is retrieved from the permission template database and stored in dictionary form, with the key being the project level and the value being the permission template.

[0049] In some embodiments, for each project-related user, its historical work sheet is queried by user ID, wherein the historical work sheet is stored in another database and contains multiple work tasks and related information (such as task type, completion time, project to which it belongs, etc.); tasks belonging to the current project are screened out from each user's historical work sheet, and the total workload of these tasks and the importance of each task to the project are calculated; based on the importance and workload of the tasks, the contribution rate of each user to the current project is calculated, wherein the contribution rate can be the sum of the task importance weighted by the workload.

[0050] In some embodiments, K-means (K-means clustering algorithm) or other clustering algorithms are used to cluster all project-related users according to their contribution rates, and the number of clusters is equal to the number of project levels. Each cluster forms a contribution rate cluster; each user is mapped to the corresponding project level according to the cluster to which his contribution rate belongs; and the corresponding permission template is searched from the permission template dictionary according to the user's project level.

[0051] Optionally, the permission configuration layer determines the project contribution rate corresponding to each project-related user according to the proportion between project tasks and work tasks in the following manner: determine any historical worksheet as a target worksheet, determine the work task in the target worksheet as a first task, and determine the project task in the target worksheet as a second task; obtain the task weights corresponding to the work tasks respectively; calculate according to the task weight corresponding to the first task to obtain a first total score; count the proportion of important tasks in the second task according to preset important figures, and count the proportion of repeated tasks in the second task; calculate according to the task weight, important task proportion, and repeated task proportion corresponding to the second task to obtain a second total score, wherein the proportion of important tasks is positively correlated with the second total score, and the proportion of repeated tasks is positively correlated with the second total score; determine the ratio of the second total score to the first total score as the project contribution rate corresponding to the target worksheet.

[0052] In some embodiments, historical worksheets of different project-related users are retrieved from the company's project management system or database, and a suitable list of historical worksheets is filtered out according to needs or specific conditions (such as time range, project name, etc.); from the filtered worksheet list, one is selected as the target worksheet for this assessment; the content of the target worksheet is parsed to distinguish between work tasks (first tasks) and project tasks (second tasks), where work tasks may include daily tasks, support tasks, etc., and project tasks specifically refer to tasks directly related to the current project.

[0053] In some embodiments, a corresponding task weight is assigned to each work task, wherein the task weight is determined based on factors such as the complexity of the task, the time required, and the impact on the project; a first total score is calculated based on the first task (work task) and its corresponding task weight, wherein the first total score is the weighted sum of all the first task weights; the proportion of important tasks in the second task (project task) is counted, wherein the important tasks may be marked in advance by the project manager or team leader; the proportion of repeated tasks in the second task is counted, wherein repeated tasks may refer to tasks that are repeatedly performed at different times or in different projects; a second total score is calculated based on the task weight, the proportion of important tasks, and the proportion of repeated tasks of the second task, and the calculation formula involves the weighted summation of the task weights, and adjustment is made based on the proportion of important tasks and repeated tasks, wherein, although the proportion of repeated tasks may be negatively correlated with the total score under conventional understanding, in this embodiment, repeated tasks may also be regarded as contributing to the project (for example, by optimizing repeated tasks to improve efficiency), and therefore, both the proportion of important tasks and the proportion of repeated tasks are positively correlated with the second total score; the second total score is compared with the first total score, and their ratio is calculated, and the ratio is the project contribution rate corresponding to the target worksheet.

[0054] In some embodiments, both the original access statement and the target statement are SQL statements.

[0055] Optionally, the statement interception layer intercepts the driver layer from executing the original access statement in the following manner: obtaining an interface proxy corresponding to the interactive interface, wherein the driver layer is used to access the target database through the interactive interface, and the interface proxy is used to implement the interactive interface; intercepting the driver layer from executing the original access statement through the interface proxy.

[0056] Optionally, the interface proxy includes at least the following parts: a driver proxy (DriverProxy), which depends on the connection proxy and is used to implement the java.sql.Driver interface in the interaction interface; a connection proxy (ConnectionProxy), which depends on the grammar proxy and the preprocessing proxy and is used to implement the java.sql.Connection interface in the interaction interface; a grammar proxy (StatementProxy), which is used to implement the java.sql.Statement interface in the interaction interface; a preprocessing proxy (PreparedStatementProxy), which inherits the grammar proxy and is used to implement the java.sql.PreparedStatement interface in the interaction interface.

[0057] In some embodiments, the proxy of the driver layer is implemented through the interface proxy, and the proxy layer corresponding to the real database driver is formed according to the interface proxy to implement the interactive interface in the JDBC protocol, thereby intercepting and recording the SQL statements for operating the target database, wherein the relationship between the interface proxy and the interactive interface is as follows: Figure 3 shown.

[0058] In some embodiments, the java.sql.Driver interface is a key interface in the JDBC API, which defines methods that a database driver must implement. This interface allows a Java application to connect to a database through JDBC and execute SQL statements.

[0059] In some embodiments, the java.sql.Connection interface is a core interface in the JDBC API (Application Programming Interface), which represents a connection (session) with a specific database. Through this interface, Java applications can execute SQL statements, manage transactions, and obtain database metadata.

[0060] In some embodiments, the java.sql.Statement interface is an interface in the JDBC API that is used to execute static SQL statements and return the result object it produces. After connecting to the database through JDBC, SQL statements are executed to query, update, insert, or delete data.

[0061] In some embodiments, the java.sql.PreparedStatement interface is an important interface in the JDBC API, which inherits from the java.sql.Statement interface. The PreparedStatement interface represents an object of a precompiled SQL statement. The SQL statement is precompiled and stored in the PreparedStatement object, which can then be used to efficiently execute the statement multiple times.

[0062] In some embodiments, the original access statement is parsed, and the grammatically parsed original access statement is reconstructed according to the permission configuration information of the current user, so that the permissions of the current user are dynamically woven into the original access statement to obtain a target statement.

[0063] Optionally, the permission control layer matches the intercepted original access statement according to the access scope to obtain the target statement in the following manner: parse the intercepted original access statement to obtain the original grammatical structure; determine the unit to be accessed in the target database according to the original grammatical structure, wherein the unit to be accessed includes at least one of a table, a row and a column; determine whether the current user corresponding to the original access statement has database access rights to the target database according to the access scope; if the current user has database access rights to the target database, determine the accessible unit in the target database according to the access scope; update the original grammatical structure according to the matching result between the accessible unit and the unit to be accessed to obtain the target grammatical structure, so as to construct the target statement according to the target grammatical structure.

[0064] In some embodiments, the intercepted SQL statement is parsed into an abstract syntax tree (AST), and the abstract syntax tree is used as the original syntax structure corresponding to the original access statement; the abstract syntax tree is used to check whether the permissions of the SQL statement meet the permission configuration information of the current user; a new SQL statement is constructed according to the abstract syntax tree that meets the permission configuration information to obtain the target statement.

[0065] Optionally, the permission control layer weaves the access condition into the target statement if the access condition does not exist in the target statement in the following manner: if the access condition exists in the permission configuration information, it is determined whether the access condition exists in the target grammatical structure; if the access condition does not exist in the target grammatical structure, the access condition is woven into the target grammatical structure to construct the target statement according to the target grammatical structure.

[0066] Combination Figure 4 As shown, the embodiment of the present disclosure provides a method for generating a target sentence, including:

[0067] Step S401, parse the intercepted original access statement to obtain the original grammatical structure;

[0068] Step S402, obtaining the name of the table to be accessed from the original grammatical structure;

[0069] Step S403, parsing the column name to be accessed in each table from the original grammatical structure;

[0070] Step S404, obtaining the permission configuration information of the current user;

[0071] Step S405, determining whether the current user has access rights to the target database, if yes, jump to step S406, if no, jump to step S410;

[0072] Step S406, determining whether the current user has access rights to the column to be accessed, if so, jump to step S407, if not, jump to step S410;

[0073] Step S407, determine whether the original grammatical structure has the access condition, if so, jump to step S409, if not, jump to step S408;

[0074] Step S408, adding access conditions to the original grammatical structure;

[0075] Step S409: Generate a target sentence according to the original grammatical structure, so as to access the target database through the target sentence.

[0076] Step S410: Block access through the original access statement.

[0077] In some embodiments, the permission configuration information of the current user obtained includes {"context":{"userName":"A"},"rules":{"t_sales":{"rows":"year>2024","columns":{"name":["read"],"age":["read"]}}}}, where the user name is A, the table name is t_sales, the row rules include "year row is greater than 2024", and the column rules include "name column has read-only permission" and "age column has read-only permission". The SQL statement intercepted by user A is select name,age from t_sales, that is, read the name column and age column in the t_sales table; parse the SQL statement into an abstract syntax tree to obtain the table name t_sales to be accessed, the column name name to be accessed, and the column name age to be accessed; determine from the permission configuration information that user A has the read permission for the name column and the age column, so the SQL statement does not exceed the permission scope; at the same time, the abstract syntax tree lacks the permission condition of "year row is greater than 2024", then add this permission condition to the abstract syntax tree to obtain a new target syntax structure, and then generate a new SQL statement "selectname,age from t_sales where year>2024" according to the target syntax structure.

[0078] In some embodiments, the reconstructed target statement is executed through the driver layer, and the execution result is returned to the application.

[0079] Combination Figure 5 As shown, the embodiment of the present disclosure provides a method for access permission control for a database, comprising:

[0080] Step S501, obtaining permission configuration information;

[0081] Wherein, the permission configuration information includes access scope and / or access conditions;

[0082] Step S502, intercepting the driver layer to execute the original access statement;

[0083] Among them, the original access statement is used to access the target database;

[0084] Step S503, matching the intercepted original access statements according to the access scope to obtain the target statement, and if the access condition does not exist in the target statement, weaving the access condition into the target statement;

[0085] Step S504: execute the target statement through the driver layer to access the target database.

[0086] The access permission control method for a database provided by the embodiment of the present disclosure is adopted, and the original access statement is executed by intercepting the driver layer, and the intercepted original access statement is matched according to the access scope in the permission configuration information to obtain the target statement, and the access condition in the permission configuration information is woven into the target statement, and then the target statement is executed by the driver layer to access the target database. In this way, the database access request is directly intercepted and processed at the driver layer, and the intercepted original access statement is modified by the centrally managed access scope and access condition, so as to realize the access permission control for the database, avoid relying on the business code or the persistence layer framework for permission control, extract the permission control logic from the business logic, improve the readability and maintainability of the access permission control, facilitate user maintenance, and thus reduce the maintenance cost of the permission control.

[0087] Combination Figure 6 As shown, the embodiment of the present disclosure provides a method for access permission control for a database, comprising:

[0088] Step S601, the access permission control module obtains permission configuration information;

[0089] Step S602, the application generates an original access statement according to the interface layer;

[0090] Step S603, the application program calls the access permission control module according to the original access statement;

[0091] Step S604, the access permission control module parses the access permission control module to obtain an original grammatical structure;

[0092] Step S605, the access permission control module modifies the original grammatical structure according to the permission configuration information of the current user, so as to generate a target sentence according to the modified original grammatical structure;

[0093] Step S606, the access permission control module calls the driver layer according to the target statement;

[0094] Step S607, the driver layer executes the target statement to access the target database and obtain the access result;

[0095] Step S608, the driver layer sends the access result to the access permission control module;

[0096] Step S609: The access permission control module sends the access result to the application.

[0097] The access permission control method for a database provided by the embodiment of the present disclosure is adopted, and the original access statement is executed by intercepting the driver layer, and the intercepted original access statement is matched according to the access scope in the permission configuration information to obtain the target statement, and the access condition in the permission configuration information is woven into the target statement, and then the target statement is executed by the driver layer to access the target database. In this way, the database access request is directly intercepted and processed at the driver layer, and the intercepted original access statement is modified by the centrally managed access scope and access condition, so as to realize the access permission control for the database, avoid relying on the business code or the persistence layer framework for permission control, extract the permission control logic from the business logic, improve the readability and maintainability of the access permission control, facilitate user maintenance, and thus reduce the maintenance cost of the permission control.

[0098] An embodiment of the present disclosure further provides an electronic device, including: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the above method.

[0099] Figure 7 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Figure 7 The computer system 700 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0100] like Figure 7As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 702 or the program loaded from the storage part 708 to the random access memory (RAM) 703, such as executing the method in the above embodiment. In the RAM 703, various programs and data required for system operation are also stored. The CPU 701, the ROM 702 and the RAM 703 are connected to each other through the bus 704. The input / output (I / O) interface 705 is also connected to the bus 704.

[0101] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed so that a computer program read therefrom is installed into the storage section 708 as needed.

[0102] The electronic device disclosed in this embodiment includes a processor, a memory, a transceiver and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store computer programs, the communication interface is used to communicate, and the processor and the transceiver are used to run the computer program so that the electronic device executes each step of the above method.

[0103] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 709, and / or installed from a removable medium 711. When the computer program is executed by a central processing unit (CPU) 701, various functions defined in the system of the present application are executed.

[0104] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, separate components and functions are optional, and the order of operation can be changed. Parts and sub-samples of some embodiments may be included in or replace parts and sub-samples of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and the claims, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of a stated sub-sample, whole, step, operation, element, and / or component, but do not exclude the presence or addition of one or more other sub-samples, wholes, steps, operations, elements, components and / or groups of these. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.

[0105] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. Technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. Technicians can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0106] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some sub-samples can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.

[0107] The flowchart and block diagram in the accompanying drawings show the possible architecture, functions and operations of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.

Claims

1. An access rights control module for a database, characterized in that: include: The permission configuration layer is used to obtain permission configuration information, wherein the permission configuration information includes access scope and / or access conditions; A statement interception layer, used to intercept the execution of an original access statement by the driver layer, wherein the original access statement is used to access a target database; The permission control layer is used to match the intercepted original access statements according to the access scope to obtain the target statement, and if the access condition does not exist in the target statement, the access condition is woven into the target statement; The statement execution layer is used to execute the target statement through the driver layer to access the target database.

2. The access authority control module according to claim 1, characterized in that: The permission configuration layer obtains permission configuration information in the following ways: Acquire a permission configuration structure, wherein the permission configuration structure includes a related information field and a rule field, and the rule field includes a row rule field and / or a column rule field; The permission configuration information corresponding to the target database is generated according to the permission configuration structure, wherein the relevant information field is used to carry the database identifier and / or user identifier, the row rule field is used to carry the access scope and / or access condition corresponding to any row in the target database, and the column rule field is used to carry the access scope and / or access condition corresponding to any column in the target database.

3. The access authority control module according to claim 2, characterized in that: The authority configuration layer generates authority configuration information corresponding to the target database according to the authority configuration structure in the following manner, including: Acquire a project-related user corresponding to the current project, and acquire multiple project levels corresponding to the current project, and permission templates corresponding to each of the project levels, wherein the target database stores project data of the current project; Acquire a historical work table corresponding to each of the project-related users, wherein the historical work table includes a plurality of work tasks, and at least a portion of the work tasks are project tasks corresponding to the current project; Determine the project contribution rate corresponding to each of the project-related users according to the proportion between the project task and the work task, and perform cluster calculation on the project contribution rate according to the number of project levels to obtain the contribution rate clusters corresponding to each of the project levels; According to the correspondence between the contribution rate cluster and the project-related users, the user level corresponding to each of the project-related users is determined from the project level, and the permission template corresponding to the user level is filled into the permission configuration structure to obtain permission configuration information.

4. The access authority control module according to claim 3, characterized in that: The authority configuration layer determines the project contribution rate corresponding to each of the project-related users according to the proportion between the project task and the work task in the following manner: Determine any historical worksheet as a target worksheet, determine the work task in the target worksheet as a first task, and determine the project task in the target worksheet as a second task; Obtaining task weights corresponding to the work tasks respectively; Calculate according to the task weight corresponding to the first task to obtain a first total score; Counting the proportion of important tasks in the second tasks according to preset important persons, and counting the proportion of repeated tasks in the second tasks; Calculate according to the task weight corresponding to the second task, the proportion of the important tasks, and the proportion of the repeated tasks to obtain a second total score, wherein there is a positive correlation between the proportion of the important tasks and the second total score, and there is a positive correlation between the proportion of the repeated tasks and the second total score; The ratio of the second total score to the first total score is determined as the project contribution rate corresponding to the target worksheet.

5. The access authority control module according to claim 1, characterized in that: The permission control layer matches the intercepted original access statements according to the access scope in the following way to obtain the target statement: Perform grammatical analysis on the intercepted original access statement to obtain the original grammatical structure; Determine a unit to be accessed in the target database according to the original grammatical structure, wherein the unit to be accessed includes at least one of a table, a row, and a column; Determining, according to the access scope, whether the current user corresponding to the original access statement has database access rights to the target database; If the current user has database access rights to the target database, determining accessible units in the target database according to the access scope; The original grammatical structure is updated according to the matching result between the accessible unit and the to-be-accessed unit to obtain a target grammatical structure, so as to construct a target sentence according to the target grammatical structure.

6. The access authority control module according to claim 5, characterized in that: The permission control layer weaves the access condition into the target statement if the access condition does not exist in the target statement in the following manner: If the access condition exists in the permission configuration information, determining whether the access condition exists in the target grammatical structure; If the access condition does not exist in the target grammatical structure, the access condition is woven into the target grammatical structure to construct a target sentence according to the target grammatical structure.

7. The access authority control module according to any one of claims 1 to 6, characterized in that: The statement interception layer intercepts the driver layer from executing the original access statement in the following way: Acquire an interface agent corresponding to an interactive interface, wherein the driver layer is used to access the target database through the interactive interface, and the interface agent is used to implement the interactive interface; The driver layer is intercepted by the interface agent to execute the original access statement.

8. The access authority control module according to claim 7, characterized in that: The interface agent includes at least one of the following: A driver agent, which depends on a connection agent and is used to implement a java.sql.Driver interface in the interaction interface; The connection agent depends on the grammar agent and the preprocessing agent, and the connection agent is used to implement the java.sql.Connection interface in the interaction interface; The grammar agent is used to implement the java.sql.Statement interface in the interactive interface; The preprocessing agent inherits the grammar agent, and the preprocessing agent is used to implement the java.sql.PreparedStatement interface in the interactive interface.

9. A method for controlling access rights of a database, characterized in that: include: Acquiring permission configuration information, wherein the permission configuration information includes access scope and / or access conditions; Intercepting the driver layer to execute an original access statement, wherein the original access statement is used to access a target database; Matching the intercepted original access statements according to the access scope to obtain a target statement, and if the access condition does not exist in the target statement, weaving the access condition into the target statement; The target statement is executed through the driver layer to access the target database.

10. An electronic device, characterized in that: include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the method as claimed in claim 9.

Citation Information

Cited By

  • Business authority management system and method based on big data

    CN119227116A