A security database management method and system
By combining bit operations and object relational mapping technology with role-based access control and database views, SQL statements containing data filtering conditions are generated, which solves the problem of low efficiency of traditional database access control and achieves efficient data access control and system performance improvement.
Patent Information
- Application Number
- CN202411047493.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-08-01
AI Technical Summary
Traditional database access control is inefficient, especially row-by-row verification in large-scale databases, which consumes too much time and resources, making it difficult to meet the growing data security needs and system performance requirements.
Using bit operations and object relational mapping (ORM) technology, through the combination of role-based access control and database views, SQL statements containing data filtering conditions are generated for column-level and row-level access control, and the workflow engine is used to perform data change operations. Orchestrate and execute to improve access control efficiency.
It achieves efficient data access control, reduces management complexity and resource consumption, improves system performance and security, and meets the growing needs for data security.
Smart Images

Figure CN118568125B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of databases, and in particular to a method and system for managing a secure database. Background Art
[0002] Database access control is an important means to ensure data security. It ensures that only authorized users can access the corresponding data resources. Traditional database access control is mostly based on the user-role-permission ternary model, which implements the management and verification of user permissions through the association between users and roles and between roles and permissions. This solution has problems such as coarse granularity, complex management, and low efficiency, and it is difficult to meet the growing data security needs and system performance requirements.
[0003] An existing database access control solution is view-based access control, which creates different database views for different users, so that users can only access the data range defined by the view. This solution implements column-level and row-level access control to a certain extent, but the creation and maintenance of views is labor-intensive and difficult to adjust dynamically.
[0004] In the related art, for example, Chinese patent document CN116992466A provides a method for managing a database, including: receiving an adjustment instruction for a database, determining a target row in the database for implementing the adjustment instruction; if the target row is associated with preset type data, based on verification information associated with the target row, determining whether the first user associated with the adjustment instruction has adjustment authority; and if the first user has adjustment authority, executing the action indicated by the adjustment instruction for the target row. However, the row-by-row verification method of this solution will lead to low efficiency of database access control, especially in large-scale databases, where row-by-row verification will consume a lot of time and resources. Summary of the invention
[0005] In view of the problem of low efficiency of database access control in the prior art, the present application provides a method and system for managing a secure database, which improves the efficiency of access control through bit operations and object-relational mapping.
[0006] The purpose of this application is achieved through the following technical solutions.
[0007] One aspect of the present specification provides a method for managing a secure database, including: S1, obtaining a user's database operation request; S2, using a role-based access control method to verify user permissions; S3, after passing the permission verification, using a database view-based access control mechanism, and using an SQL generation method to generate an SQL statement containing data filtering conditions according to the verified user permissions, and perform column-level and row-level access control; S4, accessing the database according to the generated SQL statement to obtain the database operation result; wherein the database operation includes a data query operation and a data change operation; S5, defining the data change operation as a workflow, and arranging and executing the data change process through a workflow engine; encapsulating the operation steps, judgment process and data verification rules into the workflow to control the data change operation; S6, encapsulating the database access operation as an object operation, using an object-relational mapping framework, and using the metadata mapping mechanism of the mapping framework to map object attributes with database table fields, generating SQL statements through the mapping framework, and binding the object attribute values with SQL parameters.
[0008] Among them, step S3 focuses on generating SQL statements containing data filtering conditions according to user permissions to achieve column-level and row-level access control. The main purpose of this step is to add necessary restrictions in the SQL statement to ensure that users can only access the data range they are authorized to. The generation of SQL statements here is mainly related to the results of permission verification, and the corresponding data filtering conditions are dynamically generated according to the user permissions that have passed the verification. Step S6 focuses on simplifying database access operations using the object-relational mapping (ORM) framework, mapping database tables and fields with Java objects and attributes, and implementing database CRUD operations by operating Java objects. The ORM framework uses the metadata mapping mechanism to automatically generate corresponding SQL statements based on the mapping relationship between object attributes and table fields, and binds object attribute values with SQL parameters, so that developers do not need to manually write complex SQL statements. The SQL statements generated by these two steps are combined to form a complete database access statement. The data filtering conditions generated in step S3 can be used as additional WHERE clauses and spliced with the basic SQL statements generated by the ORM framework in step S6 to form the final executed SQL statement. This not only ensures the security of data access, but also improves development efficiency. For example, assuming that step S3 generates the data filtering condition "user_id=123 ANDdepartment_id=456" according to user permissions, and in step S6 the ORM framework generates the basic query statement "SELECT*FROM employee" according to the Java object, the SQL statement finally executed can be "SELECT*FROM employee WHERE user_id=123 AND department_id=456", which includes the results of permission control and object mapping at the same time.
[0009] The data change operation is defined as a workflow, the data change process is orchestrated and executed through the workflow engine, the operation steps, approval process and data validation rules are encapsulated into the workflow, and the data change operation is controlled, including the following steps: splitting the data change operation into multiple operation steps, each operation step contains input parameters, execution conditions and output results; defining the execution order between the operation steps, and forming a directed acyclic graph structure by setting the front and back dependencies between the steps; encapsulating the operation steps, execution order and dependency relationships into the workflow template to form a structured workflow definition; identifying key operation steps, and setting the operation steps that affect the integrity and consistency of the data as approval nodes; setting approval conditions and a list of approvers for each approval node, specifying the approval required when the conditions are met and the corresponding approvers; associating the approval node with the corresponding operation step, building an approval process, and encapsulating the approval process into the workflow template; setting data validation rules for the input parameters and output results of the operation steps to ensure the validity and integrity of the data; encapsulating the data validation rules into the data validation node, and The nodes are associated with the corresponding operation steps; the data change workflow is instantiated according to the workflow template: the data change request is received, and the operation type, operation object, operation parameters and other information in the request are extracted; the corresponding workflow template is selected according to the operation type, and the operation object and operation parameters are passed to the workflow template; an executable data change workflow instance is generated based on the workflow template, and it is submitted to the workflow engine for execution; the operation steps are executed in sequence according to the execution order defined by the workflow; when executing to the approval node, whether approval is required is determined according to the approval conditions; if necessary, the workflow execution is paused, and the approval request is sent to the designated approver, and the execution is continued after the approval is completed; after executing each operation step, the output result is verified by applying the data validation rules; if the validation fails, the workflow execution is terminated and the executed operation steps are rolled back; if all operation steps are executed successfully and the data validation passes, the data change result is submitted to complete the workflow execution; the execution log of the data change workflow is recorded, including information such as the execution status, operation steps, approval records and data validation results, and the execution result is returned to the requester.
[0010] Specifically, by splitting the data change operation into multiple operation steps and defining the execution order and dependency between the steps, a structured workflow template is formed, which provides a basis for subsequent workflow arrangement and execution. By setting the approval node in the workflow template and associating the approval conditions and approvers, the approval process is embedded in the data change operation, and the approval control of key operations is realized. By setting the data verification node in the workflow template and associating the data verification rules, the data verification logic is encapsulated into the workflow, which ensures the validity and integrity of the data change. By instantiating the data change workflow according to the workflow template, associating the specific data change request with the workflow template, and dynamically generating an executable workflow instance, the reusability and flexibility of the workflow are improved. The data change workflow is executed by the workflow engine, and the operation steps are executed in sequence according to the execution order defined by the workflow, and approval and data verification are performed at key nodes, which ensures the controllability of the data change operation and the integrity of the data. If the approval fails or the data verification fails, the workflow execution is terminated and the executed operation steps are rolled back, which ensures the atomicity of the data change.
[0011] Among them, a database view is a virtual table that is defined by query statements based on one or more base tables in the database. Views can limit the scope of user access to data and only expose data columns and rows that users are authorized to access, thereby playing a role in data isolation and protection. The access control mechanism based on database views refers to the control of data access by creating different database views for different users or roles. The system dynamically generates corresponding views based on the user's permissions. Users can only query and operate the data range defined by the view and cannot access unauthorized data. This mechanism can implement fine-grained permission control at the column and row levels at the database level to improve the security of data access. A workflow engine is a software system used to define, execute and manage workflows. Workflow refers to the process of organizing and coordinating various tasks in a business process according to certain rules and sequences to achieve business goals. The workflow engine provides a series of tools and interfaces for modeling workflows, defining tasks, setting dependencies and execution sequences between tasks, assigning tasks to corresponding roles or users, monitoring and managing the execution process of workflows, etc. Through the workflow engine, business processes can be abstracted into workflow models to achieve automation, standardization and visual management of processes, and improve business efficiency and controllability. In database management, data change operations can be defined as workflows. The data change process can be orchestrated and executed through a workflow engine. The operation steps, approval processes, and data validation rules can be encapsulated into the workflow to standardize and control the data change process.
[0012] The Object-Relational Mapping (ORM) framework is a software development technology used to implement the mapping and conversion between objects in object-oriented programming languages and data in relational databases. The ORM framework provides an abstract data access method by mapping database tables and fields with classes and properties in programming languages such as Java. Developers can use object-oriented methods to perform database programming and implement operations such as adding, deleting, modifying, and querying databases by operating Java objects without having to write complex SQL statements. The ORM framework uses the metadata mapping mechanism to define the mapping relationship between object attributes and database table fields through configuration files or annotations. The framework automatically generates the corresponding SQL statements based on the mapping relationship and binds the object attribute values to SQL parameters to achieve data persistence and query. Common ORM frameworks include Hibernate, My Batis, Spring Data JPA, etc. They simplify the complexity of database programming, improve development efficiency, and also enhance the maintainability and portability of the code.
[0013] Furthermore, a role-based access control method is used to verify user permissions, including: associating permissions with roles, obtaining inheritance and reuse of parent role permissions by child roles by constructing a role inheritance relationship tree, and constructing a permission template; wherein the role inheritance relationship tree uses roles as nodes and inheritance relationships between roles as edges, and traverses the role inheritance relationship tree through depth-first search to obtain parent role permissions inherited by child roles; according to the permission template, a permission judgment matrix is constructed through sparse matrix compression storage; user ID, role ID and permission ID are mapped to rows, columns and values of the matrix; wherein the rows of the permission judgment matrix represent user IDs, columns represent permission IDs, and values are Boolean type, indicating whether the user has the corresponding permissions; receiving a user's database operation request, obtaining the user ID and operation type in the request; according to the operation type, obtaining the corresponding permission ID from the permission template; through the permission judgment matrix, using the user ID and permission ID as row and column indexes of the matrix to query the value of the corresponding position; if the value is true, it means that the user has the permission and access is allowed; otherwise, access is denied.
[0014] Among them, inheritance is an important concept in object-oriented programming, which means that a class (called a subclass or derived class) can inherit the properties and methods of another class (called a parent class or base class). Through inheritance, a subclass can obtain the characteristics of the parent class, and can add or modify its own unique properties and methods on this basis. The purpose of inheritance is to achieve code reuse and expansion. The subclass inherits the properties and methods of the parent class, avoiding the need to repeatedly write the same code and improving the reusability of the code. At the same time, the subclass can be expanded on the basis of inheritance, adding new properties and methods, or rewriting the methods of the parent class to achieve specific functions.
[0015] In role-based access control, you can build a role inheritance tree to let child roles inherit the permissions of the parent role. Child roles automatically have the permissions of the parent role without repeated definition, so that permissions can be reused. At the same time, child roles can add their own unique permissions based on inheritance to achieve flexible permission management. Reuse refers to a method in software development that applies existing software elements (such as code, design, test cases, etc.) to new software development to improve development efficiency, reduce development costs, and improve software quality.
[0016] The purpose of reuse is to maximize the use of existing software resources and avoid duplication of work and waste. Through reuse, new software systems can be built quickly and the development cycle can be shortened. Reused software elements are usually fully tested and verified, which can improve the reliability and stability of the new system. In permission management, permission reuse can be achieved through permission templates. Common permission combinations are encapsulated into permission templates, and different roles can reuse these permission templates without defining permissions from scratch. Through the reuse of permission templates, permissions can be quickly assigned to roles, improving the efficiency of permission management. Sparse matrix refers to a matrix with a relatively small number of non-zero elements in the matrix. When storing sparse matrices, if the traditional two-dimensional array storage method is used, a lot of storage space will be wasted because most of the elements are zero. Sparse matrix compression storage is a special storage method used to reduce the storage overhead of sparse matrices. Common sparse matrix compression storage methods include COO (Coordinate) format, CSR (Compressed Sparse Row) format, and CSC (Compressed Sparse Column) format. Taking the COO format as an example, it uses three arrays to store sparse matrices: the data array stores the values of non-zero elements, the row array stores the row numbers of non-zero elements, and the col array stores the column numbers of non-zero elements. In this way, only the non-zero elements and their position information in the sparse matrix are stored, avoiding the storage of a large number of zero elements and greatly reducing the storage space. In permission management, sparse matrix compression storage can be used to construct a permission judgment matrix. The user ID and permission ID are used as the row and column indexes of the matrix, and whether the user has the corresponding permission is used as the value of the matrix. Since most users have only a few permissions, the permission judgment matrix is usually a sparse matrix. Using sparse matrix compression storage can reduce storage overhead and improve the efficiency of permission judgment.
[0017] Furthermore, the user authority is verified by using a role-based access control method, which also includes: caching the authority template in memory or a distributed cache server, and setting a cache expiration time; when the user authority changes, synchronizing the changed authority information to the cache; for operations with an access frequency higher than a threshold, it is defined as a high-frequency operation; for high-frequency operations, pre-calculating the bit vector corresponding to the cache authority template; mapping the authority template ID to an index of the bit vector, and judging whether the user has the preset authority through bit operations; wherein each bit of the bit vector represents an atomic authority, 1 represents authority, and 0 represents no authority; setting session-level authority verification, when the user logs in, obtaining the user's role information from the database according to the user ID, and then obtaining the authority information corresponding to the role from the cache or database according to the role ID, and performing authority verification; saving the authority information that passes the verification to the session object. Preferably, setting session-level authority verification, when the user logs in, obtaining the user's role information from the database according to the user ID, and then obtaining the authority information corresponding to the role from the authority template cache according to the role ID, and performing authority verification; saving the authority information that passes the verification to the session object, and subsequent operations directly obtain authority from the session object to avoid repeated verification.
[0018] Among them, an expiration time is set for the cache. When the cache reaches the expiration time, it automatically becomes invalid. When accessed again, the latest data is obtained from the source data and the cache is updated. Preferably, the timed refresh strategy: a fixed time interval is set to regularly obtain the latest data from the source data and update the cache. In permission management, the permission template can be cached in the memory or distributed cache server to improve the efficiency of permission verification. At the same time, a suitable cache refresh strategy is set. When the user permission changes, the cache refresh is triggered, and the changed permission information is synchronized to the cache to ensure the accuracy of permission verification. Bit vector is a compact data structure that uses a string of binary bits (0 or 1) to represent a set of data. Each bit represents a specific attribute or condition, 1 means that the attribute is possessed or the condition is satisfied, and 0 means that the attribute is not possessed or the condition is not satisfied. Bit vectors are usually used to represent information such as sets, states or permissions. Compared with integers or strings, bit vectors can significantly reduce storage space and improve operation efficiency. Bit operations (such as AND, OR, XOR, etc.) can quickly perform set operations, state judgment or permission verification. In permission management, bit vectors can be used to represent permission templates. Each atomic permission is mapped to a bit of a bit vector, 1 means that the permission is granted, and 0 means that the permission is not granted. Bit operations can be used to efficiently determine whether a user has a specific permission combination. Atomic permissions refer to the smallest granularity unit of permission control, and are basic permissions that cannot be further subdivided. Atomic permissions usually indicate permission or prohibition for a specific resource or operation. In a permission management system, permissions are usually divided into multiple atomic permissions, and then more complex permissions are formed through the combination of atomic permissions. Atomic permissions can be permissions to add, delete, modify, and query data, access permissions to functional modules, and approval permissions for operations. Through the combination of atomic permissions, fine-grained permission control can be achieved. Different roles can have different atomic permission combinations, which can be flexibly configured according to actual needs. When performing permission verification, it can be determined whether a user has a specific atomic permission, thereby determining the user's access rights to resources or operations. Session-level permission verification refers to a mechanism for verifying and maintaining the user's permissions during a session after the user logs in to the system. When a user logs in to the system, the system obtains the user's role information from the database or other permission storage based on the user's identity information (such as user ID), and then obtains the corresponding permission information based on the role information. Verify the obtained permission information to ensure that the user has legal permissions. The verified permission information can be saved in the session object and associated with the user's session. During the session, the user's subsequent requests can directly obtain permission information from the session object without repeatedly querying the database or cache, which improves the efficiency of permission verification. Session-level permission verification avoids the overhead of permission query and verification for each request, while ensuring the consistency of user permissions during the session.When the user logs out or the session expires, the session object and its associated permission information will be destroyed to ensure timely updating of permissions.
[0019] Among them, the permission template is converted into a bit vector by atomic permission decomposition and encoding, and each bit represents an atomic permission, which improves the flexibility and scalability of permission verification. The bit vector is cached in the memory or cache server and updated synchronously with the cache of the permission template to ensure the real-time and consistency of permission verification. The target bit vector and the permission template bit vector are compared through bit operations to avoid string comparison and table lookup operations, thereby improving the performance of permission verification. The bit vector index method is adopted to map the permission template ID to the index of the bit vector, which speeds up the permission verification process and reduces the memory usage of the cache.
[0020] Furthermore, whether the user has preset permissions is determined through bit operations, including: decomposing the permission template into atomic permissions, representing each permission template as a combination of atomic permissions to form an atomic permission set; encoding the atomic permission set, using Huffman coding, allocating coding lengths according to the frequency of use of atomic permissions, and forming an atomic permission coding dictionary; according to the atomic permission coding dictionary, converting the permission template into a bit vector in the form of Huffman coding; wherein each bit indicates whether the permission template contains the corresponding atomic permission; using a Bloom filter to compress and store the bit vector, mapping the bit vector to a bit array of the Bloom filter through multiple hash functions; storing the compressed bit vector index in memory or distributed cache, and setting the expiration time and refresh policy of the bit vector index; when the permission template changes, triggering the cache refresh mechanism, regenerating the bit vector index, and updating the cache.
[0021] Among them, the cache refresh strategy refers to the strategy and mechanism for updating the cache in order to ensure the consistency of cache data with the source data when using cache technology. Expiration time strategy: set an expiration time for the cache. When the cache reaches the expiration time, it will automatically become invalid. When accessed again, the latest data will be obtained from the source data and the cache will be updated. Active update strategy: when the source data changes, the cache update is triggered immediately to synchronize the latest data to the cache.
[0022] Among them, permission decomposition refers to the process of splitting complex permission templates or permission rules into more fine-grained atomic permissions. Atomic permissions are the smallest unit of permission control and cannot be further subdivided. Through permission decomposition, permission templates can be represented as a combination of a set of atomic permissions. For example, a permission template called "article management" can be decomposed into atomic permissions such as "article creation", "article editing", "article deletion", and "article publishing". The purpose of permission decomposition is to simplify the management and verification of permissions. By mapping permission templates to a collection of atomic permissions, permissions can be combined and verified more flexibly. Different permission templates can share the same atomic permissions, improving the reusability and consistency of permissions. Huffman Coding is a lossless compression encoding method that analyzes the frequency of data occurrence, assigns shorter codes to frequently occurring data, and assigns longer codes to rarely occurring data, thereby achieving the purpose of data compression.
[0023] In Huffman coding, the frequency of occurrence of each element in the statistics is first counted, and then a Huffman tree is constructed based on the frequency. The Huffman tree is a binary tree whose leaf nodes represent data elements and non-leaf nodes represent combinations of data elements. By traversing the Huffman tree, a unique code can be generated for each data element. Using Huffman coding can reduce the storage and transmission overhead of data, and is particularly suitable for scenarios where data is unevenly distributed and has obvious frequency differences. In permission management, atomic permissions can be encoded through Huffman coding, and shorter codes can be assigned to frequently used atomic permissions to improve the efficiency of permission verification.
[0024] Bloom filter is a probabilistic data structure used to quickly determine whether an element belongs to a set. Bloom filter maps elements to a fixed-size bit array through multiple hash functions and sets the corresponding position to 1. The characteristics of Bloom filter are high space efficiency, but there is a certain misjudgment rate. When judging whether an element belongs to a set, if the Bloom filter returns no, the element must not be in the set; if it returns yes, the element may be in the set, and there is a certain possibility of misjudgment. In permission management, Bloom filter can be used to compress and store bit vectors. Map the bit vector of the permission template to the bit array of the Bloom filter through multiple hash functions, and set the corresponding bit to 1. When performing permission verification, the Bloom filter is used to quickly determine whether the user has a specific permission combination, avoiding direct comparison of the complete bit vector and improving verification efficiency.
[0025] Among them, Huffman coding is used to encode atomic permissions, and the coding length is allocated according to the frequency of use, which reduces the average length of the bit vector and improves storage efficiency and query performance. Bloom filters are used to compress and store bit vectors, which significantly reduces memory usage while ensuring fast queries. Bloom filters are used to determine whether the target bit vector is included in the permission template bit vector, avoiding bit-by-bit comparison and speeding up the permission verification process. The bit vector index is cached in memory or distributed cache, which is consistent with the cache of the permission template, improving the real-time and availability of permission verification.
[0026] Preferably, the atomic permission encoding dictionary is a data structure that maps atomic permissions to unique codes. By assigning a unique code to each atomic permission, the permission template can be converted into an encoded bit vector representation. For large-scale permission management systems, the storage and calculation of bit vectors may occupy a large amount of memory and computing resources. Compression algorithms can be used to compress and store bit vectors, such as run-length encoding (Run-Length Encoding), bitmap indexing, etc., to reduce memory usage. When performing bit operations, the parallel computing capabilities of the CPU can be utilized, such as using the SIMD (Single Instruction Multiple Data) instruction set to calculate multiple bits at the same time to improve computing efficiency. The atomic permission encoding dictionary can be combined with other data structures and algorithms to further optimize the performance of permission management. For example, a hash table or prefix tree (Trie) is used to speed up the search and matching of atomic permissions. For the hierarchy and inheritance relationship of permissions, a directed acyclic graph (DAG) or a tree structure can be used for modeling and storage, and the propagation and verification of permissions can be achieved through a graph traversal algorithm.
[0027] Furthermore, determining whether the user has preset permissions through bit operations also includes: for high-frequency operations, obtaining the corresponding permission template ID from the permission template cache according to the operation type; using the permission template ID as an index to obtain the corresponding compressed bit vector from the bit vector index cache; constructing a Huffman decoding tree based on the Huffman encoding of the compressed bit vector, and decoding the compressed bit vector into an atomic permission set; encoding the atomic permission encoding dictionary based on the atomic permission set, and converting it into a target bit vector in Huffman encoding form; performing hash mapping on the target bit vector to obtain multiple corresponding positions in the Bloom filter; determining whether the obtained positions are all 1, and if so, it means that the target bit vector is included in the permission template bit vector, indicating that the user has the requested permission and access is allowed, otherwise access is denied.
[0028] Further, an SQL statement containing data filtering conditions is generated to perform column-level and row-level access control, including: obtaining the user's access rights to the database according to the permission verification result; the access rights include the user's access control information to the database table, column and row;
[0029] According to the user's access rights to the columns of the database table, a projection operation is used to generate a column-level view that is allowed to be accessed; preferably, according to the user's access rights to the columns of the database table, a projection operation is used to generate a column-level view that is allowed to be accessed, including: obtaining the user's access rights to the columns of the database table, generating a column access rights list, each item in the column access rights list contains a column name and a corresponding access right; traversing the column access rights list, and adding the columns with access rights to the projection column list; using the projection column list to generate an SQL statement for the column-level view, and implementing the projection operation through the column name list in the SELECT statement. Among them, the column projection operation refers to selecting specific columns from the database table to generate a new view or result set. Through the column projection operation, the user's access rights to the columns of the database table can be controlled, only the columns that the user is authorized to access are exposed, and sensitive or unauthorized columns are hidden.
[0030] In SQL, column projection operations are usually implemented using SELECT statements, by explicitly specifying the required column names, or using wildcards (*) to select all columns. Preferably, use the column projection function of the SELECT statement to selectively include columns that are allowed to be accessed based on the user's access rights to the columns of the database table. Column aliases can be used to provide meaningful names for selected columns to improve the readability of the view. For sensitive columns, functions or expressions can be used to desensitize or encrypt column values to ensure data security.
[0031] According to the user's access rights to the rows of the database table, a projection operation is used to generate a row-level view that is allowed to be accessed; preferably, the user's access rights to the rows of the database table are obtained, and a row access right expression is generated, and the row access right expression consists of one or more filtering conditions; the row access right expression is converted into a WHERE clause in an SQL statement; the WHERE clause is used to generate an SQL statement for the row-level view, and the selection operation is implemented through the WHERE clause in the SELECT statement. Among them, the row projection operation refers to selecting rows that meet the conditions from the database table according to specific conditions to generate a new view or result set. Through the row projection operation, the user's access rights to the rows of the database table can be controlled, only the rows that the user is authorized to access are exposed, and the rows that are not authorized or do not meet the conditions are hidden. In SQL, the row projection operation is usually implemented using a SELECT statement with a WHERE clause, and the required rows are selected by specifying filtering conditions. Preferably, the WHERE clause of the SELECT statement is used to set filtering conditions according to the user's access rights to the rows of the database table, and only the rows that are allowed to be accessed are selected. Complex conditional expressions, such as comparison operators, logical operators, IN, EXISTS, etc., can be used to filter according to specific row-level access control rules. For row-level access control based on time, geographic location, user attributes, etc., you can use corresponding functions or query conditions to restrict it.
[0032] The column-level view and the row-level view are connected to generate the final view that is allowed to be accessed; preferably, the column-level view and the row-level view are connected using the JOIN operation to generate the final view that is allowed to be accessed. You can use inner join (INNERJOIN) or left join (LEFTJOIN) and select the appropriate connection method according to specific business needs. The connection condition can be based on the primary key, foreign key or other related columns to ensure the association between views.
[0033] The query condition requested by the user is associated with the final view, and an SQL statement is generated that only queries the data that is allowed to be accessed; preferably, the query condition requested by the user is obtained, and a query condition expression is generated; the query condition expression is spliced with the SQL statement of the final view to generate an SQL statement containing the query condition; in the spliced SQL statement, the query condition requested by the user is associated with the final view through a WHERE clause.
[0034] The changed data requested by the user is associated with the final view, and an SQL statement is generated that only updates the data that is allowed to be accessed; preferably, the changed data requested by the user is obtained, and a change data expression is generated; the change data expression is spliced with the SQL statement of the final view to generate an SQL statement containing the change data; in the spliced SQL statement, the changed data requested by the user is associated with the final view through the SET clause and WHERE clause of the UPDATE statement. The generated SQL statement is executed to access the database and obtain the database operation result.
[0035] Furthermore, generating a final view that allows access includes: using the SQL statement of the column-level view and the SQL statement of the row-level view to construct an SQL statement for a connection query; in the SQL statement for the connection query, connecting the column-level view and the row-level view through the primary key or foreign key to generate a final view containing the columns and rows that are allowed to be accessed.
[0036] Preferably, the data structures of the column-level view and the row-level view are analyzed, and the common connection fields in the two views are extracted, including primary keys, foreign keys or other fields that can be used for connection; according to the data types and constraints of the connection fields, the optimal connection mode is determined, including inner connection, left outer connection, right outer connection or full outer connection; in the SELECT clause, the columns to be queried are specified, including the columns that are allowed to be accessed in the column-level view and the row-level view; in the FROM clause, the column-level view and the row-level view are specified as the source tables for the connection; in the WHERE clause or the ON clause, the filter conditions for the connection are specified according to the conditions of the connection fields; the connection is executed. Receive the SQL statement of the query, associate the column-level view and the row-level view according to the connection conditions, and generate a final view containing the columns and rows that are allowed to be accessed; analyze the query execution plan of the final view to identify performance bottlenecks and optimization opportunities; rewrite and optimize the SQL statement of the connection query according to the query execution plan, such as adjusting the connection order, adding indexes, using materialized views, etc.; re-execute the optimized SQL statement of the connection query to generate a final view with better performance; store the definition of the final view in the data dictionary, including metadata such as view name, view structure and access rights, for subsequent data query and access control.
[0037] Specifically, by analyzing the data structure of column-level view and row-level view, the common connection fields in the two views are extracted to provide a basis for subsequent connection operations. According to the characteristics of the connection fields, the optimal connection method is selected, such as inner connection for fully matched connection conditions and outer connection for incomplete matching, to improve the efficiency and accuracy of the connection. Using the SQL statements of column-level view and row-level view, the SQL statement of the connection query is constructed, the query columns are specified by the SELECT clause, the source table of the connection is specified by the FROM clause, and the connection conditions are specified by the WHERE or ON clause. The SQL statement of the connection query is executed, the column-level view and the row-level view are associated according to the connection conditions, and the final view containing the columns and rows allowed to be accessed is generated, realizing the combination of column-level and row-level access control. The performance of the generated final view is optimized, and the performance bottleneck is identified by analyzing the query execution plan, and corresponding optimization measures are taken, such as adjusting the connection order, adding indexes, using materialized views, etc., to improve the query performance of the final view. By introducing the steps of performance optimization and metadata management, the query efficiency and maintainability of the final view are further improved, and the practicality and scalability of the secure database management method are enhanced.
[0038] Further, S6 encapsulates the database access operation as an object operation, and uses an object-relational mapping framework to bind the object attribute value with the SQL parameter, including: defining an entity object corresponding to the database table structure, and the attributes in the entity object correspond one-to-one with the fields of the database table; using the metadata annotation or configuration file provided by the object-relational mapping framework to describe the mapping relationship between the entity object and the database table; wherein the object-relational mapping framework includes a data access layer and an application layer: the data access layer is responsible for direct interaction with the database, and provides data access interfaces and methods; the application layer is responsible for processing business logic, calling the interfaces and methods provided by the data access layer, and performing database operations.
[0039] In the data access layer, data access functions are implemented based on the data access interfaces provided by the object-relational mapping framework, such as JpaRepository, Sql Session Dao Support, etc.: inherit the data access interface provided by the framework to obtain basic data access functions, such as add, delete, modify and query; define your own data access methods according to business needs, such as conditional query, batch update, etc.; in the application layer, obtain an instance of the data access layer through the factory pattern: define the data access layer interface and declare the data access method; implement the factory class, create a data access layer instance according to the configuration information, and return it to the application layer; the application layer obtains the data access layer instance through the factory class, calls the data access method, and performs database operations.
[0040] When the application layer calls the data access layer method, the object-relational mapping framework generates SQL statements executed by the data access layer based on the metadata mapping information: the mapping framework generates the SELECT clause and WHERE clause of the query statement based on the attributes and annotations of the entity object; the mapping framework generates the INSERT clause and VALUES clause of the add statement based on the attribute values of the entity object; the mapping framework generates the UPDATE clause and SET clause of the update statement based on the attribute values of the entity object; the mapping framework generates the DELETE clause and WHERE clause of the delete statement based on the passed in primary key value.
[0041] The data access layer interacts with the database by executing the generated SQL statements through the API provided by the object-relational mapping framework: the data access layer calls the data access method of the mapping framework and sends the SQL statements to the database for execution; the database executes the SQL statements and returns the operation results to the data access layer; the mapping framework converts the operation results into entity objects, fills in the attribute values of the entity objects, and returns them to the data access layer; the data access layer returns the entity objects to the application layer for use by the business logic.
[0042] When performing an update operation, the application layer passes the modified entity object to the data access layer: the application layer calls the update method of the data access layer and passes the modified entity object as a parameter; the data access layer converts the entity object into an UPDATE statement through the mapping framework and performs the update operation; the database performs the update operation and returns the update result to the data access layer; the data access layer returns the update result to the application layer, completing the update operation process.
[0043] Among them, entity objects refer to objects used to represent a table in a database in object-oriented programming. The properties of entity objects correspond one-to-one to the fields of the database table. By operating entity objects, the data in the database can be indirectly operated. Entity objects usually contain the following contents: Properties represent the fields in the database table, which can be basic data types or other entity objects. Relationships represent the associations between entity objects, such as one-to-one, one-to-many, many-to-many, etc. Methods represent the behavior of operating entity objects, such as getting attribute values, setting attribute values, saving, deleting, etc. The definition of entity objects is usually implemented using classes in object-oriented programming languages. By mapping database tables with entity objects, database operations can be converted into object operations, improving development efficiency and maintainability.
[0044] Among them, metadata annotation or configuration file refers to a method used to describe the mapping relationship between entity objects and database tables in the object-relational mapping (ORM) framework. Through metadata annotation or configuration file, the attributes of entity objects can be associated with the fields of database tables, and information such as primary keys, foreign keys, and constraints can be specified. Metadata annotation usually uses the annotation mechanism provided by the programming language to add mapping information to the class or attribute of the entity object in a declarative manner. For example, in Java, annotations provided by JPA (Java Persistence API), such as @Entity, @Table, @Column, etc., can be used to annotate the mapping relationship between entity objects and database tables. Configuration files use independent files to describe mapping relationships, usually in XML, YAML, property files and other formats. In the configuration file, the corresponding relationship between entity objects and database tables, the mapping between attributes and fields, and the association relationship can be defined. The role of metadata annotations and configuration files is to map the object-oriented entity model with the table structure of the relational database, so that developers can indirectly operate the database by operating entity objects without writing complex SQL statements. The ORM framework automatically generates corresponding SQL statements based on the mapping information provided by the metadata annotation or configuration file to perform database operations.
[0045] Among them, the factory pattern is a commonly used design pattern used to create an instance of an object without explicitly specifying a specific class. The factory pattern encapsulates the object creation process and provides a unified interface to obtain object instances, thereby reducing the complexity and coupling of object creation. In the factory pattern, the following roles are usually included: Abstract Factory defines the interface for creating objects, but does not implement the specific object creation logic. Concrete Factory implements the interface defined by the abstract factory and is responsible for the actual object creation. Abstract Product defines the interface of the object created by the factory, which can be an interface or an abstract class. Concrete Product implements the interface defined by the abstract product and represents the specific object created by the factory. In the data application layer, the factory pattern is used to obtain an instance of the data access layer, which can encapsulate the creation process of the data access layer and provide a unified interface to obtain data access objects. This can hide the specific implementation details of the data access layer and improve the maintainability and extensibility of the code. The creation and use of objects are separated, reducing the coupling. The complexity of object creation is hidden, and the client only needs to obtain objects through the factory without worrying about the specific creation process of the object. The mapping relationship between entity objects and database tables is described through metadata annotations or configuration files. The factory pattern is used to create instances of the data access layer, which simplifies the process of obtaining data access objects.
[0046] Among them, by defining the entity objects corresponding to the database table structure and using the metadata annotations or configuration files provided by the object-relational mapping framework to describe the mapping relationship between the entity objects and the database tables, the mapping foundation between objects and relationships is established. The object-relational mapping framework usually consists of two parts: the data access layer and the application layer. The data access layer is responsible for direct interaction with the database and provides data access interfaces and methods; the application layer is responsible for processing business logic, calling the interfaces and methods provided by the data access layer, and performing database operations.
[0047] In the data access layer, data access functions are implemented based on the data access interfaces provided by the object-relational mapping framework, such as JpaRepository, Sql Session Dao Support, etc. By inheriting the data access interfaces provided by the framework, basic data access functions are obtained, and your own data access methods are defined according to business needs. In the application layer, an instance of the data access layer is obtained through the factory pattern. By defining the data access layer interface and declaring the data access method, the factory class is implemented to create a data access layer instance according to the configuration information. The application layer obtains the instance through the factory class and calls the data access method to perform database operations. When the application layer calls the data access layer method, the object-relational mapping framework automatically generates SQL statements executed by the data access layer based on the metadata mapping information, including SELECT, INSERT, UPDATE, DELETE and other statements, and binds the attribute values of the entity object to the SQL parameters. The data access layer executes the generated SQL statements through the API provided by the object-relational mapping framework to interact with the database. The data access layer calls the data access method of the mapping framework and sends the SQL statement to the database for execution. After the database executes the SQL statement, it returns the operation result to the data access layer. The mapping framework converts the operation result into an entity object and returns it to the data access layer. Finally, the data access layer returns the entity object to the application layer. When performing an update operation, the application layer passes the modified entity object to the data access layer. The data access layer converts the entity object into an UPDATE statement through the mapping framework and performs the update operation. After the database executes the update, it returns the result to the data access layer. The data access layer then returns the result to the application layer, completing the data flow process of the entire update operation.
[0048] Among them, the metadata annotations or configuration files provided by the object-relational mapping framework are used to describe the mapping relationship between entity objects and database tables; among them, the object-relational mapping framework includes a data access layer and a data application layer: the data access layer is used to interact directly with the database, including: inheriting the data access interface provided by the object-relational mapping framework, such as JpaRepository, Sql Session Dao Support, etc., to obtain basic data access functions, such as add, delete, modify, and query operations; according to specific business needs, define data access methods, and use the query language or API provided by the object-relational mapping framework in the method to write data access logic; the data application layer is used to perform database operations, including: a. Obtain an instance of the data access layer through dependency injection or factory mode: declare member variables of the data access layer interface type in the service class or controller class of the data application layer; use a dependency injection framework, such as Spring The IOC container injects the instance of the data access layer into the data application layer; in the business method of the data application layer, the method of the data access layer is called to perform database operations; when performing query operations, the data application layer calls the query method of the data access layer and passes in the query conditions; the data access layer generates query statements through the API provided by the object-relational mapping framework and sends them to the database for execution; the database executes the query operation and returns the results to the data access layer; the object-relational mapping framework converts the query results into entity objects, fills in the attribute values of the entity objects, and returns them to the data access layer; the data access layer returns the query results to the data application layer in the form of entity objects for use by the business logic; when performing update operations, the data application layer passes the modified entity objects to the data access layer: the data application layer calls the update method of the data access layer and passes in the modified entity objects as parameters; the data access layer converts the entity objects into UPDATE statements through the API provided by the object-relational mapping framework and sends them to the database for execution; the database executes the update operation and returns the update results to the data access layer; the data access layer returns the update results to the data application layer to complete the update operation process.
[0049] Preferably, the metadata annotations provided by the object-relational mapping framework are used to describe the mapping relationship between the entity object and the database table, including: adding the @Entity annotation to the class definition of the entity object to identify the class as an entity class, corresponding to the database table; adding the @Column annotation to the attribute definition of the entity object to specify the mapping relationship between the attribute and the database table field, including metadata information such as the field name, data type, and length; adding the @Id annotation to the primary key attribute of the entity object to identify the attribute as the primary key, corresponding to the primary key field of the database table.
[0050] Preferably, an XML configuration file provided by an object-relational mapping framework is used to describe the mapping relationship between entity objects and database tables, including: defining in the XML configuration file <class>Element, specify the fully qualified name of the entity class, corresponding to the database table; <class>Defined within an element <property>Element, which specifies the mapping relationship between the attributes of the entity class and the fields of the database table, including metadata information such as field name, data type, length, etc. <class>Defined within an element <id>Element, specifies the primary key attribute of the entity class, corresponding to the primary key field of the database table.
[0051] Preferably, in the data access layer, the Jpa Repository interface provided by the object-relational mapping framework is inherited to obtain basic data access functions, including operations such as adding, deleting, modifying and querying. In the data access layer, data access methods are defined according to specific business needs, and the Criteria API provided by the object-relational mapping framework is used to write data query logic. In the data access layer, the Sql Session Dao Support class provided by the object-relational mapping framework is inherited to obtain basic data access functions, including operations such as adding, deleting, modifying and querying. In the data access layer, data access methods are defined according to specific business needs, and the data query logic is written using the JPQL query language provided by the object-relational mapping framework.
[0052] Preferably, in the data application layer, an instance of the data access layer is obtained through a dependency injection framework, including: declaring a member variable of the data access layer interface type in a service class or a controller class of the data application layer, and marking it with the @Autowired annotation; and injecting the instance of the data access layer into the data application layer through a dependency injection framework, such as a Spring IOC container.
[0053] Preferably, when executing a query operation: the data application layer calls the query method of the data access layer and passes in the query conditions; the data access layer generates a query statement through the API provided by the object-relational mapping framework and sends it to the database for execution; the database executes the query operation and returns the result to the data access layer; the object-relational mapping framework converts the query result into an entity object, fills in the attribute value of the entity object, and returns it to the data access layer; the data access layer returns the query result in the form of an entity object to the data application layer for use by the business logic. When the object-relational mapping framework generates SQL statements based on the metadata mapping information: the SELECT clause and WHERE clause of the query statement are generated based on the attributes and annotations of the entity object; the INSERT clause and VALUES clause of the new statement are generated based on the attribute value of the entity object; the UPDATE clause and SET clause of the update statement are generated based on the attribute value of the entity object; the DELETE clause and WHERE clause of the delete statement are generated based on the passed in primary key value.
[0054] Furthermore, when performing an update operation, the application layer passes the modified entity object to the data access layer, including: the data access layer converts the entity object into an INSERT statement through the API provided by the object-relational mapping framework and sends it to the database for execution; the database executes the INSERT statement to insert the attribute value of the entity object into the corresponding database table; the database generates a primary key value and returns the primary key value to the object-relational mapping framework; the object-relational mapping framework fills the generated primary key value into the primary key attribute of the entity object and returns it to the data access layer. The INSERT statement is a data manipulation statement in SQL (Structured Query Language) that is used to insert new data rows into a database table. It is used to add one or more records to a table and provide corresponding values for each field in the table.
[0055] Another aspect of the present specification also provides a security database management system, including: at least one processing unit; used to execute instructions to implement a security database management method of the present application.
[0056] Compared with the prior art, the advantages of this application are:
[0057] This application refines the permission control granularity to the smallest atomic permission level by decomposing the permission template into atomic permissions. Atomic permissions can be flexibly combined to form a variety of permission templates to meet the permission control needs in different scenarios. At the same time, Huffman coding is used to encode atomic permissions, and the coding length is allocated according to the frequency of use of atomic permissions. Frequently used atomic permissions have shorter coding lengths, further improving the representation efficiency of permission templates. User permissions are associated with columns and rows of database tables to achieve fine-grained access control at the column and row levels, preventing users from accessing unauthorized sensitive data and improving the security of the system.
[0058] Bloom filters are used to compress and store the bit vectors formed by atomic permission encoding, which greatly reduces the storage space of permission information. The compressed bit vector index is stored in memory or distributed cache to achieve fast reading of permission information. By performing bitwise and equal operations on the bit vector, it is quickly determined whether the user has the corresponding permission, avoiding the inefficient permission verification method based on string matching. For high-frequency operations, the corresponding bit vector index is obtained from the cache in advance without real-time calculation, further improving the response speed of permission verification. The time complexity of bit operations is O, which is more efficient than the O(n) of string matching, thereby significantly improving the processing performance of the entire system.
[0059] Based on the object-relational mapping (ORM) framework, the database table is mapped to an object entity. Developers can use an object-oriented approach to perform database programming, avoid writing complex SQL statements, and reduce the complexity of data access. The ORM framework automatically generates SQL statements corresponding to database CRUD operations. Developers do not need to pay attention to the underlying database implementation, which improves development efficiency. The list of user permission verification results and row table access control information are dynamically injected into the SQL statement generated by the ORM framework, and corresponding data filtering conditions are added to ensure that only authorized data is accessed to ensure data security. The factory mode is used to manage the data access layer and database connections, simplify the allocation and recovery of database resources, and avoid resource leakage.
[0060] We control every link from user request to database operation, and work together in request processing, permission verification, SQL generation, and data access to form a closed loop, achieving all-round security protection before and after the event. The permission management module pre-processes the permission template, the permission verification module strictly authenticates the user identity and permissions, the SQL generation module controls the access data scope, and the data access layer ensures that only authorized database operations are performed. Corresponding inspection mechanisms are set up at each node of data flow to promptly detect and block illegal requests and operations, prevent users from accessing data beyond their permissions, minimize the risk of data leakage, and improve the overall security of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 is an exemplary flow chart of a method for managing a security database according to some embodiments of this specification;
[0062] Figure 2 is an exemplary flow chart of permission verification according to some embodiments of this specification;
[0063] Figure 3 is an exemplary flow chart of determining a user access request according to some embodiments of this specification;
[0064] Figure 4 This is an exemplary flowchart of generating SQL statements according to some embodiments of this specification. DETAILED DESCRIPTION
[0065] The method and system provided in the embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0066] Figure 1 The present invention is an exemplary flow chart of a method for managing a secure database according to some embodiments of the present specification, and the method comprises: obtaining a user's database operation request; verifying the user's authority by using a role-based access control method; after the authority verification, using an access control mechanism based on a database view, and according to the verified user's authority, using an SQL generation method, generating an SQL statement containing data filtering conditions, and performing column-level and row-level access control; obtaining a database operation result; wherein the database operation includes a data query operation and a data change operation; defining the data change operation as a workflow, and arranging and executing the data change process by a workflow engine; encapsulating the operation steps, judgment process and data verification rules into the workflow, and controlling the data change operation; encapsulating the database access operation as an object operation, using an object-relational mapping framework, and using the metadata mapping mechanism of the mapping framework to map the object attributes with the database table fields, generating SQL statements through the mapping framework, and binding the object attribute values with the SQL parameters; and performing database access according to the SQL statements containing the data filtering conditions and the SQL statements generated by the mapping framework.
[0067] Get the user's database operation request; the user initiates an operation request to the database through an application or other means (such as a command line tool, API interface, etc.). The operation request can be different types of requests such as data query, data insertion, data update or data deletion. When initiating a request, the user needs to provide necessary information, such as the target database, operation type, operation parameters, etc. The application receives the database operation request initiated by the user through the corresponding interface or framework. For Web applications, user requests can be received through HTTP requests (such as GET, POST, etc.), and request parameters can be passed through URL parameters, form data or request body. For desktop applications or other types of applications, user requests can be received through the corresponding user interface or API interface. After receiving the user request, the application parses and verifies the request. The purpose of parsing the request is to extract key information contained in the request, such as the target database, operation type, operation parameters, etc. Request parsing can be implemented in different ways, such as parsing URL parameters, parsing form data, parsing request bodies in JSON or XML format, etc.
[0068] Figure 2 It is an exemplary flowchart of permission verification according to some embodiments of the present specification, which verifies user permissions by a role-based access control method; passes the user request to the permission verification module, which uses the role inheritance relationship tree and the permission judgment matrix to determine whether the user has the corresponding permission based on the user ID and operation type, and returns the verification result to the request processing module; associates permissions with roles, and obtains the inheritance and reuse of parent role permissions by child roles by building a role inheritance relationship tree, and builds a permission template; wherein the role inheritance relationship tree uses roles as nodes and the inheritance relationships between roles as edges, and traverses the role inheritance relationship tree through depth-first search to obtain the parent role permissions inherited by the child role; the permission management module associates permissions with roles, builds a role inheritance relationship tree, obtains permission templates by traversing the relationship tree, and passes the permission templates to the permission verification module.
[0069] Specifically, according to the permission template, a permission judgment matrix is constructed using sparse matrix compression storage. The user ID is mapped to the row of the matrix, the role ID is mapped to the column of the matrix, and the permission ID is used as the value of the matrix. The row of the permission judgment matrix represents the user ID, the column represents the permission ID, and the value is a Boolean type, indicating whether the user has the corresponding permission. The permission verification module constructs the permission judgment matrix according to the permission template and stores the matrix in memory. Receive the user's database operation request and obtain the user ID and operation type in the request. The request processing module receives the user request, extracts the user ID and operation type from the request, and passes it to the permission verification module. According to the operation type, the corresponding permission ID is obtained from the permission template.
[0070] Figure 3 It is an exemplary flow chart for judging user access requests according to some embodiments of this specification. The permission verification module obtains the corresponding permission ID from the permission template according to the operation type. Through the permission judgment matrix, the user ID and permission ID are used as the row and column indexes of the matrix to query the value of the corresponding position. If the value is true, it means that the user has the permission and access is allowed; otherwise, if the value is false, access is denied. The permission verification module queries the permission judgment matrix according to the user ID and permission ID, obtains the value of the corresponding position, judges whether the user has the permission according to the value, and returns the verification result to the request processing module. The permission template is cached in the memory or distributed cache server, and an appropriate cache expiration time is set. The permission management module caches the constructed permission template in the memory or distributed cache, sets a suitable cache strategy, and provides the cached permission template to the permission verification module for use. When the user permission changes, the changed permission information is synchronized to the cache. The permission management module monitors the changes in user permissions. When the permission changes are detected, the cache refresh mechanism is triggered to synchronize the changed permission information to the cache to ensure that the permission template in the cache is consistent with the database.
[0071] Specifically, the request processing module counts the access frequency of each operation and defines the operation with an access frequency higher than the set threshold as a high-frequency operation. The request processing module sends the information of the high-frequency operation to the permission management module for pre-calculating the bit vector corresponding to the permission template. For high-frequency operations, the permission management module pre-calculates the bit vector corresponding to the permission template. The permission template ID is mapped to the index of the bit vector, and the user is judged whether the user has the preset permission through bit operation. Each bit of the bit vector represents an atomic permission, 1 means permission, and 0 means no permission. The permission management module caches the pre-calculated bit vector in the memory or distributed cache and provides it to the permission verification module for fast verification. Set session-level permission verification and perform permission verification when the user logs in. When the user logs in to the system, the permission verification module obtains the user's role information from the database according to the user ID. According to the role ID, the permission information corresponding to the role is obtained from the cache or database to verify the user's permission. The verified permission information is saved in the session object for subsequent permission judgment.
[0072] Among them, the permission template is decomposed into atomic permissions, and each permission template is represented as a combination of atomic permissions to form an atomic permission set; the permission management module decomposes the permission template, extracts atomic permissions, forms an atomic permission set, and passes the atomic permission set to the permission verification module. The atomic permission set is encoded, and the Huffman coding method is used to allocate the coding length according to the frequency of use of atomic permissions to form an atomic permission coding dictionary; the permission management module performs Huffman coding according to the frequency of use of atomic permissions, generates an atomic permission coding dictionary, and passes the dictionary to the permission verification module. According to the atomic permission coding dictionary, the permission template is converted into a bit vector in the form of Huffman coding; wherein each bit indicates whether the permission template contains the corresponding atomic permission; the permission verification module converts the permission template into a bit vector form according to the atomic permission coding dictionary, which is convenient for bit operations. The bit vector is compressed and stored using a Bloom filter, and the bit vector is mapped to the bit array of the Bloom filter through multiple hash functions; the permission verification module uses a Bloom filter to compress the bit vector to reduce storage space. The compressed bit vector index is stored in memory or distributed cache, and the expiration time and refresh policy of the bit vector index are set; the permission verification module stores the compressed bit vector index in the cache, and sets the expiration time and refresh policy. When the permission template changes, the cache refresh mechanism is triggered, the bit vector index is regenerated, and the cache is updated. The permission management module monitors the permission template changes, notifies the permission verification module to refresh the cache, and regenerates the bit vector index.
[0073] Specifically, after receiving a high-frequency operation request, the permission verification module obtains the corresponding permission template ID from the permission template cache according to the operation type. The permission template cache is pre-built and stores the mapping relationship between the operation type and the permission template ID. By querying the permission template cache, the permission template ID of the corresponding operation type can be quickly obtained. The permission verification module uses the permission template ID as an index to obtain the corresponding compressed bit vector from the bit vector index cache. The bit vector index cache is pre-built and stores the mapping relationship between the permission template ID and the compressed bit vector. The corresponding compressed bit vector can be quickly queried through the permission template ID. The permission verification module constructs a Huffman decoding tree based on the Huffman coding of the compressed bit vector. By traversing the Huffman decoding tree, the compressed bit vector is decoded into an atomic permission set. The decoding process restores the atomic permission through the combination of bits according to the rules of Huffman coding. The permission verification module converts the atomic permission set into a target bit vector in the form of Huffman coding through the atomic permission coding dictionary. The atomic permission coding dictionary stores the corresponding relationship between atomic permissions and Huffman coding. By querying the atomic permission coding dictionary, the atomic permission set is converted into a target bit vector. The permission verification module performs multiple hash calculations on the target bit vector to obtain multiple corresponding positions in the Bloom filter.
[0074] A Bloom filter is a fixed-size bit array used to quickly determine whether an element exists. The target bit vector is hashed and mapped to the corresponding position of the Bloom filter. The permission verification module determines whether the values of the corresponding positions of the Bloom filter are all 1. If the corresponding positions are all 1, it means that the target bit vector is included in the permission template bit vector, indicating that the user has the permission and access is allowed. If any corresponding position is 0, it means that the target bit vector is not included in the permission template bit vector, indicating that the user does not have the permission and access is denied. The permission verification module returns the verification result to the request processing module, and the request processing module performs corresponding processing based on the verification result.
[0075] Figure 4 This is an exemplary flow chart for generating SQL statements according to some embodiments of the present specification. After passing the authority verification, an access control mechanism based on database views is adopted. According to the verified user authority, an SQL generation method is used to generate SQL statements containing data filtering conditions to perform column-level and row-level access control; the verified user authority is passed to the SQL generation module, and the SQL generation module generates corresponding SQL statements according to the user authority, and returns the SQL statements to the request processing module.
[0076] Specifically, the SQL generation module receives the permission verification result and extracts the user's access control information to the database tables, columns and rows contained therein. The access rights include the user's access rights to the database table, the access rights to the columns in the table, and the access rights to the rows in the table. The SQL generation module obtains the user's detailed access rights information to the database based on the permission verification result. The SQL generation module uses a projection operation to generate a column-level view that is allowed to be accessed based on the user's access rights to the columns of the database table. The projection operation refers to selecting specific columns from the table and generating a new view that only contains the columns that are allowed to be accessed. The SQL generation module uses the SQL SELECT statement and specifies the columns that are allowed to be accessed in the SELECT clause to generate a column-level view. The SQL generation module uses a selection operation to generate a row-level view that is allowed to be accessed based on the user's access rights to the rows of the database table. The selection operation refers to selecting qualified rows from the table according to specific conditions and generating a new view that only contains the rows that are allowed to be accessed.
[0077] The SQL generation module uses the SQL SELECT statement and specifies the row access conditions in the WHERE clause to generate a row-level view. The SQL generation module connects the column-level view and the row-level view to generate a final view that is allowed to be accessed. The connection operation refers to merging two or more views according to specific conditions to generate a new view. The SQL generation module uses the SQL JOIN statement to connect the column-level view and the row-level view through the primary key or foreign key to generate the final data access view. The SQL generation module associates the query conditions requested by the user with the final view and generates an SQL statement that only queries the data that is allowed to be accessed. The query conditions requested by the user include the columns to be queried, the filter conditions, etc. The SQL generation module associates the query conditions with the final view and generates a complete SQL query statement to ensure that only the data that the user has the right to access is queried. The SQL generation module associates the change data requested by the user with the final view and generates an SQL statement that only updates the data that is allowed to be accessed. The change data requested by the user includes the columns to be updated, the update conditions, etc. The SQL generation module associates the change data with the final view and generates a complete SQL update statement to ensure that only the data that the user has the right to modify is updated. The SQL generation module uses the SQL statements of the column-level view and the SQL statements of the row-level view to construct the SQL statements of the join query. The join query SQL statement connects the column-level view and the row-level view through the primary key or foreign key to generate the final view containing the columns and rows that are allowed to be accessed.
[0078] The SQL generation module connects the column-level view and the row-level view in the connection query SQL according to the primary and foreign key relationship of the table to ensure the consistency and integrity of the data. The SQL generation module returns the generated SQL statement (query SQL statement or update SQL statement) to the request processing module. The request processing module sends the SQL statement to the database for execution. After the database executes the SQL statement, it returns the operation result to the request processing module. The request processing module returns the corresponding response information to the user based on the execution result.
[0079] The database is accessed according to the generated SQL statement to obtain the database operation results; wherein, the database operation includes data query operation and data change operation; the request processing module sends the SQL statement to the database, and after the database executes the SQL statement, the operation result is returned to the request processing module; the data change operation is defined as a workflow, and the data change process is orchestrated and executed by the workflow engine; the operation steps, judgment process and data validation rules are encapsulated into the workflow to control the data change operation; the data change request is sent to the workflow engine, and the workflow engine processes the request according to the predefined workflow. After a series of approval processes and data validation, the change request is submitted to the database for execution, and the database returns the change result to the workflow engine, and the workflow engine returns the result to the request processing module.
[0080] Encapsulate database access operations as object operations, adopt an object-relational mapping framework, and use the metadata mapping mechanism of the mapping framework to map object attributes to database table fields. Generate SQL statements through the mapping framework and bind object attribute values to SQL parameters. The request processing module forwards the request to the application layer. The application layer obtains an instance of the data access layer through the factory mode, calls the method of the data access layer, and passes the request parameters to the data access layer. The data access layer uses the object-relational mapping framework to convert the request into a corresponding SQL statement and sends the SQL statement to the database for execution. The database returns the execution result to the data access layer, and the data access layer converts the result into an object and returns it to the application layer. The application layer then returns the result to the request processing module.
[0081] Specifically, define entity objects: the application layer defines the corresponding entity objects according to the database table structure. The attributes in the entity object correspond to the fields in the database table one by one, and a mapping relationship between the attributes and fields is established. Entity objects are usually represented by classes in object-oriented programming languages (such as Java, C#, etc.). The attributes of the entity object are annotated using metadata annotations or configuration files provided by the object-relational mapping framework to specify the mapping relationship with the database table.
[0082] Configure object-relational mapping: The application layer uses the metadata annotations or configuration files provided by the object-relational mapping framework to obtain the mapping relationship between entity objects and database tables. Metadata annotations are specific annotations added to the classes and properties of entity objects, such as @Entity, @Table, @Column, etc., which are used to specify the mapping relationship between entity objects and database tables. Configuration files are configuration files in XML or other formats that describe the mapping relationship between entity objects and database tables, such as Hibernate's mapping files or JPA's persistence.xml files. The object-relational mapping framework automatically generates the mapping relationship between entity objects and database tables by reading metadata annotations or configuration files, without the need to manually write SQL statements.
[0083] Data access layer: The data access layer is part of the object-relational mapping framework and is used to interact with the database. The data access layer performs database read and write operations based on the data access interfaces provided by the object-relational mapping framework, such as Session, Entity Manager, etc. The data access layer performs add, delete, modify, and query operations on the database through the APIs provided by the mapping framework, such as save(*), find(*), update(*), etc. The methods of the data access layer receive entity objects as parameters, and generate corresponding SQL statements based on the attribute values of the entity objects to perform database operations.
[0084] Data application layer: The data application layer is the business logic layer of the application, responsible for executing database operations and processing business logic. The application layer obtains instances of the data access layer through the factory mode, such as Session Factory, EntityManager Factory, etc. The application layer calls methods of the data access layer, such as save (*), find (*), update (*), etc., to operate the database. When the application layer calls methods of the data access layer, the object-relational mapping framework automatically generates corresponding SQL statements based on the metadata mapping information of the entity object.
[0085] Database interaction: The data access layer interacts with the database by executing the generated SQL statements through the API provided by the object-relational mapping framework. For query operations, the data access layer executes SELECT statements to retrieve data from the database, and encapsulates the results as entity objects and returns them to the application layer. For update operations, the application layer passes the modified entity object to the data access layer, and the data access layer automatically generates UPDATE statements through the mapping framework to persist the changes in the database. For insert operations, the application layer creates a new entity object and passes it to the data access layer. The data access layer automatically generates INSERT statements through the mapping framework to insert new records into the database. For delete operations, the application layer passes the entity object to be deleted to the data access layer, and the data access layer automatically generates DELETE statements through the mapping framework to delete the record from the database.
[0086] Data return and processing: After the data access layer performs database operations, it encapsulates the results as entity objects and returns them to the application layer. For query operations, the data access layer converts the query results into entity objects and returns the entity objects to the application layer for subsequent business logic processing. For update, insert, and delete operations, after the data access layer performs the operation, it returns the results of the operation (such as the number of rows affected) to the application layer, and the application layer performs corresponding processing based on the results.
[0087] Specifically, when the application layer performs an update operation, it passes the modified entity object to the data access layer. The application layer passes the entity object to the data access layer by calling the update method provided by the data access layer, such as update(*) or merge(*). The entity object contains the attribute values to be updated, which correspond to the fields in the database table. After the data access layer receives the entity object passed by the application layer, it converts the entity object into the corresponding UPDATE statement through the API provided by the object-relational mapping framework. The data access layer calls the API of the mapping framework, such as Session.update(*) or EntityManager.merge(*), to convert the entity object into an UPDATE statement. The mapping framework generates the corresponding UPDATE statement based on the attribute values and mapping relationships of the entity object, which is used to update the data in the database table. The data access layer sends the generated UPDATE statement to the database for execution. After receiving the UPDATE statement, the database executes the statement and updates the attribute values of the entity object to the corresponding database table. The database updates the data in the table according to the conditions (such as the primary key) and the field values to be updated specified in the UPDATE statement.
[0088] After the database executes the UPDATE statement, it returns the update result to the object-relational mapping framework. The update result usually includes the number of affected rows, indicating the number of records successfully updated. The object-relational mapping framework receives the update result returned by the database and processes the result. The object-relational mapping framework encapsulates the update result returned by the database into the entity object. The mapping framework updates the attribute value of the entity object based on the update result to reflect the latest data in the database. The updated entity object contains the latest updated value in the database. The data access layer returns the updated entity object to the application layer through the API. The application layer receives the updated entity object and can further process or use the entity object as needed. The updated entity object is consistent with the data in the database and reflects the latest data status. Among them, the data flow path between the modules is: user request -> request processing module -> permission verification module (permission management module) -> SQL generation module -> request processing module -> application layer -> data access layer -> object-relational mapping framework -> database, and returns in reverse. Among them, permission verification, SQL generation and object-relational mapping respectively apply different technical solutions to realize their respective functions and work together to complete the entire secure data access process.< / id> < / class> < / property> < / class> < / class>
Claims
1. A method for managing a security database, comprising: Get the user's database operation request; Use role-based access control to verify user permissions; After passing the authority verification, the access control mechanism based on the database view is adopted. According to the verified user authority, the SQL generation method is used to generate SQL statements containing data filtering conditions to perform column-level and row-level access control; Obtain database operation results; database operations include data query operations and data change operations; Define data change operations as workflows, and use workflow engines to orchestrate and execute data change processes; encapsulate operation steps, judgment processes, and data validation rules into workflows to control data change operations; Encapsulate database access operations as object operations, adopt an object-relational mapping framework, and use the metadata mapping mechanism of the mapping framework to map object attributes with database table fields. Generate SQL statements through the mapping framework to bind object attribute values with SQL parameters; Generate SQL statements based on SQL statements containing data filtering conditions and the mapping framework to access the database; A role-based access control approach is used to verify user permissions, including: Associate permissions with roles, and build a role inheritance tree to obtain the inheritance and reuse of parent role permissions by child roles, and build a permission template. The role inheritance tree uses roles as nodes and the inheritance relationships between roles as edges. The role inheritance tree is traversed through a depth-first search to obtain the parent role permissions inherited by the child role. According to the permission template, a permission judgment matrix is constructed by sparse matrix compression storage; wherein the rows of the permission judgment matrix represent user IDs, the columns represent permission IDs, and the values are Boolean type, indicating whether the user has the corresponding permission; Receive the user's database operation request and obtain the user ID and operation type in the request; According to the operation type, obtain the corresponding permission ID from the permission template; Through the permission judgment matrix, the user ID and permission ID are used as the row and column indexes of the matrix to query the value of the corresponding position; if the value is true, it means that the user has the permission and access is allowed; otherwise, access is denied; A role-based access control approach is used to verify user permissions, including: Cache the permission template in memory or distributed cache server and set the cache expiration time; When user permissions change, synchronize the changed permission information to the cache; For operations with access frequency higher than the threshold, they are defined as high-frequency operations; For high-frequency operations, pre-calculate the bit vector corresponding to the cached permission template; map the permission template ID to the index of the bit vector, and determine whether the user has the preset permission through bit operations; where each bit of the bit vector represents an atomic permission, 1 means permission, and 0 means no permission; Set up session-level permission verification. When a user logs in, get the user's role information from the database based on the user ID, and then get the permission information corresponding to the role from the cache or database based on the role ID to perform permission verification; save the verified permission information to the session object; Use bit operations to determine whether the user has preset permissions, including: Perform atomic permission decomposition on permission templates, represent each permission template as a combination of atomic permissions, and form an atomic permission set; Encode the atomic permission set using Huffman coding, assign code lengths based on the frequency of use of atomic permissions, and form an atomic permission coding dictionary; According to the atomic permission coding dictionary, the permission template is converted into a bit vector in the form of Huffman coding, where each bit indicates whether the permission template contains the corresponding atomic permission; The Bloom filter is used to compress and store the bit vector, and the bit vector is mapped to the bit array of the Bloom filter through multiple hash functions; Store the compressed bit vector index in memory or distributed cache, and set the expiration time and refresh policy of the bit vector index; When the permission template changes, the cache refresh mechanism is triggered, the bit vector index is regenerated, and the cache is updated; Determine whether the user has the preset permissions through bit operations, including: For high-frequency operations, obtain the corresponding permission template ID from the permission template cache based on the operation type; Using the permission template ID as an index, obtain the corresponding compressed bit vector from the bit vector index cache; According to the Huffman coding of the compressed bit vector, a Huffman decoding tree is constructed to decode the compressed bit vector into an atomic permission set; According to the atomic permission set, the atomic permission coding dictionary is encoded and converted into a target bit vector in Huffman coding form; Hash mapping is performed on the target bit vector to obtain the corresponding multiple positions in the Bloom filter; It is determined whether all the obtained positions are 1. If so, it means that the target bit vector is included in the permission template bit vector, indicating that the user has the requested permission and access is allowed, otherwise access is denied.
2. The method for managing a security database according to claim 1, characterized in that: Generate SQL statements containing data filtering conditions to perform column-level and row-level access control, including: Based on the permission verification result, obtain the user's access rights to the database; the access rights include the user's access control information to the database tables, columns and rows; Based on the user's access rights to the columns of the database table, a projection operation is used to generate a column-level view that is allowed to be accessed; Based on the user's access rights to the rows of the database table, a projection operation is used to generate a row-level view that is allowed to be accessed; Connect the column-level view and the row-level view to generate the final view that is allowed to be accessed; Associate the query conditions requested by the user with the final view and generate SQL statements that only query the data that is allowed to be accessed; Associate the changed data requested by the user with the final view and generate SQL statements that only update the data that is allowed to be accessed; Execute the generated SQL statement, access the database, and obtain the database operation results.
3. The method for managing a security database according to claim 2, characterized in that: Generates the final view that allows access, including: Use the SQL statements of the column-level view and the row-level view to construct the SQL statement for the join query; In the SQL statement of the join query, the column-level view and the row-level view are joined through the primary key or foreign key to generate a final view containing the columns and rows that are allowed to be accessed.
4. The method for managing a security database according to claim 1, characterized in that: Encapsulate database access operations as object operations, use the object-relational mapping framework, and bind object attribute values to SQL parameters, including: Define entity objects corresponding to the database table structure. The attributes in the entity objects correspond one-to-one to the fields in the database table. The metadata annotation or configuration file provided by the object-relational mapping framework is used to obtain the mapping relationship between the entity object and the database table; wherein the object-relational mapping framework includes a data access layer and a data application layer; the data access layer is used to interact with the database; and the data application layer is used to perform database operations; In the data access layer, data access is performed based on the data access interface provided by the object-relational mapping framework; In the data application layer, obtain the instance of the data access layer through the factory mode; When the data application layer calls the method of the data access layer, the object-relational mapping framework generates SQL statements executed by the data access layer based on the metadata mapping information; The data access layer interacts with the database by executing the generated SQL statements through the API provided by the object-relational mapping framework; When performing an update operation, the application layer passes the modified entity object to the data access layer.
5. The method for managing a security database according to claim 4, characterized in that: When performing an update operation, the application layer passes the modified entity object to the data access layer, including: The data access layer converts entity objects into INSERT statements through the API provided by the object-relational mapping framework and sends them to the database for execution; The database executes the INSERT statement to insert the attribute values of the entity object into the corresponding database table; The database generates a primary key value and returns the primary key value to the object-relational mapping framework; The object-relational mapping framework fills the generated primary key value into the primary key attribute of the entity object and returns it to the data access layer.
