当前位置:网站首页>Permission management with binary
Permission management with binary
2022-04-23 18:08:00 【dawnsun001】
Just give an example ! Examples will be explained 1. Permission means 2. Authority judgment 3. Add permissions 4. Cancellation of authority
- public class Test {
- /**
- * @param args
- */
- public static void main(String[] args) {
- /**
- * Four permissions , Currently defined as int, The following binary representation takes only the last four digits for explanation
- */
- // add to
- int c = 1;// ...0001
- // Inquire about
- int r = 2;// ...0010
- // modify
- int u = 4;// ...0100
- // Delete
- int d = 8;// ...1000
- /**
- *
- * You can observe the rules of binary representation of four permissions , All are 2 Of N Power ,
- * It means itself , The last bit of add permission is... Others 0, The penultimate digit of the query is 1 Everything else is 0, Change the penultimate to 1 Everything else is 0, Delete the penultimate as 1 Everything else is 0
- *
- */
- /**
- *1111---- This indicates what kind of permission you have. You can use |( Press bit or ) operation
- *
- */
- // user A Have the right to add and modify
- int usera = c | r | u;
- // user B Have the right to add and delete
- int userb = c | d;
- /**
- * 2222---- To judge whether a user has certain permissions, use the user permissions and the permissions to be judged &( Bitwise AND ) operation , When the result is the permission value to be judged, it means that the user has this permission , Otherwise, you don't have this permission
- */
- if ((usera & u) == u) {
- System.out.println(" user a Have update permission ");
- } else {
- System.out.println(" user a No update permission ");
- }
- /**
- * 3333---- Add permissions to users. Use user permissions and permissions to be added |( Press bit or ) The operation overwrites the previous permission value
- */
- if ((userb & u) == u) {
- System.out.println(" user b Have update permission ");
- } else {
- System.out.println(" user b No update permission ");
- }
- // To the user b Add update permissions
- userb = userb | u;
- if ((userb & u) == u) {
- System.out.println(" user b Have update permission ");
- } else {
- System.out.println(" user b No update permission ");
- }
- /**
- * 4444---- Cancel a user's permission , Use the user authority and the authority to be cancelled to reverse by bit, and then carry out by bit operation , Overwrite the previous permission value
- */
- if ((usera & r) == r) {
- System.out.println(" user a Have query authority ");
- } else {
- System.out.println(" user a No query permission ");
- }
- // Cancel user a The query authority of
- usera = usera & (~r);
- if ((usera & r) == r) {
- System.out.println(" user a Have query authority ");
- } else {
- System.out.println(" user a No query permission ");
- }
- }
- }
版权声明
本文为[dawnsun001]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230544289337.html
边栏推荐
- 深度学习经典网络解析目标检测篇(一):R-CNN
- Auto. JS custom dialog box
- powerdesigner各种字体设置;preview字体设置;sql字体设置
- C [file operation] read TXT text by line
- Robocode Tutorial 4 - robocode's game physics
- Rust: a simple example of TCP server and client
- 解决报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
- From source code to executable file
- Climbing watermelon video URL
- Win1远程出现“这可能是由于credssp加密oracle修正”解决办法
猜你喜欢

Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战

ArcGIS table to excel exceeds the upper limit, conversion failed

JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability

【ACM】509. 斐波那契数(dp五部曲)

2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展

mysql自动启动设置用Systemctl start mysqld启动

How to install jsonpath package

Re expression régulière

Closure type of rust (difference between FN, fnmut and fnone)

【ACM】70. 爬楼梯
随机推荐
Rust: a simple example of TCP server and client
.104History
C network related operations
Rust: how to implement a thread pool?
NVIDIA Jetson: GStreamer and openmax (GST OMX) plug-ins
cartographer_ There is no problem compiling node, but running the bug that hangs directly
Queue solving Joseph problem
Yolov4 pruning [with code]
C medium? This form of
Implement a simple function to calculate the sum of all integers between M ~ n (m < n)
.105Location
深度学习经典网络解析目标检测篇(一):R-CNN
Go's gin framework learning
C#字节数组(byte[])和字符串相互转换
GDAL + ogr learning
Crack sliding verification code
MySQL auto start settings start with systemctl start mysqld
Crawling mobile game website game details and comments (MQ + multithreading)
由tcl脚本生成板子对应的vivado工程
Pyppeter crawler