Data permission control method, device, equipment and storage medium
By building data permission control tables and intercepting SQL statements, analyzing the filtering conditions of user roles and data tables, and building a data filtering model, the problem of high difficulty in maintaining database data permission control and maintenance is solved, and fine permission control and business logic separation is achieved.
Patent Information
- Application Number
- CN202210253777.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-15
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2042-03-15
AI Technical Summary
In the prior art, the maintenance of database data permission control is difficult, especially when complex SQL statements and permission adjustments, a large amount of code development and maintenance is required, which affects the normal use of the business.
Build a data permission control table for a preset database, intercept SQL statements, parse filter conditions for user roles and data tables, query operable data tables and filter conditions, build a data filtering model, realize permission control, and avoid rewriting of the underlying code.
It reduces the difficulty of maintenance of permission control, reduces the analysis and processing of each table and field, and improves the precision and maintenance convenience of permission control.
Smart Images

Figure CN114528593B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a data authority control method, device, electronic device and computer-readable storage medium. Background Art
[0002] In order to protect the security and stability of data in the database, it is usually necessary to perform permission control on the database data, that is, to assign different database data operation permissions to different users, so that users with specific permissions can perform database data operations such as add, delete, modify, and query specified by the specific permissions on the data tables or table fields covered by the specific permissions.
[0003] At present, the more common practice in the industry is to add SQL statements for accessing database data in the business code to control permissions. This approach has the following disadvantages:
[0004] On the one hand, for complex SQL statements, for example, an SQL statement involves multiple data tables, table fields, and multiple filtering conditions. In this case, it is necessary to analyze and judge each data table, related table fields, and filtering conditions, and to assemble SQL statements that comply with data permission control. The code development workload of the corresponding permission control program is relatively large, which will also lead to an increase in the workload of subsequent business maintenance.
[0005] On the other hand, when database data permissions are adjusted, the code of the corresponding permission control program needs to be modified, which affects the normal use of the business and increases the difficulty and cost of business maintenance. Summary of the invention
[0006] The present invention provides a data authority control method, device and computer-readable storage medium, the main purpose of which is to solve the problem of high maintenance difficulty in the data authority control process.
[0007] To achieve the above purpose, the present invention provides a data authority control method, comprising:
[0008] Construct the data permission control table of the preset database;
[0009] When an SQL statement accessing the preset database is detected, the SQL statement is intercepted;
[0010] Parsing the SQL statement to obtain the user role, the object data table and the filtering condition of the object data table;
[0011] From the data authority control table, query the operable data table corresponding to the user role and the filtering conditions of each operable data table;
[0012] Determining whether the object data table is within the operable data table;
[0013] If the object data table is not within the operable data table, access to the SQL statement is prohibited;
[0014] If the object data table is within the operable data table, constructing a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table;
[0015] The data screening model is used to screen out operable data of the user role in the object data table, and the SQL statement is used to perform access operations on the operable data.
[0016] Optionally, the step of constructing a data authority control table of a preset database includes:
[0017] Obtaining the association relationship between all user roles, data tables and filtering conditions in the preset database;
[0018] According to the association relationship, a record row consisting of a corresponding user role, table fields operable by the user role, and corresponding filtering conditions is created for each data table in the database;
[0019] All record rows are collected as a data authority control table of the preset database.
[0020] Optionally, intercepting the SQL statement includes:
[0021] Use Mybatis interceptor to configure interception interface and interception type;
[0022] The interception interface is utilized to intercept SQL statements in the preset database that conform to the interception type.
[0023] Optionally, the determining whether the object data table is within the operable data table includes:
[0024] Constructing a table name index of the operable data table;
[0025] Compile a search statement according to the table name of the object data table;
[0026] Using the search statement to search in the table name index;
[0027] When the table name of the object data table cannot be retrieved in the table name index, determining that the object data table is not within the operable data table;
[0028] When the table name of the object data table can be retrieved in the table name index, it is determined that the object data table is within the operable data table.
[0029] Optionally,
[0030] The step of constructing a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table includes:
[0031] One of the filtering conditions in the object data table and the filtering conditions in the operable data table is designated as a root node one by one;
[0032] Performing node splitting processing on the root node to obtain a basic decision tree including multiple root nodes;
[0033] All basic decision trees are repeatedly node-associated to obtain a data screening model.
[0034] Optionally,
[0035] The node splitting process is performed on the root node to obtain a basic decision tree including multiple root nodes, including:
[0036] Obtain a preset node splitting condition table, and retrieve the splitting condition corresponding to the root node from the node splitting condition table;
[0037] Taking each of the splitting conditions retrieved as a root node parallel to the root node;
[0038] The preset scoring function is configured to each root node to obtain a basic decision tree containing multiple root nodes.
[0039] Optionally, the using the data screening model to screen out the operable data of the user role in the object data table includes:
[0040] Inputting the data in the object data table into the data screening model one by one, and obtaining the output score of the scoring function of each root node in the data screening model for each data in the object data table;
[0041] The sum of the output scores of each data in the object data table is calculated, and the data whose sum is greater than a preset score is selected as the operable data of the user role.
[0042] In order to solve the above problem, the present invention further provides a data authority control device, the device comprising:
[0043] A statement interception module is used to construct a data permission control table of a preset database, and intercept the SQL statement when an SQL statement accessing the preset database is detected;
[0044] A statement parsing module, used to parse the SQL statement to obtain the user role, the object data table and the filtering condition of the object data table;
[0045] A condition query module, used to query the operable data table corresponding to the user role and the filtering condition of each operable data table from the data authority control table;
[0046] A data screening module, used for judging whether the object data table is within the operable data table, prohibiting access to the SQL statement if the object data table is not within the operable data table, and constructing a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table if the object data table is within the operable data table;
[0047] The authority control module is used to use the data screening model to filter out the operable data of the user role in the object data table, and use the SQL statement to perform access operations on the operable data.
[0048] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:
[0049] at least one processor; and,
[0050] a memory communicatively connected to the at least one processor; wherein,
[0051] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the data authority control method described above.
[0052] In order to solve the above problem, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored. The at least one computer program is executed by a processor in an electronic device to implement the data permission control method described above.
[0053] The embodiment of the present invention analyzes the intercepted SQL statements to obtain the user role, object data table and the filtering conditions of the object data table, and compares the object data table with the operable data table corresponding to the user role to achieve the first rough permission control; at the same time, the filtering conditions are used to build a data screening model to filter out the data that meets the filtering conditions so that the user can access it, thereby achieving the second fine permission control, avoiding the rewriting of the underlying code, and there is no need to analyze and process each table and field. Only the data that the user needs to access needs to be processed, which is convenient for subsequent maintenance and reduces the difficulty of dimensional permission control. Therefore, the data permission control method, device, electronic device and computer-readable storage medium proposed in the present invention can solve the problem of high maintenance difficulty in the data permission control process. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 A flowchart of a data authority control method provided by an embodiment of the present invention;
[0055] Figure 2 A schematic diagram of a process for constructing a data authority control table provided in one embodiment of the present invention;
[0056] Figure 3 A schematic diagram of a process for constructing a data screening model provided by an embodiment of the present invention;
[0057] Figure 4 A functional module diagram of a data authority control device provided by an embodiment of the present invention;
[0058] Figure 5 A schematic diagram of the structure of an electronic device for implementing the data authority control method provided by an embodiment of the present invention.
[0059] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0060] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0061] The embodiment of the present application provides a data authority control method. The execution subject of the data authority control method includes but is not limited to at least one of the electronic devices such as a server, a terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the data authority control method can be executed by software or hardware installed on a terminal device or a server device. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0062] Reference Figure 1 FIG. 1 is a flow chart of a data permission control method provided by an embodiment of the present invention. In this embodiment, the data permission control method includes:
[0063] S1. Construct a data permission control table for the preset database.
[0064] In the embodiment of the present invention, the preset database is a relational database, which is the most widely used database and usually organizes data using a relational model and stores data in the form of rows and columns. To facilitate user understanding, in a relational database, a storage unit consisting of a series of rows or columns is called a data table, and a group of data tables constitutes a database.
[0065] In an embodiment of the present invention, in order to protect the security and stability of the data in the preset database, it is usually necessary to perform permission control on the data in the database, that is, to assign different database data operation permissions to different operating users, so that users with specific permissions can perform database data operations such as adding, deleting, modifying, and checking specified by the specific permissions on the data tables or table fields covered by the specific permissions.
[0066] In detail, see Figure 2 As shown, the data authority control table of the preset database is constructed, including:
[0067] S21, obtaining the association relationship between all user roles, data tables and filtering conditions in the preset database;
[0068] S22. Creating, according to the association relationship, a record row consisting of a corresponding user role, table fields operable by the user role, and corresponding filtering conditions for each data table in the database;
[0069] S23. Gather all record rows as a data authority control table of the preset database.
[0070] In an embodiment of the present invention, the filtering condition refers to filtering the data in the data table of the preset database according to certain conditions, and then performing corresponding operations such as adding, deleting, and modifying the filtered data, wherein the filtering condition includes types such as equal conditions and range conditions. For example, a data table named Student Basic Information Table is composed of fields such as Student ID, Student Name, Class Information, Subject 1 Score, and Subject 2 Score. Search for the Subject 2 score of the student whose student ID is equal to 12304520 in the Student Basic Information Table, where the corresponding filtering condition belongs to the equal condition, and search for the student ID of the student whose Subject 2 score is greater than 85 in the Student Basic Information Table, where the corresponding filtering condition belongs to the range condition.
[0071] S2. When an SQL statement accessing the preset database is detected, the SQL statement is intercepted.
[0072] In an embodiment of the present invention, the Mybatis framework can be used to intercept the SQL statements of the preset database. The Mybatis framework is an ORM (Object Relational Mapping) framework, which encapsulates the repetitive and modular work related to the database, for example, encapsulating the connection of the database, the driver package of the database, etc. During development, the user only needs to focus on the SQL statement itself, and does not need to spend time processing the tedious process of loading the driver, creating the connection, etc. Usually, the Mybatis framework manages the database in the form of configuration files or annotations.
[0073] In detail, when the SQL statement accessing the preset database is detected, intercepting the SQL statement includes:
[0074] Use Mybatis interceptor to configure interception interface and interception type;
[0075] The interception interface is utilized to intercept SQL statements in the preset database that conform to the interception type.
[0076] In an embodiment of the present invention, the interface for intercepting SQL statements may be the org.apache.ibatis.plugin.Interceptor interface in the Mybatis framework, and the interception type is specified by the Signature function in the interface. The interception type refers to the type of SQL statement, including addition, deletion, update, and the like.
[0077] Preferably, after intercepting the SQL statement, the method further includes: saving the intercepted SQL statement into the preset database; monitoring the modification result of the intercepted SQL statement; when the modification result of the intercepted SQL statement is failure, obtaining the intercepted SQL statement from the preset database, and re-modifying the intercepted SQL statement.
[0078] In the embodiment of the present invention, the relevant SQL statements of the preset database are uniformly intercepted by the Mybatis interceptor, and the developer does not need to add SQL monitoring, interception and judgment programs in the business logic, thereby achieving the effect of separating business logic from SQL management, and the developer can concentrate on business logic implementation and optimization.
[0079] S3. Parse the SQL statement to obtain the user role, the object data table, and the filtering condition of the object data table.
[0080] In the embodiment of the present invention, the SQL parser sqlparse can be used to split and format the SQL statement to obtain the user role, object data table and filtering condition information of the object data table contained in the SQL statement.
[0081] In another embodiment of the present invention, the SQL statement may also be parsed using a regular expression.
[0082] S4. Query the operable data table corresponding to the user role and the filtering condition of each operable data table from the data authority control table.
[0083] In an embodiment of the present invention, according to the user role, the permission information matching the user role is searched in the data permission control table, and the permission information includes but is not limited to the data tables operable by the user role and the filtering conditions of each operable data table.
[0084] S5. Determine whether the object data table is within the operable data table.
[0085] In one of the practical application scenarios of the present invention, since the object data table is the data table that the user role wants to access, and the operable data table is the data table that the user role can access, the preliminary authority of the user role can be controlled by determining whether the object data table is within the operable data table.
[0086] In the embodiment of the present invention, the step of determining whether the object data table is within the operable data table includes:
[0087] Constructing a table name index of the operable data table;
[0088] Compile a search statement according to the table name of the object data table;
[0089] Using the search statement to search in the table name index;
[0090] When the table name of the object data table cannot be retrieved in the table name index, determining that the object data table is not within the operable data table;
[0091] When the table name of the object data table can be retrieved in the table name index, it is determined that the object data table is within the operable data table.
[0092] In detail, the table name index of the operable data table may be constructed using the CREATE INDEX function in the SQL library.
[0093] For example, the CREATE INDEX function may be:
[0094] CREATE INDEX index name
[0095] ON table name(column name)
[0096] Among them, index name is the name of the table name index, table name is the operable data table, and columnname is the name of the data column where the table name of the operable data table is located.
[0097] S6. If the object data table is not within the operable data table, access to the SQL statement is prohibited.
[0098] In the embodiment of the present invention, if the object data table is not within the operable data table, it means that the object data table that the user role wants to access is a data table for which the user role has no access rights, and therefore the access request of the SQL statement is prohibited.
[0099] S7. If the object data table is within the operable data table, construct a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table.
[0100] In the embodiment of the present invention, if the object data table is within the operable data table, it means that the object data table that the user role wants to access is a data table to which the user role has access rights.
[0101] In one of the actual application scenarios of the present invention, when the object data table is within the operable data table, the user role does not necessarily have access rights to all the data in the object data table. Therefore, in order to achieve data granularity permission control, a data screening model can be constructed based on the filtering conditions of the object data table and the filtering conditions of the operable data table, so as to use the data screening model to analyze and screen the data in the object data table, so as to achieve field-granularity permission control in the data table.
[0102] In the embodiment of the present invention, Figure 3 As shown, the data screening model is constructed according to the filtering conditions of the object data table and the filtering conditions of the operable data table, including:
[0103] S31, selecting one of the filtering conditions in the object data table and the filtering conditions in the operable data table as a target condition one by one;
[0104] S32, assigning a value to a preset decision function using the target condition as a parameter, and using the assigned decision function as a decision condition to generate a decision tree;
[0105] S33. The decision tree generated by collecting all the filtering conditions is used as the data screening model.
[0106] Exemplarily, the decision function may be:
[0107]
[0108] Among them, f(x) is the output value of the decision function, x is the parameter of the decision function, and g(y) is the input value of the decision function.
[0109] In detail, one of the filter conditions of the object data table and the filter conditions of the operable data table can be selected one by one as the target condition, the parameter x of the decision function is assigned using the target condition, and the assigned decision function is used as the decision condition to generate the following decision tree:
[0110] When the input value g(y) of the decision tree is the same as the parameter x of the decision tree, the output value of the decision tree is f(x)=α;
[0111] When the input g(y) of the decision tree is different from the parameter x of the decision tree, the decision tree outputs a value f(x)=β.
[0112] In the embodiment of the present invention, the decision trees corresponding to each feature in the filtering condition may be aggregated in parallel or in series to obtain a data screening model.
[0113] In another embodiment of the present invention, the constructing of the data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table includes:
[0114] One of the filtering conditions in the object data table and the filtering conditions in the operable data table is designated as a root node one by one;
[0115] Performing node splitting processing on the root node to obtain a basic decision tree including multiple root nodes;
[0116] All basic decision trees are repeatedly node-associated to obtain a data screening model.
[0117] In detail, the basic decision tree is the simplest decision tree and is the basis for subsequent decision trees to make decisions.
[0118] Specifically, the node splitting process is performed on the root node to obtain a basic decision tree containing multiple root nodes, including:
[0119] Obtain a preset node splitting condition table, and retrieve the splitting condition corresponding to the root node from the node splitting condition table;
[0120] Taking each of the splitting conditions retrieved as a root node parallel to the root node;
[0121] The preset scoring function is configured to each root node to obtain a basic decision tree containing multiple root nodes.
[0122] Furthermore, the node splitting condition table includes a plurality of filtering conditions and a corresponding splitting condition when each filtering condition is used as a root node.
[0123] In detail, the step of retrieving the splitting condition corresponding to the root node from the node splitting condition table is consistent with the step of searching the table name index using the search statement in S6, and will not be described in detail here.
[0124] Specifically, all basic decision trees are associated with repeated nodes, that is, whether there are repeated root nodes between each basic decision tree is screened. When there are repeated root nodes, different basic decision trees are connected according to the repeated root nodes to obtain a data screening model.
[0125] S8. Filter out the operable data of the user role in the object data table using the data screening model, and perform access operations on the operable data using the SQL statement.
[0126] In an embodiment of the present invention, the data screening model can be used to screen the data in the object data table to filter out the data fields in the object data table that the user can access, thereby achieving data-granular access permission control and improving the accuracy of access permission control.
[0127] In the embodiment of the present invention, the step of using the data screening model to screen out the operable data of the user role in the object data table includes:
[0128] Select one of the data fields from the object data table one by one as input value;
[0129] Selecting one decision tree from the data screening model as a target decision tree, inputting the input value into the target decision tree, and obtaining an output result output by the target decision tree, wherein the output result is that the input value is the same as the parameter of the target decision tree, or the input value is different from the parameter of the target decision tree;
[0130] The output results are collected as data fields whose input values are the same as the parameters of the target decision tree to obtain operable data of the user role.
[0131] For example, the data screening model includes decision trees a1, a2, b1 and b2, and decision tree a1 is selected as the target decision tree; one of the fields is selected from the object data table as the input value, and the input value is input into the decision tree a1, so as to obtain an output result in which the input value output by the decision tree a1 is the same as the parameter of the decision tree a1; the input value is input into the decision tree a2, so as to obtain an output result in which the input value output by the decision tree a2 is different from the parameter of the decision tree a2; the input value is input into the decision tree b1, so as to obtain an output result in which the input value output by the decision tree b1 is different from the parameter of the decision tree b1; the input value is input into the decision tree b2, so as to obtain an output result in which the input value output by the decision tree b2 is different from the parameter of the decision tree b2.
[0132] Among them, since the input value output by the decision tree a1 is the same as the output result of the parameter of the decision tree a1, it can be determined that the input value is an accessible data field of the user role.
[0133] In detail, the output results may be aggregated into data fields whose input values are the same as the parameters of the target decision tree to obtain the operable data of the user role.
[0134] In another embodiment of the present invention, the step of using the data screening model to screen out the operable data of the user role in the object data table includes:
[0135] Inputting the data in the object data table into the data screening model one by one, and obtaining the output score of the scoring function of each root node in the data screening model for each data in the object data table;
[0136] The sum of the output scores of each data in the object data table is calculated, and the data whose sum is greater than a preset score is selected as the operable data of the user role.
[0137] In detail, each data in the object data table can be input into the data screening model one by one, and then the input data can be scored using the scoring function contained in each root node in the data screening model, and the sum of the scores of all root nodes for the data can be calculated to obtain the sum of the output scores of the data, so as to filter the data in the object data table according to the sum, and select the data whose sum is greater than the preset score as the operational data of the user role.
[0138] In the embodiment of the present invention, the rewritten SQL statement can be obtained by using a preset data proxy interface, and the rewritten SQL statement can be sent to the preset database to perform related operations on the preset database. The data proxy interface is connected to the preset database.
[0139] The present invention applies to generate a data permission control table for a preset database based on the three elements of database data permission control, namely user role, data table and filtering conditions, and intercepts SQL statements for accessing the database, and rewrites the SQL statements according to the data permission control table so that the rewritten SQL statements meet the data permission control requirements, wherein the configuration of the data permission control table, interception and rewriting of SQL statements can all be independent of the business, thereby realizing the separation of data permission control from business logic, thereby reducing the development workload and maintenance difficulty of database data permission control.
[0140] The embodiment of the present invention analyzes the intercepted SQL statements to obtain the user role, object data table and the filtering conditions of the object data table, and compares the object data table with the operable data table corresponding to the user role to achieve the first rough permission control; at the same time, the filtering conditions are used to build a data screening model to filter out the data that meets the filtering conditions so that the user can access it, thereby achieving the second fine permission control, avoiding the rewriting of the underlying code, and there is no need to analyze and process each table and field. Only the data that the user needs to access needs to be processed, which is convenient for subsequent maintenance and reduces the difficulty of dimensional permission control. Therefore, the data permission control method proposed in the present invention can solve the problem of high maintenance difficulty in the data permission control process.
[0141] like Figure 4 , which is a functional module diagram of a data authority control device provided in one embodiment of the present invention.
[0142] The data authority control device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the data authority control device 100 can include a statement interception module 101, a statement parsing module 102, a conditional query module 103, a data screening module 104 and an authority control module 105. The module of the present invention can also be referred to as a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.
[0143] In this embodiment, the functions of each module / unit are as follows:
[0144] The statement interception module 101 is used to construct a data permission control table of a preset database, and intercept the SQL statement when an SQL statement accessing the preset database is detected;
[0145] The statement parsing module 102 is used to parse the SQL statement to obtain the user role, the object data table and the filtering condition of the object data table;
[0146] The condition query module 103 is used to query the operable data table corresponding to the user role and the filtering condition of each operable data table from the data authority control table;
[0147] The data screening module 104 is used to determine whether the object data table is within the operable data table. If the object data table is not within the operable data table, access to the SQL statement is prohibited. If the object data table is within the operable data table, a data screening model is constructed according to the filtering conditions of the object data table and the filtering conditions of the operable data table.
[0148] The authority control module 105 is used to use the data screening model to filter out the operable data of the user role in the object data table, and use the SQL statement to perform access operations on the operable data.
[0149] In detail, each module described in the data authority control device 100 in the embodiment of the present invention adopts the same Figures 1 to 3 The data permission control method described in the present invention has the same technical means and can produce the same technical effects, so I will not go into details here.
[0150] like Figure 5 FIG. 1 is a schematic diagram of the structure of an electronic device for implementing a data authority control method provided by an embodiment of the present invention.
[0151] The electronic device 1 may include a processor 10, a memory 11, a communication bus 12, and a communication interface 13, and may also include a computer program stored in the memory 11 and executable on the processor 10, such as a data authority control program.
[0152] In some embodiments, the processor 10 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 10 is the control core (ControlUnit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (for example, executing data authority control programs, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data.
[0153] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 may also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Further, the memory 11 may also include both an internal storage unit of the electronic device and an external storage device. The memory 11 can be used not only to store application software and various types of data installed in the electronic device, such as the code of the data authority control program, but also to temporarily store data that has been output or is to be output.
[0154] The communication bus 12 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.
[0155] The communication interface 13 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), and optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.
[0156] The figure only shows an electronic device with components. Those skilled in the art will understand that the structure shown in the figure does not constitute a limitation on the electronic device, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0157] For example, although not shown, the electronic device may also include a power source (such as a battery) for supplying power to various components. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include any components such as one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, etc. The electronic device may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0158] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0159] The data authority control program stored in the memory 11 of the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:
[0160] Construct the data permission control table of the preset database;
[0161] When an SQL statement accessing the preset database is detected, the SQL statement is intercepted;
[0162] Parsing the SQL statement to obtain the user role, the object data table and the filtering condition of the object data table;
[0163] From the data authority control table, query the operable data table corresponding to the user role and the filtering conditions of each operable data table;
[0164] Determining whether the object data table is within the operable data table;
[0165] If the object data table is not within the operable data table, access to the SQL statement is prohibited;
[0166] If the object data table is within the operable data table, constructing a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table;
[0167] The data screening model is used to screen out operable data of the user role in the object data table, and the SQL statement is used to perform access operations on the operable data.
[0168] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to the description of the relevant steps in the corresponding embodiment of the accompanying drawings, which will not be repeated here.
[0169] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).
[0170] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program can implement:
[0171] Construct the data permission control table of the preset database;
[0172] When an SQL statement accessing the preset database is detected, the SQL statement is intercepted;
[0173] Parsing the SQL statement to obtain the user role, the object data table and the filtering condition of the object data table;
[0174] From the data authority control table, query the operable data table corresponding to the user role and the filtering conditions of each operable data table;
[0175] Determining whether the object data table is within the operable data table;
[0176] If the object data table is not within the operable data table, access to the SQL statement is prohibited;
[0177] If the object data table is within the operable data table, constructing a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table;
[0178] The data screening model is used to screen out operable data of the user role in the object data table, and the SQL statement is used to perform access operations on the operable data.
[0179] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0180] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0181] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0182] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0183] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.
[0184] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0185] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0186] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A data authority control method, characterized in that: The method comprises: Construct the data permission control table of the preset database; When an SQL statement accessing the preset database is detected, the SQL statement is intercepted; Parsing the SQL statement to obtain the user role, the object data table and the filtering condition of the object data table; From the data authority control table, query the operable data table corresponding to the user role and the filtering conditions of each operable data table; Determining whether the object data table is within the operable data table; If the object data table is not within the operable data table, access to the SQL statement is prohibited; If the object data table is within the operable data table, constructing a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table; Using the data screening model to screen out the operable data of the user role in the object data table, and using the SQL statement to perform access operations on the operable data; The step of constructing a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table includes: specifying one of the filtering conditions of the object data table and the filtering conditions of the operable data table as a root node; performing node splitting processing on the root node to obtain a basic decision tree containing multiple root nodes; and performing repeated node association on all basic decision trees to obtain a data screening model; The node splitting process is performed on the root node to obtain a basic decision tree including multiple root nodes, including: obtaining a preset node splitting condition table, retrieving the splitting condition corresponding to the root node from the node splitting condition table; using each of the retrieved splitting conditions as a root node parallel to the root node; configuring a preset scoring function to each root node to obtain a basic decision tree including multiple root nodes; The method of using the data screening model to screen out the operational data of the user role in the object data table includes: inputting the data in the object data table into the data screening model one by one, obtaining the output score of the scoring function of each root node in the data screening model for each data in the object data table; calculating the sum of the output scores of each data in the object data table, and selecting the data whose sum is greater than a preset score as the operational data of the user role.
2. The data authority control method according to claim 1, characterized in that: The data authority control table of the preset database is constructed, including: Obtaining the association relationship between all user roles, data tables and filtering conditions in the preset database; According to the association relationship, a record row consisting of a corresponding user role, table fields operable by the user role, and corresponding filtering conditions is created for each data table in the preset database; All record rows are collected as a data authority control table of the preset database.
3. The data authority control method according to claim 1, characterized in that: The intercepting of the SQL statement comprises: Use Mybatis interceptor to configure interception interface and interception type; The interception interface is utilized to intercept SQL statements in the preset database that conform to the interception type.
4. The data authority control method according to claim 1, characterized in that: The determining whether the object data table is within the operable data table includes: Constructing a table name index of the operable data table; Compile a search statement according to the table name of the object data table; Using the search statement to search in the table name index; When the table name of the object data table cannot be retrieved in the table name index, determining that the object data table is not within the operable data table; When the table name of the object data table can be retrieved in the table name index, it is determined that the object data table is within the operable data table.
5. A data authority control device, used to implement the data authority control method according to any one of claims 1 to 4, characterized in that: The device comprises: A statement interception module is used to construct a data permission control table of a preset database, and intercept the SQL statement when an SQL statement accessing the preset database is detected; A statement parsing module, used to parse the SQL statement to obtain the user role, the object data table and the filtering condition of the object data table; A condition query module, used to query the operable data table corresponding to the user role and the filtering condition of each operable data table from the data authority control table; A data screening module, used for judging whether the object data table is within the operable data table, prohibiting access to the SQL statement if the object data table is not within the operable data table, and constructing a data screening model according to the filtering conditions of the object data table and the filtering conditions of the operable data table if the object data table is within the operable data table; The authority control module is used to use the data screening model to filter out the operable data of the user role in the object data table, and use the SQL statement to perform access operations on the operable data.
6. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the data authority control method as described in any one of claims 1 to 4.
7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the data authority control method as described in any one of claims 1 to 4 is implemented.
