A rights management method and device
By calculating the required number of permission fields and adding corresponding fields to the database, and combining bit operations to directly operate the permission status, the problems of permission management complexity and resource waste in the existing technology are solved, and simplified permission management and resource conservation are achieved.
Patent Information
- Application Number
- CN201810552532.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-05-31
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2038-05-31
AI Technical Summary
In the prior art, in the permission management, the database needs to be modified every time a new channel is added, the operations are complex and table locks are frequently locked, which affects the business, and the permission status field occupies a lot of space, causing waste of resources.
By determining the number of permission statuses saved in each permission field and the estimated number of channels, calculate the number of permission fields required, add corresponding fields to the database, reduce the number of new permission fields, and directly operate the binary bits for permission status using bit operations Query and update.
It reduces the business complexity and impact on normal business when adding new channels, saves database storage space, and simplifies the permission management process.
Smart Images

Figure CN110633273B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a permission management method and device. Background Art
[0002] Permission management generally refers to the fact that users can access and can only access the resources they are authorized to according to the security rules or security policies set by the system. Each user may have different permission status in the system. For example, a content platform has dozens or even hundreds of channels, and a channel corresponds to a function of the content platform. The channels can be, for example, a channel for discovering good products, a channel for buying albums, etc. Each user has a corresponding permission status for each channel, and the permission status can be, for example: "Not applied for", "Submit application, pending review", "Review passed", "Review rejected", "User has illegal behavior, closed", etc. Users must have the corresponding permissions for the channel before they can perform the corresponding operations. Managing and maintaining the permission status of each user is the daily work of the database administrator (Database Administrator, DBA).
[0003] When managing and maintaining the above-mentioned permission status, the prior art generally maintains a field for storing the permission status for each channel in the data table corresponding to the user, and generates a separate permission table. If a new permission field needs to be added, a new row of permission data needs to be added to the permission table; if the user has permission for the channel, a new record of the association between the permission data and the user needs to be added to the data table. When a user publishes content on the content platform, the content platform will verify the permission status field of the corresponding channel through a one-to-many association query to determine whether the user has permission to publish content.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0005] (1) Each time a new channel is added, the DBA needs to modify the corresponding data table in the database to add the permission status field corresponding to the channel, which is a complex operation;
[0006] (2) Each time a permission status field is added, the table will be locked. If permission status fields are added frequently, normal business will be affected to a certain extent.
[0007] (3) The permission status field in the database will take up a lot of space overhead, resulting in a waste of resources. Summary of the invention
[0008] In view of this, an embodiment of the present invention provides a permission management method and device, which determines the number of permission states saved by each permission field and estimates the number of channels required by the platform to obtain the number of permission fields required by the platform, so as to add a corresponding number of permission fields in the database. Through the above method, each time a new channel is added to the application, there is no need to add the permission field corresponding to the channel, which reduces the number of times the permission field is added and the complexity of the business, and facilitates business expansion.
[0009] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for managing rights is provided.
[0010] A permission management method according to an embodiment of the present invention includes: determining the number of permission states that can be saved by each permission field according to the number of permission states and the data type of the permission field; calculating the number of permission fields according to the estimated number of channels and the number of permission states that can be saved by each permission field; and adding corresponding permission fields to a database according to the number of permission fields.
[0011] Optionally, determining the number of the permission states that can be stored in each permission field based on the number of permission states and the data type of the permission field includes: calculating the number of bits occupied by each permission state based on the number of permission states; dividing the word length corresponding to the data type of the permission field by the number of bits occupied, and rounding down the division result to obtain the number of the permission states that can be stored in each permission field.
[0012] Optionally, the method also includes: calculating the permission field identifier and order corresponding to the permission state of the channel identifier based on the acquired channel identifier and the number of permission states that each permission field can save; generating a mask based on the number of bits occupied by the permission state; and performing a bitwise AND operation on the mask and the field data corresponding to the permission field identifier to obtain the permission state corresponding to the channel identifier.
[0013] Optionally, generating a mask according to the number of occupants of the permission status includes: subtracting 1 from the order and multiplying the result by the number of occupants, setting 1s equal to the number of occupants in high order, and setting 0s equal to the number of multiplication results in low order to generate a mask.
[0014] Optionally, generating a mask according to the number of occupants of the permission status includes: generating a mask of all 1s according to the number of occupants of the permission status; before the step of performing a bitwise AND operation on the mask and the field data corresponding to the permission field identifier, further comprising: calculating a shift number according to the order and the number of occupants to right-shift the field data corresponding to the permission field identifier according to the shift number; performing a bitwise AND operation on the mask and the field data corresponding to the permission field identifier includes: performing a bitwise AND operation on the right-shifted field data and the mask of all 1s.
[0015] Optionally, the method also includes: obtaining the permission field identifier and order corresponding to the permission state of the channel identifier based on the acquired channel identifier and the number of permission states that each permission field can save; extracting all permission states below the order and above the order; calculating the shift number based on the order and the number of occupants to left-shift the new permission state according to the shift number; and performing a bitwise OR operation on the result of the left shift, all permission states below the order, and all permission states above the order to obtain a new permission field.
[0016] Optionally, extracting all permission states lower than the order includes: shifting 1 left by the shift number and then subtracting 1 to obtain a low-order mask; performing a bitwise AND operation on the low-order mask and field data corresponding to the permission field identifier to obtain all permission states lower than the order.
[0017] Optionally, extracting all permission states higher than the order includes: multiplying the order by the bit occupancy to obtain a multiplication result, and using the multiplication result as the number of high-shift bits; right-shifting the field data corresponding to the permission field identifier according to the number of high-shift bits; and left-shifting the right-shift result according to the number of high-shift bits to obtain all permission states higher than the order.
[0018] Optionally, the method also includes: generating a corresponding query expression and query mask according to the query conditions; wherein the target permission status in the query mask is 1 and the rest are 0; obtaining the permission status of at least one of the channel identifiers of each user, and performing a bitwise AND operation on the permission status and the query mask; and performing a bitwise XOR operation on the operation result and the query expression to obtain the user whose XOR operation result is 0.
[0019] To achieve the above objective, according to another aspect of an embodiment of the present invention, a rights management device is provided.
[0020] A permission management device according to an embodiment of the present invention includes: a determination module, used to determine the number of permission states that can be saved by each permission field according to the number of permission states and the data type of the permission field; a calculation module, used to calculate the number of permission fields according to the estimated number of channels and the number of permission states that can be saved by each permission field; and an adding module, used to add the corresponding permission fields in the database according to the number of permission fields.
[0021] Optionally, the determination module is further used to: calculate the number of bits occupied by each permission state according to the number of permission states; and divide the word length corresponding to the data type of the permission field by the number of bits occupied, and round down the division result to obtain the number of permission states that each permission field can save.
[0022] Optionally, the device also includes: a first query module, used to calculate the permission field identifier and order corresponding to the permission state of the channel identifier based on the acquired channel identifier and the number of permission states that each permission field can save; generate a mask according to the number of bits occupied by the permission state; and perform a bitwise AND operation on the mask and the field data corresponding to the permission field identifier to obtain the permission state corresponding to the channel identifier.
[0023] Optionally, the first query module is further used to: subtract 1 from the order and multiply the result by the digit occupants, set the same number of 1s as the digit occupants in the high order, and set the same number of 0s as the multiplication result in the low order to generate a mask.
[0024] Optionally, the first query module is also used to: generate a mask of all 1s according to the number of occupants of the permission status; the device also includes: a right shift module, used to calculate the shift number according to the order and the number of occupants, so as to right shift the field data corresponding to the permission field identifier according to the shift number; the first query module is also used to: perform a bitwise AND operation on the right-shifted field data and the mask of all 1s.
[0025] Optionally, the device also includes: an updating module, used to obtain the permission field identifier and order corresponding to the permission state of the channel identifier based on the acquired channel identifier and the number of permission states that each permission field can save; extract all permission states below the order and above the order; calculate the shift number based on the order and the number of occupants to left-shift the new permission state according to the shift number; and perform a bitwise OR operation on the result after the left shift, all permission states below the order, and all permission states above the order to obtain a new permission field.
[0026] Optionally, the update module is further used to: shift 1 left by the shift number and then subtract 1 to obtain a low-order mask; and perform a bitwise AND operation on the low-order mask and field data corresponding to the permission field identifier to obtain all permission states lower than the order.
[0027] Optionally, the update module is also used to: multiply the order by the bit occupancy to obtain a multiplication result, and use the multiplication result as the number of high-shift bits; right-shift the field data corresponding to the permission field identifier according to the number of high-shift bits; and left-shift the right-shift result according to the number of high-shift bits to obtain all permission states higher than the order.
[0028] Optionally, the device also includes: a second query module, used to generate a corresponding query expression and query mask according to the query conditions; wherein the target permission status in the query mask is 1, and the rest are 0; obtaining the permission status of at least one of the channel identifiers of each user, performing a bitwise AND operation on the permission status and the query mask; and performing a bitwise XOR operation on the operation result and the query expression to obtain the user whose XOR operation result is 0.
[0029] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.
[0030] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a permission management method according to an embodiment of the present invention.
[0031] To achieve the above objective, according to another aspect of the embodiments of the present invention, a computer readable medium is provided.
[0032] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, a permission management method according to an embodiment of the present invention is implemented.
[0033] An embodiment of the above invention has the following advantages or beneficial effects: by determining the number of permission states saved in each permission field and estimating the number of channels required by the platform, the number of permission fields required by the platform is obtained, so as to add the corresponding number of permission fields in the database. Through the above method, each time a new channel is added to the present application, there is no need to add the permission field corresponding to the channel, thereby reducing the number of times and business complexity of adding new permission fields and facilitating business expansion; using bit operations to directly operate the binary bits in the computer, it is possible to query and update the user's permission status and query the users with specified channel permissions, thereby reducing the complexity of business expansion, reducing the impact of each new channel added on normal business, and saving database storage space.
[0034] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0036] Figure 1 is a schematic diagram of the main steps of the rights management method according to an embodiment of the present invention;
[0037] Figure 2 This is a schematic diagram of the main process of the rights management method according to an embodiment of the present invention;
[0038] Figure 3 This is a schematic diagram of the main process of querying the user authority status according to an embodiment of the present invention;
[0039] Figure 4 This is a schematic diagram of the implementation principle of the second method for querying the user authority status according to an embodiment of the present invention;
[0040] Figure 5 is a schematic diagram of the main process of changing the user authority status according to an embodiment of the present invention;
[0041] Figure 6 A schematic diagram of the implementation principle of changing the user authority status according to an embodiment of the present invention;
[0042] Figure 7 is a schematic diagram of a main process of querying users with specified channel authority according to an embodiment of the present invention;
[0043] Figure 8 A schematic diagram of the implementation principle of querying users with specified channel authority according to an embodiment of the present invention;
[0044] Fig. 9 is a schematic diagram of main modules of a rights management device according to an embodiment of the present invention;
[0045] Fig.10 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0046] Fig.11 It is a schematic diagram of the structure of a computer device suitable for implementing the electronic device of the embodiment of the present invention. DETAILED DESCRIPTION
[0047] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0048] Figure 1 FIG. 1 is a schematic diagram of the main steps of the rights management method according to an embodiment of the present invention. Figure 1 As shown, the rights management method of the embodiment of the present invention mainly includes the following steps:
[0049] Step S101: Determine the number of permission states that can be stored in each permission field according to the number of permission states and the data type of the permission field. The number refers to the number of types of permission states. The data type is defined in the data structure as a set of values and a set of operations defined on this value set, which is used to divide the data into data of different required memory sizes, including byte type (Byte), integer type (Integer), long integer type (Long), etc. This step first needs to calculate the number of bits occupied by each permission state according to the number of permission states; then divide the word length corresponding to the data type of the permission field by the number of bits occupied, and round the division result down to get the number of permission states that can be stored in each permission field.
[0050] Step S102: Calculate the number of permission fields according to the estimated number of channels and the number of permission states that each permission field can save. Set a channel identifier (Channel ID) for each channel in advance, and the Channel ID increases monotonically starting from 1. According to the development trend of the content platform, estimate the number of channels required by the content platform. Assuming that the required number of channels is p, and the number of permission states that each permission field can save is q, p / q permission fields are required to save all permission states. Among them, the content platform is a PGC (Professional Generated Content) platform, which refers to professionally produced content (video websites) and expert-produced content (Weibo), also known as PPC (Professionally-produced Content). Users can generate content, contribute content, interact with fans, etc. through the PGC platform.
[0051] Step S103: According to the number of the permission fields, the corresponding permission fields are added to the database. The value of p / q is rounded up, and the corresponding number of permission fields are added to the database according to the result of the rounding. Assuming that the estimated number of channels is 60, and the number of the permission states that can be saved by each permission field is 21, then 3 permission fields need to be added to the database. Assuming that the number of channels on the current content platform is less than the estimated number of channels, if a new channel needs to be added, the corresponding permission field is obtained according to the channel ID and the number of occupants of the channel, and the corresponding permission state is directly added to the permission field. There is no need to add the corresponding permission field of the channel every time a new channel is added, which reduces the business complexity of the new channel and the number of times the permission field is added, and facilitates business expansion.
[0052] Figure 2 FIG. 1 is a schematic diagram of the main flow of the rights management method according to an embodiment of the present invention. Figure 2 As shown, the rights management method of the embodiment of the present invention mainly includes the following steps:
[0053] Step S201: Determine the number of permission states that can be saved in each permission field according to the number of permission states and the data type of the permission field. The user's permissions in each channel have corresponding permission states, such as "not applied for", "submitted application, pending review", "review passed", etc., which are different types of permission states. In a preferred embodiment, assuming that there are m types of permission states, and a Long type permission field is used to save the permission states, the number of occupants n required for each permission state can be calculated by the following formula:
[0054]
[0055] Since the word length of the Long type is 64 bits, the number q of the permission states that can be saved by each permission field is:
[0056]
[0057] In the formula, represents rounding up, Represents round down.
[0058] Step S202: Calculate the number of required permission fields according to the estimated number of channels and the number of permission states that each permission field can save. Set a Channel ID for each channel of the content platform in advance, and the Channel ID increases monotonically starting from 1. In the embodiment, according to the estimated number of channels, when establishing a data table in the database, 6 permission fields are added, and these permission fields can support 126 permission states. According to the current development trend of the content platform, these permission fields can be used for about 5 years.
[0059] Step S203: According to the number of the permission fields, add the corresponding permission fields to the database. Assume that the estimated number of channels required by the content platform is p, round up the value of p / q, and add the corresponding number of permission fields to the database according to the rounded result. Assuming that the estimated number of channels is 60, the number of bits occupied by each permission state is 3. Since the word length of the Long type is 64 bits, each permission field can support The permission status that needs to be added in the database is These three permission fields are represented by privilege0, privilege1 and privilege2. If the number of channels on the current content platform is 20 and a new channel needs to be added, the channel ID of the new channel is 21, and the number of bits of the permission status of the new channel is 3, then the corresponding permission status needs to be added to the first permission field, that is, the last 3 binary bits of privilege0. It is not necessary to add the permission field corresponding to the channel every time a new channel is added, which reduces the business complexity of adding new channels and the number of times the permission field is added, and facilitates business expansion.
[0060] The status values of various permission states for each channel are defined in advance. The same permission state in all channels has the same status value. For example, the status value of "submit application, pending review" is defined as 010, the status value of "review passed" is 011, and the status value of "review rejected" is 100, etc. After adding the permission field in the database, the permission status can be set for the user currently logged in to the content platform. For example, the permission status of the user currently logged in to the content platform in channel 1 is "review passed", and the first three binary bits of the first permission field are assigned to 011.
[0061] Steps S201 to S203 implement adding a permission field for a user in the database. A large number of users may apply to register and subscribe to channels on a content platform. This application will add a corresponding permission field for each user in the database. The permission field of each user can be distinguished by the user ID.
[0062] In the actual operation of the content platform, when a user publishes content on a channel, the content platform needs to determine whether the user has the permission to publish content on the channel by querying the user's permission status. The following is a detailed description of the process of querying the user's permission status.
[0063] Figure 3 FIG. 1 is a schematic diagram of the main flow of querying user authority status according to an embodiment of the present invention. Figure 3 As shown, the process of querying the user authority status in an embodiment of the present invention mainly includes the following steps:
[0064] Step S301: Calculate the permission field identifier and order corresponding to the permission state of the channel identifier based on the acquired channel identifier and the number of permission states that each permission field can save. A user logs in to the content platform and publishes content in a channel. The content platform obtains user information and channel information, and the channel information includes ChannelID. The quotient obtained by dividing Channel ID by the number q of permission states that each permission field can save is the permission field identifier corresponding to the permission state of the channel identifier, and the remainder is the order of the permission state in the permission field, that is, permission field identifier = Channel ID / q, order = Channel ID%q.
[0065] In a preferred embodiment, assuming q=8, the number of occupancy n of each permission state is The permission status that can be saved in each Long type permission field in the database is When Channel ID = 50, the quotient of 50 / 21 is 2 and the remainder is 8. The permission field identifier corresponding to the permission status of this Channel ID is 2, that is, the permission status is in privilege2 and the order is 8.
[0066] Step S302: Generate a mask according to the number of occupants of the permission status. The mask is a string of binary codes used to perform bitwise AND operations on the target field to mask the current input bit. There are two ways to generate a mask in this step. Method 1: Subtract 1 from the order and multiply it by the number of occupants, set the same number of 1s as the number of occupants in the high position, and set the same number of 0s as the multiplication result in the low position to generate a mask. Method 2: Generate a mask with all 1s according to the number of occupants.
[0067] In a preferred embodiment, assuming that the order is 8 and the number of occupants is 3, the mask generated according to the first method is composed of a 24-bit binary number, in which 3 high bits are 1 and 21 low bits are 0, specifically: 11100000000000000000000000. According to the second method, the generated mask is 111.
[0068] Step S303: Perform a bitwise AND operation on the mask and the field data corresponding to the permission field identifier to obtain the permission status corresponding to the channel identifier. If step S202 adopts method 1, the mask generated by method 1 needs to be bitwise ANDed with the field data corresponding to the permission field identifier to obtain the permission status corresponding to the channel identifier. If step S202 adopts method 2, the shift number needs to be calculated first according to the order and the number of occupants to right-shift the field data corresponding to the permission field identifier according to the shift number; then the right-shifted field data is bitwise ANDed with the mask that is all 1 to obtain the permission status corresponding to the channel identifier. In this embodiment, the shift number is (Channel ID%q-1)×n=(8-1)×3=21 bits. The shift of field data from left to right means moving from high bit to low bit. The function of this step is to place the queried permission status in the low bit.
[0069] Figure 4 FIG. 2 is a schematic diagram showing the implementation principle of the second method for querying the user authority status according to an embodiment of the present invention. Figure 4 As shown in the figure, 21 kinds of privilege status are stored in a 63-bit binary number. To query the privilege status of a user in Channel ID=50, the privilege status is in privilege2 and the order is 8. Shift the field data in privilege2 right by 21 bits to get a 42-bit binary number. At this time, the privilege status of Channel ID=50 is placed in the low position. Perform a bitwise AND operation on the shifted field data and mask 111 to obtain the privilege status corresponding to Channel ID=50.
[0070] The following is an example of a permission field that uses a 9-bit binary number to store the permission status, and the number of bits occupied by each permission status is 3, to illustrate the above shift acquisition operation. Assuming that the field data of a permission field is 110101010, if you want to obtain the second permission status (from right to left, the first to the third permission status), first shift the field data 110101010 right by 3 bits to get 110101; then perform a bitwise AND operation on 110101 and the mask 111, and finally get the second permission status 101.
[0071] In the actual operation of the content platform, it is sometimes necessary to change the permission status of a user's channel. The following is a detailed description of the process of changing the user's permission status.
[0072] Figure 5 FIG. 1 is a schematic diagram of the main process of changing the user authority status according to an embodiment of the present invention. Figure 5 As shown, the process of changing the user authority status in the embodiment of the present invention mainly includes the following steps:
[0073] Step S501: Calculate the permission field identifier and order corresponding to the permission state of the channel identifier based on the acquired channel identifier and the number of permission states that each permission field can save. A user logs in to the content platform and publishes content in a channel. The content platform obtains user information and channel information, and the channel information includes ChannelID. The quotient obtained by dividing the Channel ID by the number q of the permission states that each permission field can save is the permission field identifier corresponding to the permission state of the channel identifier, and the remainder is the order of the permission state in the permission field.
[0074] Step S502: extract all the permission states lower than the order. The specific process of extracting all the permission states lower than the order is as follows:
[0075] (1) Calculate the shift bit according to the order and the number of occupants, shift 1 to the left by the shift bit and then subtract 1 to obtain the low-order mask. Where, the shift bit moveBits = (Channel ID%q-1) × n, then the low-order mask lowMsak = 1< <moveBits-1。
[0076] (2) Performing a bitwise AND operation on the low-order mask and the field data corresponding to the privilege field identifier to obtain all privilege states lower than the order. If privilege is used to represent the field data corresponding to the privilege field identifier, then all privilege states lower than the order are lowStatus=lowMsak&privilege.
[0077] Step S503: Calculate the shift bit according to the order and the number of occupancy bits, so as to shift the new permission status to the left according to the shift bit. Wherein, the shift bit moveBits = (Channel ID% q-1) × n. If status represents the new permission status, then the result after left shift updateStatus = status< <moveBits。
[0078] Step S504: extract all the permission states higher than the order. The specific process of extracting all the permission states higher than the order is as follows:
[0079] (1) Multiply the order by the number of occupied bits to obtain a multiplication result, and use the multiplication result as the number of high-shift bits; wherein the number of high-shift bits highMoveBits = Channel ID%q×n.
[0080] (2) right-shifting the field data corresponding to the authority field identifier according to the number of high-order shift bits;
[0081] (3) Shift the right shift result left according to the high shift bit number to obtain all privilege states higher than the order. All privilege states higher than the order highStatus = (privilege>>highMoveBits) < <highMoveBits。
[0082] Step S505: Perform a bitwise OR operation on the results of step S502, step S503 and step S504 to obtain a new privilege field. In this step, all privilege states below the order, the result after left shift and all privilege states above the order are bitwise ORed to finally obtain a new privilege field privilegeNew = lowStatus | updateStatus | highStatus. In the above process, the execution order of step S502, step S503 and step S504 can be interchanged.
[0083] Figure 6 FIG. 1 is a schematic diagram of the implementation principle of changing the user authority status according to an embodiment of the present invention. Figure 6 As shown, 21 kinds of permission states are stored in a 63-bit binary number. To update the permission state of a user in Channel ID=50, the permission state is in privilege2 and the order is 8. First, shift 1 left by 21 bits and then subtract 1 to obtain 21 1s as the low-order mask, and perform a bitwise AND operation on the low-order mask and the field data corresponding to the permission field identifier to obtain the low-order 21-bit field data; then shift the new permission state left by 21 bits to obtain a 24-bit binary number (where the upper 3 bits are the new permission state and the lower 21 bits are 0); then shift the field data corresponding to the permission field identifier right by 24 bits and then shift it left by 24 bits to obtain a 63-bit binary number (where the upper 39 bits are the upper 39-bit field data and the lower 24 bits are 0); finally, perform a bitwise operation on the above-mentioned lower 21-bit field data, the 24-bit binary number and the 63-bit binary number to obtain the updated permission field. Figure 6 XXX is the new permission status.
[0084] The following takes a permission field that uses a 9-bit binary number to store the permission state, and the number of bits occupied by each permission state is 3 as an example to illustrate the above shift acquisition operation. Assuming that the field data of a permission field is 110101010, if the second permission state needs to be changed from 101 to 110, first obtain all permission states lower than the second permission state. In this embodiment, the first permission state 010 is obtained; then the new permission state 110 is shifted left by 3 bits to obtain 110000; then obtain all permission states higher than the second permission state. In this embodiment, 110000000 is obtained; finally, 110000000|110000|010=110110010, and the second permission state is changed to the new permission state 110.
[0085] In the actual operation of the content platform, sometimes it is necessary to batch query some users who have the permissions of a specified channel (for example, query users who have opened permissions for the three channels channel1, channel2, and channel5 at the same time). The query process is described in detail below.
[0086] Figure 7 FIG. 1 is a schematic diagram of the main process of querying users with specified channel permissions according to an embodiment of the present invention. Figure 7 As shown, the process of querying users with specified channel permissions in the embodiment of the present invention mainly includes the following steps:
[0087] Step S701: Generate corresponding query expressions and query masks according to the query conditions; wherein the target permission status in the query mask is 1, and the rest are 0. The target permission status is the permission status of the channel to be queried. Assuming that there are five channels in the content platform, the digit occupies for the permission status of each channel is 3, and the query condition is a user who has opened permissions for the three channels, channel1, channel2, and channel5 at the same time. Assuming that the permission status for opening a certain channel permission is 001, the query expression is 001000000001001, and the query mask is 111000000111111.
[0088] Step S702: Obtain the permission status of at least one of the channel identifiers of each user, and perform a bitwise AND operation on the permission status and the query mask. Obtain the permission status of all channels of each user in the database, and perform a bitwise AND operation on the permission of each user and the query mask. In this step, you can also only obtain the permission status of the channel specified in the query condition, or only obtain the permission status of all channels that are less than or equal to the maximum channel identifier in the query condition. In this case, you need to obtain the permission status according to the execution process of steps S301 to S303. For example, there are 20 channels in the content platform. To query users who have opened permissions for the three channels channel1, channel2, and channel5 at the same time, you can obtain the permission status of each user's 20 channels in this step, or obtain the permission status of the three channels channel1, channel2, and channel5, or obtain the permission status of the five channels channel1 to channel5.
[0089] Step S703: Perform a bitwise XOR operation on the operation result and the query expression to obtain the user whose XOR operation result is 0. Assuming that the privilege status of all channels of a certain user is represented by privilege, the query mask is represented by privilege Filter, and the query expression is represented by query Condition, then steps S702 and S703 are used to find the user for which ((privilege & privilege Filter)^query Condition)=0.
[0090] Figure 8 FIG. 1 is a schematic diagram of the implementation principle of querying users with specified channel permissions according to an embodiment of the present invention. Figure 8 As shown, assuming that there are three users registered in the content platform, namely user 1, user 2 and user 3, to obtain the permission status of all channels of the three users (the "..." in the figure represents the channel status of all channels of channel 6 and above), it is necessary to query the users who have opened the permissions of the three channels, channel 1, channel 2 and channel 5, from these three users. Then, user 1's privilege: ...011010110010001, user 2's privilege: ...001110010001001, user 3's privilege: ...000110010001001, query mask privilege Filter: 111000000111111, query expression query Condition: 001000000001001, the user who can make ((privilege&privilege Filter)^queryCondition)=0 is user 2.
[0091] It can be seen from the permission management method of the embodiment of the present invention that the number of permission states saved in each permission field is determined, and the number of channels required by the platform is estimated, and the number of permission fields required by the platform is obtained, so that the corresponding number of permission fields is added to the database. Through the above method, each time a new channel is added to the present application, there is no need to add the permission field corresponding to the channel, which reduces the number of times and business complexity of adding new permission fields and facilitates business expansion; bit operations are used to directly operate the binary bits in the computer, so as to realize the query and update of the user permission status and the query of users with specified channel permissions, which reduces the complexity of business expansion, reduces the impact of each new channel on normal business, and saves database storage space.
[0092] Fig. 9 Schematic diagram of the main modules of the rights management device according to an embodiment of the present invention. Fig. 9 As shown, the rights management device 900 of the embodiment of the present invention mainly includes:
[0093] Determination module 901 is used to determine the number of the permission states that can be stored in each permission field according to the number of permission states and the data type of the permission field. The module first needs to calculate the number of bits for each permission state according to the number of permission states; then divide the word length corresponding to the data type of the permission field by the number of bits, and round down the division result to obtain the number of the permission states that can be stored in each permission field.
[0094] Calculation module 902 is used to calculate the number of permission fields according to the estimated number of channels and the number of permission states that each permission field can save. A Channel ID is set for each channel in advance, and the Channel ID increases monotonically starting from 1. According to the development trend of the content platform, the number of channels required by the content platform is estimated. Assuming that the required number of channels is p and the number of permission states that each permission field can save is q, p / q permission fields are required to save all permission states.
[0095] Adding module 903 is used to add the corresponding permission fields in the database according to the number of the permission fields. The value of p / q is rounded up, and the corresponding number of permission fields are added to the database according to the result of the rounding. Assuming that the estimated number of channels is 60, and the number of permission states that can be saved by each permission field is 21, then 3 permission fields need to be added to the database. Assuming that the number of channels on the current content platform is less than the estimated number of channels, if a new channel needs to be added, the corresponding permission field is obtained according to the channel ID and the number of occupants of the channel, and the corresponding permission state is directly added to the permission field. There is no need to add the corresponding permission field of the channel every time a new channel is added, which reduces the business complexity of the new channel and the number of times the permission field is added, and facilitates business expansion.
[0096] In addition, the rights management device 900 of the embodiment of the present invention may also include: a right shift module, a first query module, an update module, and a second query module ( Fig. 9 (not shown in the figure). The right shift module is used to calculate the shift number according to the order and the number of occupants, so as to right shift the field data corresponding to the permission field identifier according to the shift number; the first query module is used to query the permission status of a certain user in a certain channel; the update module is used to change the permission status of a certain user in a certain channel; the second query module is used to query users with specified channel permissions. The specific implementation of the first query module, the update module and the second query module is as described above.
[0097] From the above description, it can be seen that by determining the number of permission states saved in each permission field and estimating the number of channels required by the platform, the number of permission fields required by the platform is obtained, so that the corresponding number of permission fields can be added to the database. Through the above method, each time a new channel is added to the present application, there is no need to add the permission field corresponding to the channel, which reduces the number of times and business complexity of adding new permission fields and facilitates business expansion; bit operations are used to directly operate the binary bits in the computer to realize the query and update of user permission status and the query of users with specified channel permissions, which reduces the complexity of business expansion, reduces the impact of each new channel on normal business, and saves database storage space.
[0098] Fig.10 An exemplary system architecture 1000 is shown to which the rights management method or rights management apparatus according to the embodiment of the present invention can be applied.
[0099] like Fig.10As shown, the system architecture 1000 may include terminal devices 1001, 1002, 1003, a network 1004, and a server 1005. The network 1004 is used to provide a medium for communication links between the terminal devices 1001, 1002, 1003 and the server 1005. The network 1004 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0100] Users can use terminal devices 1001, 1002, 1003 to interact with server 1005 through network 1004 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 1001, 1002, 1003, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0101] The terminal devices 1001 , 1002 , and 1003 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0102] The server 1005 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using the terminal devices 1001, 1002, and 1003. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information and product information) to the terminal device.
[0103] It should be noted that the permission management method provided in the embodiment of the present application is generally executed by the server 1005, and accordingly, the permission management device is generally set in the server 1005.
[0104] It should be understood that Fig.10 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0105] According to an embodiment of the present invention, the present invention also provides an electronic device and a computer-readable medium.
[0106] The electronic device of the present invention comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a permission management method of an embodiment of the present invention.
[0107] The computer-readable medium of the present invention stores a computer program, and when the program is executed by a processor, a rights management method of an embodiment of the present invention is implemented.
[0108] Reference below Fig.11 , which shows a schematic diagram of the structure of a computer system 1100 suitable for implementing an electronic device of an embodiment of the present invention. Fig.11 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0109] like Fig.11 As shown, the computer system 1100 includes a central processing unit (CPU) 1101, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1102 or a program loaded from a storage part 1108 into a random access memory (RAM) 1103. In the RAM 1103, various programs and data required for the operation of the computer system 1100 are also stored. The CPU 1101, the ROM 1102, and the RAM 1103 are connected to each other via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0110] The following components are connected to the I / O interface 1105: an input section 1106 including a keyboard, a mouse, etc.; an output section 1107 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1108 including a hard disk, etc.; and a communication section 1109 including a network interface card such as a LAN card, a modem, etc. The communication section 1109 performs communication processing via a network such as the Internet. A drive 1110 is also connected to the I / O interface 1105 as needed. A removable medium 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1110 as needed, so that a computer program read therefrom is installed into the storage section 1108 as needed.
[0111] In particular, according to the embodiments disclosed in the present invention, the process described in the main step diagram above can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the main step diagram. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1109, and / or installed from the removable medium 1111. When the computer program is executed by the central processing unit (CPU) 1101, the above-mentioned functions defined in the system of the present invention are executed.
[0112] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0113] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0114] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, may be described as: a processor includes a determination module, a calculation module and an addition module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the determination module may also be described as "a module that determines the number of permission states that can be saved by each permission field according to the number of permission states and the data type of the permission field".
[0115] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: determining the number of permission states that can be saved by each permission field according to the number of permission states and the data type of the permission field; calculating the number of permission fields according to the estimated number of channels and the number of permission states that can be saved by each permission field; and adding the corresponding permission fields to the database according to the number of permission fields.
[0116] From the above description, it can be seen that by determining the number of permission states saved in each permission field and estimating the number of channels required by the platform, the number of permission fields required by the platform is obtained, so that the corresponding number of permission fields can be added to the database. Through the above method, each time a new channel is added to the present application, there is no need to add the permission field corresponding to the channel, which reduces the number of times and business complexity of adding new permission fields and facilitates business expansion; bit operations are used to directly operate the binary bits in the computer to realize the query and update of user permission status and the query of users with specified channel permissions, which reduces the complexity of business expansion, reduces the impact of each new channel on normal business, and saves database storage space.
[0117] The above product can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.
[0118] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A rights management method, characterized in that: include: Determining the number of the permission states that can be stored in each permission field according to the number of permission states and the data type of the permission field; Calculating the number of the permission fields according to the estimated number of channels and the number of the permission states that can be saved by each of the permission fields comprises: According to the number of the permission fields, adding corresponding permission fields in the database; According to the acquired channel identifier and the number of the permission states that can be stored in each permission field, acquiring the permission field identifier and order corresponding to the permission state of the channel identifier; Generate a mask according to the number of occupants of the permission status; Performing a bitwise AND operation on the mask and the field data corresponding to the permission field identifier to obtain the permission status corresponding to the channel identifier; Extract all permission states below the order and above the order; calculate the shift number according to the order and the number of occupants to left-shift the new permission state according to the shift number; perform a bitwise OR operation on the result of the left shift, all permission states below the order, and all permission states above the order to obtain a new permission field.
2. The method according to claim 1, characterized in that The step of determining the number of the permission states that can be stored in each permission field according to the number of permission states and the data type of the permission field includes: According to the number of permission states, the number of digits occupied by each permission state is calculated; The word length corresponding to the data type of the permission field is divided by the number of bit occupants, and the division result is rounded down to obtain the number of the permission states that can be stored in each permission field.
3. The method according to claim 1, characterized in that The generating of the mask according to the number of occupants of the permission status includes: subtracting 1 from the order and multiplying the result by the number of occupants, setting the same number of 1s as the number of occupants in the high order, and setting the same number of 0s as the number of multiplication results in the low order to generate the mask.
4. The method according to claim 1, characterized in that: Generating a mask according to the number of digits occupied by the permission status includes: generating a mask with all 1s according to the number of digits occupied by the permission status; Before the step of performing a bitwise AND operation on the mask and the field data corresponding to the permission field identifier, the method further includes: calculating a shift number according to the order and the number of occupants, so as to right-shift the field data corresponding to the permission field identifier according to the shift number; The bitwise AND operation of the mask and the field data corresponding to the permission field identifier includes: performing a bitwise AND operation of the right-shifted field data and the mask that is all 1s.
5. The method according to claim 1, characterized in that Extract all permission states below the stated order, including: Shift 1 left by the shift number and then subtract 1 to obtain a low-order mask; A bitwise AND operation is performed on the low-order mask and the field data corresponding to the permission field identifier to obtain all permission states lower than the order.
6. The method according to claim 1, characterized in that Extract all permission states above the stated order, including: Multiply the order by the number of occupants to obtain a multiplication result, and use the multiplication result as the number of high-order shift bits; Shift the field data corresponding to the permission field identifier right by the number of high-order shift bits; The right shift result is left-shifted according to the high-order shift bit number to obtain all permission states higher than the order.
7. The method according to claim 2, characterized in that The method further comprises: Generate a corresponding query expression and query mask according to the query condition; wherein the target permission status in the query mask is 1, and the rest are 0; Obtaining the permission status of at least one of the channel identifiers of each user, and performing a bitwise AND operation on the permission status and the query mask; Perform a bitwise XOR operation on the operation result and the query expression to obtain the user whose XOR operation result is 0.
8. A rights management device, characterized in that: include: A determination module, configured to determine the number of the permission states that can be stored in each permission field according to the number of permission states and the data type of the permission field; A calculation module, configured to calculate the number of the permission fields according to the estimated number of channels and the number of the permission states that can be saved by each of the permission fields; An adding module, used for adding corresponding permission fields in the database according to the number of the permission fields; Calculate the permission field identifier and order corresponding to the permission state of the channel identifier according to the acquired channel identifier and the number of the permission states that can be stored in each permission field; A first query module is used to generate a mask according to the number of bits occupied by the permission status; perform a bitwise AND operation on the mask and the field data corresponding to the permission field identifier to obtain the permission status corresponding to the channel identifier; An update module is used to extract all permission states below the order and above the order; calculate the shift number according to the order and the number of occupants to left-shift the new permission state according to the shift number; and perform a bitwise OR operation on the result after the left shift, all permission states below the order, and all permission states above the order to obtain a new permission field.
9. The device according to claim 8, characterized in that The determining module is further used for: Calculate the number of occupancy of each permission state according to the number of permission states; and The word length corresponding to the data type of the permission field is divided by the number of bit occupants, and the division result is rounded down to obtain the number of the permission states that can be stored in each permission field.
10. The device according to claim 8, characterized in that The first query module is further used to: subtract 1 from the order and multiply the result by the digit occupants, set the same number of 1s as the digit occupants in the high order, and set the same number of 0s as the multiplication result in the low order to generate a mask.
11. The device according to claim 8, characterized in that The first query module is further used to: generate a mask of all 1s according to the number of digits occupied by the permission status; The device further comprises: a right shift module, configured to calculate a shift number according to the order and the number of occupants, so as to right shift the field data corresponding to the authority field identifier according to the shift number; The first query module is further used to: perform a bitwise AND operation on the right-shifted field data and the mask of all 1s.
12. The device according to claim 8, characterized in that The update module is further used for: Shift 1 left by the shift number and then subtract 1 to obtain a low-order mask; and A bitwise AND operation is performed on the low-order mask and the field data corresponding to the permission field identifier to obtain all permission states lower than the order.
13. The device according to claim 8, characterized in that The update module is further used for: Multiply the order by the number of occupants to obtain a multiplication result, and use the multiplication result as the number of high-order shift bits; Shift the field data corresponding to the permission field identifier right by the number of high-order shift bits; as well as The right shift result is left-shifted according to the high-order shift bit number to obtain all permission states higher than the order.
14. The device according to claim 9, characterized in that The device also includes: a second query module, which is used to Generate a corresponding query expression and query mask according to the query condition; wherein the target permission status in the query mask is 1, and the rest are 0; Obtaining the permission status of at least one of the channel identifiers of each user, performing a bitwise AND operation on the permission status and the query mask; and Perform a bitwise XOR operation on the operation result and the query expression to obtain the user whose XOR operation result is 0.
15. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
16. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Data processing system and processing method in cloud computing multi-tenant architecture
CN102930027A